It is currently March 28th, 2024, 11:23 pm

HOWTO: Easily add update checking to your skins.

Tips and Tricks from the Rainmeter Community
slartibartfast
Posts: 15
Joined: September 10th, 2012, 3:42 pm

HOWTO: Easily add update checking to your skins.

Post by slartibartfast »

As I gradually increased the functionality of my multiFEED skin, I began to wish for an easy way to allow the skin to notify the user if there was a new version available. After a bit of conscious and subconscious cogitation, this what I came up with:

When any application (or skin) wants to know if there is a newer version, it has to look to a server somewhere on the Internet with information about the latest release. Although I maintain my own Web and FTP servers from my home network, I didn't want to put the version lookup server there since I can't guarantee it is up most of the time. The breakthrough came when I realized I could embed the latest version number on my deviantART gallery page, and use WebParser to extract it.

To start, embed the latest version number for your skin in the TITLE of your skin page in your deviantART gallery. Do this in a way that allows you to find it with a WebParser measure. For my multiFEED skin I set the title to the form "multiFEED RSS/Atom Feed Skin v0.0.0"

Next, define a measure to parse the version number for your skin from your gallery web page.

Code: Select all

[MeasureLatestVersion]
Measure=Plugin
Plugin=WebParser
URL="#DeviantARTpage#"
RegExp="(?siU)multiFEED.+([0-9]+\.[0-9]+\.[0-9]+)"
StringIndex=1
UpdateDivider=#UpdateCheckInterval#
Obviously, set the URL variable to point to your gallery, and UpDateDivider to determine how often to check for updates. The regular expression should pull the version off the gallery page as StringIndex one.

With this measure you have everything you need to compare the current skin version with the latest one. You could pop up a child skin in response to a user request for an update check, but I chose a different method that unobtrusively monitors for updates and alerts the user automatically without their intervention.

First I created a small 16x16 PNG icon with a bright Alert/Warning image. Then I converted it to B&W and saved it under a different name. I named them Alert0.png and Alert1.png (you'll see why below). Next I created a timer than alternates between zero and one just under once per second.

Code: Select all

[MeasureAlertFlasher]
Measure=Calc
Formula="(MeasureAlertFlasher=1)?0:1"
UpdateDivider=7
My base skin update interval is 100ms, so this timer switches states every 700ms. Next, we need a meter to display the flashing alert.

Code: Select all

[MeterUpdateAlert]
Meter=Image
MeasureName=MeasureAlertFlasher
MeasureName2=MeasureLatestVersion
ImageName=#CURRENTPATH#Alert%1.png
ToolTipText="New Version Available (%2). Click here to download it."
Hidden=1
LeftMouseUpAction="#DeviantPage#"
Note that we use two MeasureName variables. The first is the timer we set up earlier, and the second is the latest version string we got from our deviantART gallery page. By specifying the ImageName with "%1" in it, the image displayed is switched between Alert0.png and Alert1.png every time the timer changes states. "%2" holds the latest version string, so we can use it in the ToolTipText to include the new version number in the popup when the user hovers over the alert icon. The LeftMouseUpAction="#DeviantPage#" takes the user to your devianART gallery if they click on the alert icon. Notice also that the meter has Hidden=1, so it won't be displayed at all until we have time for WebParser to read the latest version from the Internet. We'll change that formula after the main WebParser measure finishes executing the first time by executing a !SetOption bang.

Code: Select all

[MeasureLatestVersion]
..
..
FinishAction=[!SetOption MeterUpdateAlert Hidden "([*MeasureHideNewVersionAlert*])"]
The asterisks in the new Hidden= formula definition prevent it from being substitued when the bang executes. What is missing is that [MeasureHideNewVersionAlert] measure that allows the Alert image to show only if there is a new version available. Since there is no way to compare two string values in the Hidden= formula directly, we'll use a LUA script to do this instead.

Code: Select all

--HideNewVersionAlert.lua
function Update()

	LatestVersion = SKIN:GetMeasure('MeasureLatestVersion'):GetStringValue()
	CurrentVersion = SKIN:GetVariable('Version')
	if (CurrentVersion=="" or CurrentVersion==LatestVersion) then
		return 1
	else
		return 0
	end
	
end -- function Update
We not only compare for string equality, but also for an empty new version string so we don't display the alert if the WebParser is unable to get the new version from the gallery page. Now, create a measure to use the new script.

Code: Select all

[MeasureHideNewVersionAlert]
Measure=Script
ScriptFile=#CURRENTPATH#HideNewVersionAlert.lua
Now, with this new measure the [MeterUpdateAlert] will be hidden unless the skin version doesn't match the latest version number retrieved from the deviantART gallery page.

That's it! Your skin will now alert the user if there is a new version available, and take them directly to your deviantART gallery to download it if they click on the flashing alert. Of course, you could embed the latest skin version number on any web page you have control over, not just your deviantART gallery. If you can define the actual HTML for the page, you can even hide the version number in metadata so the viewer won't see it.

Hope this proves useful as you build and publish your new skins.

Slarti
User avatar
exper1mental
Posts: 269
Joined: January 9th, 2013, 7:52 pm
Location: Clemson University

Re: HOWTO: Easily add update checking to your skins.

Post by exper1mental »

Nice man! This was just what I was looking for!
Image
CyrDaan
Posts: 12
Joined: November 18th, 2012, 9:55 am

Re: HOWTO: Easily add update checking to your skins.

Post by CyrDaan »

Nvm :] I figured out that I just had to have my URL in ""
XD anyways thank you for this, I will definatly reference you in my skins from now on!
Follow me on Twitter @CyrDaan for updates on old skins and when new skins are released.