From 68055f24587b0cb3276a04176a1365578bc9eaff Mon Sep 17 00:00:00 2001 From: Kalila L Date: Thu, 27 Aug 2020 05:30:45 -0400 Subject: [PATCH] Add update checker and notifier for Interface. --- scripts/system/checkForUpdates.js | 54 +++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 scripts/system/checkForUpdates.js diff --git a/scripts/system/checkForUpdates.js b/scripts/system/checkForUpdates.js new file mode 100644 index 0000000000..932dffafcc --- /dev/null +++ b/scripts/system/checkForUpdates.js @@ -0,0 +1,54 @@ +// checkForUpdates.js +// +// Created by Kalila L. on 8/27/20 +// Copyright 2020 Vircadia contributors. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + +Script.include("/~/system/libraries/utils.js"); +var networkingConstants = Script.require("./libraries/networkingConstants.js"); + +// We'll want a way to specify this later, auto detection can also be a thing, but strictly optional. +var currentBuildType = "latest"; +var currentVersion = HifiAbout.buildVersion; + +// Notification Variables +var NOTIFICATION_CHANNEL = "System-Notifications"; +var NOTIFICATION_TYPE = "Update-Notification"; +var NOTIFICATION_CATEGORY = "Interface"; +var notificationText = "An update is available: "; +var notificationColor = { red: 137, green: 63, blue: 255 }; + +function retrieveMetadata() { + var requireMetadata = Script.require(networkingConstants.interfaceMetadataSource + '?' + Date.now()); + + if (requireMetadata) { + return requireMetadata; + } else { + return false; + } +} + +function checkForUpdates() { + var retrievedMetadata = retrieveMetadata(); + + // Don't check for updates on a dev build. + if (retrievedMetadata && currentVersion !== "dev") { + var checkVersion = semanticVersionCompare(currentVersion, retrievedMetadata[currentBuildType].version); + + // An update is available! + if (checkVersion === -1) { + Messages.sendMessage(NOTIFICATION_CHANNEL, JSON.stringify({ + type: NOTIFICATION_TYPE, + category: NOTIFICATION_CATEGORY, + channel: "Local", + position: MyAvatar.position, + colour: notificationColor, + message: notificationText + retrievedMetadata[currentBuildType].version, + })); + } + } +} + +checkForUpdates();