It is currently May 6th, 2024, 2:51 pm

PluginWebView - Make skin using web technology

Share and get help with Plugins and Addons
Kotofanchik
Posts: 99
Joined: March 15th, 2024, 7:30 pm

Re: PluginWebView - Make skin using web technology

Post by Kotofanchik »

2) try to uninstall the existing Edge and WebView normally from one of these locations:
- Control Panel > Programs And Features
- Start > Settings > Apps
3) delete any "Edge..." and "Temp" folders from the "C:\Program Files (x86)\Microsoft" folder (skip files that cannot be deleted, if any)
4) step wrote that a newer version is installed
User avatar
Yincognito
Rainmeter Sage
Posts: 7206
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: PluginWebView - Make skin using web technology

Post by Yincognito »

Kotofanchik wrote: April 1st, 2024, 8:36 pm I can't do it. I don't get anything. I see the information in the skin and see that it is there. But she doesn't go any further. I can't pass this string to another measure. Do not understand why. Which quotation marks and brackets should be used. I again go through random options, try to do what I find in other skins and nothing.
Yes, I commented on regexpsubstitute and substitute and tried to do for example

Code: Select all

[Data1]
Measure =Plugin
Plugin=WebParser
Url=[Data]
RegExp=.....
But nothing works out.
The URL option in a WebParser measure can be either a local or online webpage address, or another WebParser measure. Setting it to the [Data] measure will not work, because [Data] is a String measure. So, the right way to approach this is, like I said, through the Substitute option of [Data] itself (assuming a RegExpSubstitute=1 line is present in [Data] as well, so that regular expressions can be used in the Substitute option). Understanding what symbols should be used in regular expression (i.e. regex) patterns depends on you understanding how regular expressions work. I know, looks difficult, but it's not that hard - it's like math, but for strings.
Kotofanchik wrote: April 1st, 2024, 8:48 pm 4) step wrote that a newer version is installed
Step 4) is referring to the Edge installation. Step 2), 3), 5) and 6) also refer to the WebView uninstallation process. I think you're confusing the two.
To be more specific, you couldn't get that error when trying to install Edge, because you can perform step 2) for Edge, just not for latest WebView.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
Kotofanchik
Posts: 99
Joined: March 15th, 2024, 7:30 pm

Re: PluginWebView - Make skin using web technology

Post by Kotofanchik »

Yincognito wrote: April 1st, 2024, 8:54 pm The URL option in a WebParser measure can be either a local or online webpage address, or another WebParser measure. Setting it to the [Data] measure will not work, because [Data] is a String measure. So, the right way to approach this is, like I said, through the Substitute option of [Data] itself (assuming a RegExpSubstitute=1 line is present in [Data] as well, so that regular expressions can be used in the Substitute option). Understanding what symbols should be used in regular expression (i.e. regex) patterns depends on you understanding how regular expressions work. I know, looks difficult, but it's not that hard - it's like math, but for strings.


Step 4) is referring to the Edge installation. Step 2), 3), 5) and 6) also refer to the WebView uninstallation process. I think you're confusing the two.
To be more specific, you couldn't get that error when trying to install Edge, because you can perform step 2) for Edge, just not for latest WebView.
Making the entire skin using regexpsubstitute is unrealistic. It is possible, but very labor intensive. Maybe you can save the entire Data string to a file and rewrite the entire file every time the information is updated? I would then direct a regexp to the file on it
Kotofanchik
Posts: 99
Joined: March 15th, 2024, 7:30 pm

Re: PluginWebView - Make skin using web technology

Post by Kotofanchik »

because you can perform step 2) for Edge, just not for latest WebView.
My version of Windows has a standard ability to remove webwiew2. But it is not possible to remove Edge. As far as I know, it is possible to remove Edge in the European Union, but I do not have this option.
User avatar
Yincognito
Rainmeter Sage
Posts: 7206
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: PluginWebView - Make skin using web technology

Post by Yincognito »

Kotofanchik wrote: April 1st, 2024, 9:24 pm My version of Windows has a standard ability to remove webwiew2. But it is not possible to remove Edge. As far as I know, it is possible to remove Edge in the European Union, but I do not have this option.
Oh, I see. Well, that probably explains it, indeed.
Kotofanchik wrote: April 1st, 2024, 9:19 pm Making the entire skin using regexpsubstitute is unrealistic. It is possible, but very labor intensive. Maybe you can save the entire Data string to a file and rewrite the entire file every time the information is updated? I would then direct a regexp to the file on it
I get what you're saying, but there are 3 problems with your proposal:
- for security reasons, Javascript can't really write to local files:
https://stackoverflow.com/questions/21012580/is-it-possible-to-write-data-to-file-using-only-javascript
- for the same reason, Rainmeter has a limited such ability too:
https://docs.rainmeter.net/manual/bangs/#WriteKeyValue
- even if it's done, you'd still need regex patterns in the RegExp:
https://docs.rainmeter.net/manual/measures/webparser/#Local
https://docs.rainmeter.net/manual/measures/webparser/#RegExp

So, basically, you'd end up doing more or less the same thing, except in a RegExp and not a Substitute. Same effort, if you ask me.



Plus, this would be exactly what a single WebParser measure with its URL set to the desired address does (i.e. you wouldn't need WebView or Javascript at all) - not to mention WebParser also has the ability to save the response to a local file via its Download=1 and DownloadFile=<filenamehere> options. Obviously, this would probably not solve the Cloudflare issue as you already suspect (though you didn't mention if the WebView method here solves it either, by trying that method on your weather site instead of google.com), but since you asked...



Here is how to do it with just 2 WebParser measures (copied from another advice I gave, no need for the local Page.html or a WebView measure using it):

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
BackgroundMode=2
SolidColor=0,0,0,128

---Measures---

[Page]
Measure=WebParser
URL=https://www.google.com
Download=1
DownloadFile=Data.txt
UpdateRate=600
FinishAction=[!EnableMeasure Data][!UpdateMeasure Data][!CommandMeasure Data "Update"]

[Data]
Disabled=1
Measure=WebParser
URL=file://#CURRENTPATH#DownloadFile\Data.txt
RegExp=(?siU)^(.*)$
StringIndex=1
UpdateRate=-1
FinishAction=[!UpdateMeter PageData][!Redraw]

---Meters---

