It does this in the form of a version/update checker which contacts the GitHub server to get the latest release version information of a particular repository (they have an API for that).
It can then compare the latest release version against a current version, and if a newer version is found it can send the Notification to Touch Portal for display.
The Notification contains a link to download the latest version. If the user clicks on that link, a callback function is executed in this code which opens the default Web browser to the desired URL.
16var checkReleaseVersion =
function(user_repo, current_version, show_notification =
false)
19 const url =
"https://api.github.com/repos/" + user_repo +
"/releases/latest";
23 Net.fetch(url, { rejectOnError:
true })
26 .then(response => response.json())
30 if (result.tag_name !== undefined) {
32 const currVersion = versionStringToNumber(current_version);
33 const newVersion = versionStringToNumber(result.tag_name);
34 const hasNewVersion = newVersion > currVersion;
37 let logText = `The latest release date is ${result.published_at};\n`;
38 logText += `The latest tag is ${result.tag_name}; Current version: ${current_version};\n`;
39 logText += `Latest release version ${newVersion.toString(16)}; Current version: ${currVersion.toString(16)}\n\n`;
42 logText +=
"The latest released version is newer!\n" +
43 `Click below or go to\n<${result.html_url}>\nfor downloads.`;
44 else if (newVersion == currVersion)
45 logText +=
"The latest release version is same as current.";
47 logText +=
"Congratulations, you're running a development version! (-8";
50 console.log(
'Version Check Report:\n' + logText);
53 if (show_notification && hasNewVersion)
62 title:
"Go To Download"
68 let callback =
function(choiceId, notificationId) {
69 console.log(`The option ID
'${choiceId}' was selected
for notification ID
'${notificationId}'.`);
72 new Process().startCommand(`explorer
"${result.html_url}"`);
74 new Process().startCommand(`open
"${result.html_url}"`);
76 new Process().startCommand(`xdg-open
"${result.html_url}"`);
81 "New Version Available",
93 console.warn(
"Could not find tag name in returned data :-( ");
110function versionStringToNumber(version)
113 version = version.replace(/([\d\.]+)/,
'$1');
114 for (
const part of version.split(
'.', 4))
115 iVersion = iVersion << 8 | ((parseInt(part) || 0) & 0xFF);
The DSE object contains constants and functions related to the plugin environment....
String PLATFORM_OS
This property contains the name of the operating system running the plugin.
Definition: DSE.h:95
The Process class allows interaction with external processes, such as launching a system command or r...
Definition: Process.h:62
The global TP namespace is used as a container for all Touch Portal API methods, which are invoked wi...
Definition: touchportal.dox:7
void showNotification(String notificationId, String title, String message, Array< Object > options=[],< Function|String|Array > callback=null)
Creates or raises a user notification in the Touch Portal window.
The Net namespace contains static functions for working with network requests.
Definition: fetch.dox:4