mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-10 07:00:22 +02:00
Merge pull request #658 from kasenvr/feature/add-update-notififier
Feature/add update notififier
This commit is contained in:
commit
b02205e5b8
6 changed files with 149 additions and 4 deletions
|
@ -23,6 +23,7 @@ var CONTROL_KEY = 67108864;
|
||||||
var SHIFT_KEY = 33554432;
|
var SHIFT_KEY = 33554432;
|
||||||
var FLOOF_CHAT_CHANNEL = "Chat";
|
var FLOOF_CHAT_CHANNEL = "Chat";
|
||||||
var FLOOF_NOTIFICATION_CHANNEL = "Floof-Notif";
|
var FLOOF_NOTIFICATION_CHANNEL = "Floof-Notif";
|
||||||
|
var SYSTEM_NOTIFICATION_CHANNEL = "System-Notifications";
|
||||||
|
|
||||||
var MAIN_CHAT_WINDOW_HEIGHT = 450;
|
var MAIN_CHAT_WINDOW_HEIGHT = 450;
|
||||||
var MAIN_CHAT_WINDOW_WIDTH = 750;
|
var MAIN_CHAT_WINDOW_WIDTH = 750;
|
||||||
|
@ -79,6 +80,7 @@ init();
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
Messages.subscribe(FLOOF_CHAT_CHANNEL);
|
Messages.subscribe(FLOOF_CHAT_CHANNEL);
|
||||||
|
Messages.subscribe(SYSTEM_NOTIFICATION_CHANNEL);
|
||||||
historyLog = [];
|
historyLog = [];
|
||||||
try {
|
try {
|
||||||
historyLog = JSON.parse(Settings.getValue(settingsRoot + "/HistoryLog", "[]"));
|
historyLog = JSON.parse(Settings.getValue(settingsRoot + "/HistoryLog", "[]"));
|
||||||
|
@ -435,8 +437,8 @@ function replaceFormatting(text) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function messageReceived(channel, message) {
|
function messageReceived(channel, message, sender) {
|
||||||
if (channel === "Chat") {
|
if (channel === FLOOF_CHAT_CHANNEL) {
|
||||||
var cmd = {FAILED: true};
|
var cmd = {FAILED: true};
|
||||||
try {
|
try {
|
||||||
cmd = JSON.parse(message);
|
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() {
|
function time() {
|
||||||
|
@ -569,7 +591,9 @@ function fromQml(message) {
|
||||||
cmd = processChat(cmd);
|
cmd = processChat(cmd);
|
||||||
if (cmd.message === "") return;
|
if (cmd.message === "") return;
|
||||||
Messages.sendMessage(FLOOF_CHAT_CHANNEL, JSON.stringify({
|
Messages.sendMessage(FLOOF_CHAT_CHANNEL, JSON.stringify({
|
||||||
type: "TransmitChatMessage", channel: "Domain", colour: chatColour("Domain"),
|
type: "TransmitChatMessage",
|
||||||
|
channel: "Domain",
|
||||||
|
colour: chatColour("Domain"),
|
||||||
message: cmd.message,
|
message: cmd.message,
|
||||||
displayName: cmd.avatarName
|
displayName: cmd.avatarName
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -36,7 +36,8 @@ var DEFAULT_SCRIPTS_COMBINED = [
|
||||||
"system/miniTablet.js",
|
"system/miniTablet.js",
|
||||||
"system/audioMuteOverlay.js",
|
"system/audioMuteOverlay.js",
|
||||||
"system/inspect.js",
|
"system/inspect.js",
|
||||||
"system/keyboardShortcuts/keyboardShortcuts.js"
|
"system/keyboardShortcuts/keyboardShortcuts.js",
|
||||||
|
"system/checkForUpdates.js"
|
||||||
];
|
];
|
||||||
var DEFAULT_SCRIPTS_SEPARATE = [
|
var DEFAULT_SCRIPTS_SEPARATE = [
|
||||||
"system/controllers/controllerScripts.js",
|
"system/controllers/controllerScripts.js",
|
||||||
|
|
54
scripts/system/checkForUpdates.js
Normal file
54
scripts/system/checkForUpdates.js
Normal file
|
@ -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 = About.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 vircadiaMetadata = retrieveMetadata();
|
||||||
|
|
||||||
|
// Don't check for updates on a dev build.
|
||||||
|
if (vircadiaMetadata && currentVersion !== "dev") {
|
||||||
|
var checkVersion = semanticVersionCompare(currentVersion, vircadiaMetadata[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 + vircadiaMetadata[currentBuildType].version,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkForUpdates();
|
|
@ -17,6 +17,7 @@ Script.include("/~/system/libraries/Xform.js");
|
||||||
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
||||||
Script.include("/~/system/libraries/controllers.js");
|
Script.include("/~/system/libraries/controllers.js");
|
||||||
Script.include("/~/system/libraries/cloneEntityUtils.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";
|
var DEFAULT_SPHERE_MODEL_URL = "http://hifi-content.s3.amazonaws.com/alan/dev/equip-Fresnel-3.fbx";
|
||||||
|
|
14
scripts/system/libraries/networkingConstants.js
Normal file
14
scripts/system/libraries/networkingConstants.js
Normal file
|
@ -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
|
||||||
|
}
|
|
@ -502,3 +502,54 @@ getMainTabletIDs = function () {
|
||||||
}
|
}
|
||||||
return tabletIDs;
|
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) {
|
||||||
|
return -1;
|
||||||
|
} else if (splitA > splitB) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else { // Else, they're both numbers so compare the strings as if they were.
|
||||||
|
if (versionAParts[i] < versionBParts[i]) {
|
||||||
|
return -1;
|
||||||
|
} else if (versionAParts[i] > versionBParts[i]) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// They're both equal!
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue