From bfdcdee96b627faa62dea54e1c49d4d97e8d3616 Mon Sep 17 00:00:00 2001 From: Kalila L Date: Thu, 27 Aug 2020 01:52:21 -0400 Subject: [PATCH 1/9] Attempt to fix isInEditMode error on line 780. --- scripts/system/controllers/controllerModules/equipEntity.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/system/controllers/controllerModules/equipEntity.js b/scripts/system/controllers/controllerModules/equipEntity.js index 54b56ff271..1deb97c20e 100644 --- a/scripts/system/controllers/controllerModules/equipEntity.js +++ b/scripts/system/controllers/controllerModules/equipEntity.js @@ -17,6 +17,7 @@ Script.include("/~/system/libraries/Xform.js"); Script.include("/~/system/libraries/controllerDispatcherUtils.js"); Script.include("/~/system/libraries/controllers.js"); Script.include("/~/system/libraries/cloneEntityUtils.js"); +Script.include("/~/system/libraries/utils.js"); var DEFAULT_SPHERE_MODEL_URL = "http://hifi-content.s3.amazonaws.com/alan/dev/equip-Fresnel-3.fbx"; From d45c283f3b8e7377a585670f4036572f90e39845 Mon Sep 17 00:00:00 2001 From: Kalila L Date: Thu, 27 Aug 2020 03:53:04 -0400 Subject: [PATCH 2/9] Add semanticVersionCompare function to utils.js --- scripts/system/libraries/utils.js | 55 +++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/scripts/system/libraries/utils.js b/scripts/system/libraries/utils.js index d5155ff465..ff467b1f5b 100644 --- a/scripts/system/libraries/utils.js +++ b/scripts/system/libraries/utils.js @@ -502,3 +502,58 @@ getMainTabletIDs = function () { } return tabletIDs; }; + +// returns 1 if A is greater, 0 if equal, -1 if A is lesser +semanticVersionCompare = function(versionA, versionB) { + var versionAParts = versionA.split('.'); + var versionBParts = versionB.split('.'); + + // make sure each version has 3 parts + var partsLength = versionAParts.length; + while (partsLength < 3) { + partsLength = versionAParts.push(0); + } + + partsLength = versionBParts.length; + while (partsLength < 3) { + partsLength = versionBParts.push(0); + } + + for (var i = 0; i < 3; ++i) { + // We're detecting if there's tags, indicating a pre-release OR it's obsolete. + var versionAPartHasTag = (versionAParts[i].indexOf('-') !== -1); + var versionBPartHasTag = (versionBParts[i].indexOf('-') !== -1); + + if (versionAPartHasTag || versionBPartHasTag) { + // In semantic versioning, if version A has a tag and B does not, B is a higher version. + if (versionAPartHasTag < versionBPartHasTag) { + return 1; + } else if (versionAPartHasTag > versionBPartHasTag) { + return -1; + } else { + // They both have tags + var splitA = versionAParts[i].split('-')[0]; + var splitB = versionBParts[i].split('-')[0]; + + if (splitA == splitB) { + continue; + } else if (splitA > splitB) { + return 1; + } else { + return -1; + } + } + } else { // Else, they're both numbers so compare the strings as if they were. + if (versionAParts[i] == versionBParts[i]) { + continue; + } else if (versionAParts[i] > versionBParts[i]) { + return 1; + } else { + return -1; + } + } + } + + // They're both equal! + return 0; +} From 2d7a640935e33d560834469835a189caf3960a2c Mon Sep 17 00:00:00 2001 From: Kalila L Date: Thu, 27 Aug 2020 05:27:47 -0400 Subject: [PATCH 3/9] Create networkingConstants.js --- scripts/system/libraries/networkingConstants.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 scripts/system/libraries/networkingConstants.js diff --git a/scripts/system/libraries/networkingConstants.js b/scripts/system/libraries/networkingConstants.js new file mode 100644 index 0000000000..95e91c7f85 --- /dev/null +++ b/scripts/system/libraries/networkingConstants.js @@ -0,0 +1,14 @@ +// networkingConstants.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 + +// Interface Metadata Source +var interfaceMetadataSource = "https://cdn.vircadia.com/dist/launcher/vircadiaMeta.json"; + +module.exports = { + interfaceMetadataSource: interfaceMetadataSource +} From e8526aa6b75458918d2161a1a321a2f416c5b32e Mon Sep 17 00:00:00 2001 From: Kalila L Date: Thu, 27 Aug 2020 05:28:07 -0400 Subject: [PATCH 4/9] Update chat to accept system notifications. --- scripts/communityScripts/chat/FloofChat.js | 30 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/scripts/communityScripts/chat/FloofChat.js b/scripts/communityScripts/chat/FloofChat.js index d1324bd560..b558e52bf8 100644 --- a/scripts/communityScripts/chat/FloofChat.js +++ b/scripts/communityScripts/chat/FloofChat.js @@ -23,6 +23,7 @@ var CONTROL_KEY = 67108864; var SHIFT_KEY = 33554432; var FLOOF_CHAT_CHANNEL = "Chat"; var FLOOF_NOTIFICATION_CHANNEL = "Floof-Notif"; +var SYSTEM_NOTIFICATION_CHANNEL = "System-Notifications"; var MAIN_CHAT_WINDOW_HEIGHT = 450; var MAIN_CHAT_WINDOW_WIDTH = 750; @@ -79,6 +80,7 @@ init(); function init() { Messages.subscribe(FLOOF_CHAT_CHANNEL); + Messages.subscribe(SYSTEM_NOTIFICATION_CHANNEL); historyLog = []; try { historyLog = JSON.parse(Settings.getValue(settingsRoot + "/HistoryLog", "[]")); @@ -435,8 +437,8 @@ function replaceFormatting(text) { } } -function messageReceived(channel, message) { - if (channel === "Chat") { +function messageReceived(channel, message, sender) { + if (channel === FLOOF_CHAT_CHANNEL) { var cmd = {FAILED: true}; try { cmd = JSON.parse(message); @@ -518,6 +520,26 @@ function messageReceived(channel, message) { } } } + + if (channel === SYSTEM_NOTIFICATION_CHANNEL && sender == MyAvatar.sessionUUID) { + var cmd = {FAILED: true}; + try { + cmd = JSON.parse(message); + } catch (e) { + // + } + if (!cmd.FAILED) { + if (cmd.type === "Update-Notification") { + addToLog(cmd.message, cmd.category, cmd.colour, cmd.channel); + + Messages.sendLocalMessage(FLOOF_NOTIFICATION_CHANNEL, JSON.stringify({ + sender: "(" + cmd.category + ")", + text: replaceFormatting(cmd.message), + colour: {text: cmd.colour} + })); + } + } + } } function time() { @@ -569,7 +591,9 @@ function fromQml(message) { cmd = processChat(cmd); if (cmd.message === "") return; Messages.sendMessage(FLOOF_CHAT_CHANNEL, JSON.stringify({ - type: "TransmitChatMessage", channel: "Domain", colour: chatColour("Domain"), + type: "TransmitChatMessage", + channel: "Domain", + colour: chatColour("Domain"), message: cmd.message, displayName: cmd.avatarName })); From 68055f24587b0cb3276a04176a1365578bc9eaff Mon Sep 17 00:00:00 2001 From: Kalila L Date: Thu, 27 Aug 2020 05:30:45 -0400 Subject: [PATCH 5/9] 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(); From 4836f4b369d0810992aef331a4f8b6861767bb89 Mon Sep 17 00:00:00 2001 From: Kalila L Date: Thu, 27 Aug 2020 05:32:07 -0400 Subject: [PATCH 6/9] NOTE: Undo commit before merging, for testing purposes only. --- scripts/system/checkForUpdates.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/system/checkForUpdates.js b/scripts/system/checkForUpdates.js index 932dffafcc..6a16a98877 100644 --- a/scripts/system/checkForUpdates.js +++ b/scripts/system/checkForUpdates.js @@ -11,7 +11,7 @@ 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; +var currentVersion = "2020.2.3-Asteria"; // HifiAbout.buildVersion; // Notification Variables var NOTIFICATION_CHANNEL = "System-Notifications"; From abac59c09b733f9671838179828a83a89338c5bd Mon Sep 17 00:00:00 2001 From: Kalila L Date: Thu, 27 Aug 2020 05:38:50 -0400 Subject: [PATCH 7/9] Add checkForUpdates.js to the defaultScripts.js --- scripts/defaultScripts.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/defaultScripts.js b/scripts/defaultScripts.js index 92a262a3e3..7e7bb12440 100644 --- a/scripts/defaultScripts.js +++ b/scripts/defaultScripts.js @@ -36,7 +36,8 @@ var DEFAULT_SCRIPTS_COMBINED = [ "system/miniTablet.js", "system/audioMuteOverlay.js", "system/inspect.js", - "system/keyboardShortcuts/keyboardShortcuts.js" + "system/keyboardShortcuts/keyboardShortcuts.js", + "system/checkForUpdates.js" ]; var DEFAULT_SCRIPTS_SEPARATE = [ "system/controllers/controllerScripts.js", From 0b1dce14a0b526f1b90866a40bf2349797371dd2 Mon Sep 17 00:00:00 2001 From: kasenvr <52365539+kasenvr@users.noreply.github.com> Date: Sun, 30 Aug 2020 13:56:09 -0400 Subject: [PATCH 8/9] Apply suggestions from code review Co-authored-by: David Rowe --- scripts/system/libraries/utils.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/scripts/system/libraries/utils.js b/scripts/system/libraries/utils.js index ff467b1f5b..c7c30a58dd 100644 --- a/scripts/system/libraries/utils.js +++ b/scripts/system/libraries/utils.js @@ -535,21 +535,17 @@ semanticVersionCompare = function(versionA, versionB) { var splitA = versionAParts[i].split('-')[0]; var splitB = versionBParts[i].split('-')[0]; - if (splitA == splitB) { - continue; + if (splitA < splitB) { + return -1; } else if (splitA > splitB) { return 1; - } else { - return -1; } } } else { // Else, they're both numbers so compare the strings as if they were. - if (versionAParts[i] == versionBParts[i]) { - continue; + if (versionAParts[i] < versionBParts[i]) { + return -1; } else if (versionAParts[i] > versionBParts[i]) { return 1; - } else { - return -1; } } } From ec25ac9e7dc9c25f70bf5c46c369e71564a652e7 Mon Sep 17 00:00:00 2001 From: Kalila L Date: Sun, 30 Aug 2020 13:57:45 -0400 Subject: [PATCH 9/9] Update checkForUpdates.js "retrievedMetadata" -> "vircadiaMetadata" --- scripts/system/checkForUpdates.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/system/checkForUpdates.js b/scripts/system/checkForUpdates.js index 6a16a98877..724cd0a68d 100644 --- a/scripts/system/checkForUpdates.js +++ b/scripts/system/checkForUpdates.js @@ -31,11 +31,11 @@ function retrieveMetadata() { } function checkForUpdates() { - var retrievedMetadata = retrieveMetadata(); + var vircadiaMetadata = retrieveMetadata(); // Don't check for updates on a dev build. - if (retrievedMetadata && currentVersion !== "dev") { - var checkVersion = semanticVersionCompare(currentVersion, retrievedMetadata[currentBuildType].version); + if (vircadiaMetadata && currentVersion !== "dev") { + var checkVersion = semanticVersionCompare(currentVersion, vircadiaMetadata[currentBuildType].version); // An update is available! if (checkVersion === -1) { @@ -45,7 +45,7 @@ function checkForUpdates() { channel: "Local", position: MyAvatar.position, colour: notificationColor, - message: notificationText + retrievedMetadata[currentBuildType].version, + message: notificationText + vircadiaMetadata[currentBuildType].version, })); } }