[PageData]
Meter=String
X=(600/2)
Y=(350/2)
W=600
H=350
FontFace=Consolas
FontSize=12
FontColor=255,255,255,255
FontEffectColor=0,0,0,255
StringEffect=Shadow
StringAlign=CenterCenter
AntiAlias=1
ClipString=2
MeasureName=Data
Text=Data: %1
As you can see, the Page measure is commanding the Data measure to "Update" from its FinishAction (well, not the usual update for measures, but retrieving the resource in the case of WebParsers), meaning that once the 1st measure downloads the resource, the 2nd one can then parse the resulting text file written by the 1st (make a habit of using built-in path variables instead of hardcoded paths for stuff like your Data.txt file, otherwise your skins won't work on other systems or if paths change).

The EnableMeasure and UpdateMeasure in Page, as well as the Disabled=1 option in Data are just to avoid a missing file error from the 2nd measure in the log, if the Data.txt file has not been created yet (by starting with the 2nd measure initially disabled and enabling it only after the file has been created). The UpdateRate=-1 in Data is to make the measure retrieve the resource just once, and any other subsequent retrievals to be done manually, on demand, like done when commanding it to "Update" from Page, for example. The rest is just basic webparsing like we've done before.

References:
- https://docs.rainmeter.net/manual/measures/webparser/#FinishAction
- https://docs.rainmeter.net/manual/measures/webparser/#CommandMeasureUpdate

By the way, if you ever want to manually do the whole thing on a click or something, all you need is a [!CommandMeasure Page "Update"], since its FinishAction will handle the rest automatically.


Here is how to do it with a WebView and a WebParser (a bit redundant given the first variant, and the [SkinFolder]\DownloadFile\Data.txt file must already exist in this case for the !WriteKeyValue from Javascript to work):
[SkinFolder]\@Resources\Page.html:

Code: Select all

<!DOCTYPE html>
<html>
  <body style="margin: 0; background-color: red;">
    <script>
      var r = new XMLHttpRequest();
      r.onreadystatechange = function()
      {
        if (r.readyState == 4 && r.status == 200)
        {
          let page = r.response, file = RainmeterAPI.GetVariable('CURRENTPATH') + 'DownloadFile\\Data.txt';
          let bang = '[!WriteKeyValue Variables Page """' + page + '""" "' + file + '"][!EnableMeasure Data][!UpdateMeasure Data][!CommandMeasure Data "Update"]';
          RainmeterAPI.Bang(bang);
        };
      };
      r.open('GET', 'https://api.allorigins.win/get?url=' + encodeURIComponent('https://www.google.com'), true); r.responseType = 'text'; r.send();
    </script>
  </body>
</html>
[SkinFolder]\Skin.ini:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
BackgroundMode=2
SolidColor=0,0,0,128

---Measures---

[Page]
Measure=Plugin
Plugin=WebView
X=0
Y=0
W=5
H=5
URL=file:///#@#Page.html
UpdateDivider=600

[Data]
Disabled=1
Measure=WebParser
URL=file://#CURRENTPATH#DownloadFile\Data.txt
RegExp=(?siU)^(.*)$
StringIndex=1
UpdateRate=-1
FinishAction=[!UpdateMeter PageData][!Redraw]

---Meters---

[PageData]
Meter=String
X=(600/2)
Y=(350/2)
W=600
H=350
FontFace=Consolas
FontSize=12
FontColor=255,255,255,255
FontEffectColor=0,0,0,255
StringEffect=Shadow
StringAlign=CenterCenter
AntiAlias=1
ClipString=2
MeasureName=Data
Text=Data: %1


Both of the above should get you the entire contents of the Data.txt file in the Data measure via its RegExp and StringIndex options every 10 minutes (through the UpdateRate and UpdateDivider options which are in seconds because Update=1000 milliseconds), but of course you can get rid of the StringIndex one in this measure and just add more WebParser child measures to get specific parts of the file contents separately.

That's all there is to it, really. Next, checking the manual and its examples a bit as well as how regex patterns are built and adjusting things to your preference should move you forward towards achieving your goal. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
Kotofanchik
Posts: 99
Joined: March 15th, 2024, 7:30 pm

Re: PluginWebView - Make skin using web technology

Post by Kotofanchik »

Thanks, I'll look into it.
I'm interested in writing to a file for two and a half reasons. It seems to me that webparser is more convenient to work with than regexpsubstitute, maybe this is my personal understanding. Secondly, I want to work with existing skins with minimal changes. simply by redirecting them to a local file instead of a URL. Well, thirdly, it may be possible to simplify checking the skin without updating the data from the site every time.
User avatar
Yincognito
Rainmeter Sage
Posts: 7206
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: PluginWebView - Make skin using web technology

Post by Yincognito »

Kotofanchik wrote: April 2nd, 2024, 1:24 pm Thanks, I'll look into it.
I'm interested in writing to a file for two and a half reasons. It seems to me that webparser is more convenient to work with than regexpsubstitute, maybe this is my personal understanding. Secondly, I want to work with existing skins with minimal changes. simply by redirecting them to a local file instead of a URL. Well, thirdly, it may be possible to simplify checking the skin without updating the data from the site every time.
Sure thing. Yeah, most folks prefer RegExp in a WebParser measure, rather than a (regex) Substitute in a String measure, for the same reasons. It is indeed more convenient and clear like that, I was just pointing out that you'd still have to deal with regular expression patterns either way, that's all. Saving the response to a local file first can workaround some occasional issues with parsing the URL address response directly. Hopefully some of these will work for your case, though I'd be cautious and not getting my hopes too high on that one. :confused:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
Kotofanchik
Posts: 99
Joined: March 15th, 2024, 7:30 pm

Re: PluginWebView - Make skin using web technology

Post by Kotofanchik »

Your help is invaluable. And it gives me the strength to help other people in matters in which I am competent again and again. :D
Kotofanchik
Posts: 99
Joined: March 15th, 2024, 7:30 pm

Re: PluginWebView - Make skin using web technology

Post by Kotofanchik »

Something isn't working. Rainmeter\Skins\test3\DownloadFile\Data.txt file is empty
It also started causing the entire Rainmeter to freeze. I didn’t do anything, I see it froze, now it constantly freezes with test3
!WriteKeyValue: File not found: C:\Users\RmicroN\Documents\Rainmeter\Skins\test3\ + f +
You do not have the required permissions to view the files attached to this post.
Kotofanchik
Posts: 99
Joined: March 15th, 2024, 7:30 pm

Re: PluginWebView - Make skin using web technology

Post by Kotofanchik »

I think about everything. why is api.allorigins.win here? I don’t understand the capabilities of Webwiev, but isn’t it easier to save a file using its ability to save to a file?
Maybe it’s simpler as I originally suggested:
Webwiev opens the specified site and receives a command to save its contents or overwrite it and that's it. and do it at intervals. Or is this impossible?
Well, and by the way, once again why webparser is not suitable. He cannot get to the desired site, but webwiev can.
Perhaps the option with api.allorigins.win will also work. But it hasn't been possible to check yet. Now the site works without human verification and I don’t know how the different ways will work.