It is currently March 29th, 2024, 12:59 am

Creating an update checker using GitHub

Tips and Tricks from the Rainmeter Community
User avatar
raiguard
Posts: 660
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Creating an update checker using GitHub

Post by raiguard »

Image

NOTE: This is NOT a tutorial on how to use GitHub with Rainmeter. I am working on a tutorial on how to set up multiple repositories in the skins folder at once, but for now you'll have to figure it out by Googling it. Once you know how to use Git and GitHub, we can get started.

For this tutorial, I will walk through the code for a simple update checking sample skin, which you can download in the attachments section. Download and install the skin so you can follow along in the code.

First and foremost, this skin uses a GitHub repository to check a version number contained within a file in that repository. I'm not going to go over anything about using GitHub, but I will say this: You must have a file in the repo which contains only the version number of the latest released version of your skin. Once you do that, you're ready to implement the update checker!

The update checker consists of two main variables: 'version' and 'githubCurrentReleaseVerFilePath'. 'version' is simply the current version of your skin pack, and you will need to update the variable every time you release a new skin pack version. 'githubCurrentReleaseVerFilePath' is where you put the URL leading to the file discussed earlier. For example, in my illustro Gadgets skin pack the URL is "https://github.com/iamanai/illustro-Gadgets/blob/master/CurrentReleaseVer.txt". Once you get this set up, the update checker will do its work when the skin is refreshed.

How to implement with your own skins
The update checker uses various measures to break down a version number you provide, break down the version number provided via GitHub, and perform a subtraction between the two to determine whether your version is more recent or older. If the numbers subtract to a positive value, you have an old version. If they subtract to 0, you're up to date. And if they subtract to a negative number, you are using an unreleased version.

The code below does this:

Code: Select all

[MeasureVersionAbsolute]
Measure=String
String=#version#
Substitute=".":"","-d":""

[MeasureIPAddress]
Measure=Plugin
Plugin=WebParser
UpdateRate=1000
Url="#githubCurrentReleaseVerFilePath#"
RegExp="(?siU)<td id="LC1" class="blob-code blob-code-inner js-file-line">(.*)</td>.*"
FinishAction=[!EnableMeasure MeasureVersionCheck]

[MeasureCurrentReleaseVer]
Measure=Plugin
Plugin=WebParser
Url=[MeasureIPAddress]
StringIndex=1

[MeasureCurrentReleaseVerAbsolute]
Measure=Plugin
Plugin=WebParser
Url=[MeasureIPAddress]
StringIndex=1
Substitute=".":"","-d":""

[MeasureVersionCheck]
Measure=Calc
Formula=[MeasureCurrentReleaseVerAbsolute] - [MeasureVersionAbsolute]
IfAboveValue=0
IfAboveAction=[!SetOption UpdateCheckerString MeterStyle "StyleText | StyleUpdateCheckerYes"][!Redraw]
IfEqualValue=0
IfEqualAction=[!SetOption UpdateCheckerString MeterStyle "StyleText | StyleUpdateCheckerNo"][!Redraw]
IfBelowValue=0
IfBelowAction=[!SetOption UpdateCheckerString MeterStyle "StyleText | StyleUpdateCheckerDev"][!Redraw]
DynamicVariables=1
Disabled=1
There are a few styles you need to have as well:

Code: Select all

[StyleUpdateCheckerConnecting]
Text="Update: Connecting to GitHub..."

[StyleUpdateCheckerYes]
Text="Update: v[MeasureCurrentReleaseVer] is available!"

[StyleUpdateCheckerNo]
Text="Update: Up to date"

[StyleUpdateCheckerDev]
Text="Update: Using dev version"
These styles are manipulated with the [MeasureVersionCheck] measure and change what the update checker's text is displaying. Keep in mind that you will need to rename 'UpdateCheckerString' to the name of the meter you use to display the update checker for this to work.

That's the most simple explanation I could come up with. If anybody has any questions, please feel free to leave a comment! I'll rewrite/restructure this tutorial if any new issues or questions crop up.
You do not have the required permissions to view the files attached to this post.
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017