From 2de46284cc806130f0b2df8908cbb1de469e2127 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Wed, 12 Jun 2019 17:13:51 -0600 Subject: [PATCH] Improve upgrade required screen --- www/css/app.css | 7 ++++ www/index.html | 2 +- www/js/api.js | 58 ++++++++++++++++++++++++++++++ www/js/main.js | 78 +++++++++++++--------------------------- www/js/platform.js | 12 +++++++ www/pages/upgrade.html | 19 +++++++++- www/routes.js | 7 ++-- www/settings.template.js | 11 ++++++ 8 files changed, 136 insertions(+), 58 deletions(-) diff --git a/www/css/app.css b/www/css/app.css index ba184a3..e6ef9ac 100644 --- a/www/css/app.css +++ b/www/css/app.css @@ -4,6 +4,13 @@ License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +/* +Framework7 and FontAwesome both have a .fab class +*/ +.fafab { + font-family: "Font Awesome 5 Brands"; +} + #app.framework7-root { padding-top: 0px; } diff --git a/www/index.html b/www/index.html index 4c09a47..6d917fb 100644 --- a/www/index.html +++ b/www/index.html @@ -7,10 +7,10 @@ + - diff --git a/www/js/api.js b/www/js/api.js index 3ef5d20..c797383 100644 --- a/www/js/api.js +++ b/www/js/api.js @@ -13,6 +13,64 @@ function getActionUrl(action) { return SETTINGS["server"] + "/" + action; } +/** + * Compare two version strings. + * http://stackoverflow.com/a/16187766/2534036 + * @param {string} a + * @param {string} b + * @returns a number < 0 if a < b, a number > 0 if a > b, 0 if a = b + */ +function compareVersions(a, b) { + var i, diff; + var regExStrip0 = /(\.0+)+$/; + var segmentsA = a.replace(regExStrip0, '').split('.'); + var segmentsB = b.replace(regExStrip0, '').split('.'); + var l = Math.min(segmentsA.length, segmentsB.length); + + for (i = 0; i < l; i++) { + diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10); + if (diff) { + return diff; + } + } + return segmentsA.length - segmentsB.length; +} + +function checkClientVersion(success, failure) { + return $.ajax({ + type: 'GET', + url: getActionUrl("version.txt"), + timeout: 5000, + success: function (version) { + $.getJSON("package.json", {}, function (local) { + if (compareVersions(local.version, version) < 0) { + success(false); + } else { + success(true); + } + }); + }, + error: function (xhr, textStatus, errorThrown) { + if (typeof failure != 'function') { + return; + } + switch (textStatus) { + case "timeout": + failure("Couldn't connect to the server (timeout).", xhr); + break; + case "error": + failure("Couldn't connect to the server (error).", xhr); + break; + case "parseerror": + failure("The server sent a malformed response.", xhr); + break; + default: + failure("Couldn't connect to the server.", xhr); + } + } + }); +} + /** * Call an API function on the server. * @param {string} action diff --git a/www/js/main.js b/www/js/main.js index a07f889..63ae07a 100644 --- a/www/js/main.js +++ b/www/js/main.js @@ -78,29 +78,6 @@ function isServerAlive(callback) { }); } -/** - * Compare two version strings. - * http://stackoverflow.com/a/16187766/2534036 - * @param {string} a - * @param {string} b - * @returns a number < 0 if a < b, a number > 0 if a > b, 0 if a = b - */ -function compareVersions(a, b) { - var i, diff; - var regExStrip0 = /(\.0+)+$/; - var segmentsA = a.replace(regExStrip0, '').split('.'); - var segmentsB = b.replace(regExStrip0, '').split('.'); - var l = Math.min(segmentsA.length, segmentsB.length); - - for (i = 0; i < l; i++) { - diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10); - if (diff) { - return diff; - } - } - return segmentsA.length - segmentsB.length; -} - /** * Check if the saved username and password are valid. * @param {function} callback A function that will be called with a boolean argument indicating validity. @@ -125,39 +102,32 @@ function checkLogin(callback) { if (localStorage.getItem("configured") == null) { router.navigate("/signin"); } else { - isServerAlive(function (yes) { - if (yes) { - callAPI("version", { - username: localStorage.getItem("username"), - password: localStorage.getItem("password") - }, function (data) { - $.getJSON("package.json", {}, function (local) { - if (compareVersions(local.version, data.version) < 0) { - router.navigate("/upgrade"); - } else { - checkLogin(function (valid) { - if (valid) { - callAPI("playerexists", { - username: localStorage.getItem("username"), - password: localStorage.getItem("password") - }, function (resp) { - if (resp.exists == true) { - router.navigate("/home"); - } else { - router.navigate("/chooseteam"); - } - }, function (msg) { - router.navigate("/signin"); - }); - } else { - router.navigate("/signin"); - } - }); - } - }); + checkClientVersion(function (ok) { + if (ok) { + // Version OK + checkLogin(function (valid) { + if (valid) { + callAPI("playerexists", { + username: localStorage.getItem("username"), + password: localStorage.getItem("password") + }, function (resp) { + if (resp.exists == true) { + router.navigate("/home"); + } else { + router.navigate("/chooseteam"); + } + }, function (msg) { + router.navigate("/signin"); + }); + } else { + router.navigate("/signin"); + } }); } else { - router.navigate("/connection"); + // Version incompatible + router.navigate("/upgrade"); } + }, function () { + router.navigate("/connection"); }); } \ No newline at end of file diff --git a/www/js/platform.js b/www/js/platform.js index 437bd82..e22ccbb 100644 --- a/www/js/platform.js +++ b/www/js/platform.js @@ -11,7 +11,11 @@ var platform_theme = "md"; var nw_tray = null; var openBrowser = function (url) { + window.open(url); +} +var openSystemBrowser = function (url) { + window.open(url); } var scanBarcode = function (success, error) { @@ -85,6 +89,10 @@ function initCordova() { cordova.InAppBrowser.open(url, '_blank', 'location=yes'); } + openExternalBrowser = function (url) { + window.open(url, '_system', ''); + } + scanBarcode = function (success, error) { cordova.plugins.barcodeScanner.scan( function (result) { @@ -139,6 +147,10 @@ function initNW() { }); } + openExternalBrowser = function (url) { + require('nw.gui').Shell.openExternal(url); + } + $("body").append(''); scanBarcode = function (success, error) { diff --git a/www/pages/upgrade.html b/www/pages/upgrade.html index c64685e..1d1a3e0 100644 --- a/www/pages/upgrade.html +++ b/www/pages/upgrade.html @@ -13,9 +13,26 @@
-
+

This version of TerranQuest is too old to work properly with the game server.

+ + {{#js_if "platform_type != 'browser'"}} +

Download:

+
+ {{#js_if "platform_type == 'cordova'"}} + {{#each android}} +
{{@key}}
+ {{/each}} + {{/js_if}} + + {{#js_if "platform_type == 'nw'"}} + {{#each nwjs}} +
{{@key}}
+ {{/each}} + {{/js_if}} +
+ {{/js_if}}
diff --git a/www/routes.js b/www/routes.js index 2c20d9a..b3e4aa1 100644 --- a/www/routes.js +++ b/www/routes.js @@ -68,8 +68,11 @@ var routes = [ }, { path: '/upgrade', - url: './pages/upgrade.html', - name: 'upgrade' + templateUrl: './pages/upgrade.html', + name: 'upgrade', + options: { + context: SETTINGS.download_links + } }, { path: '/connection', diff --git a/www/settings.template.js b/www/settings.template.js index 8bd2539..2cd679e 100644 --- a/www/settings.template.js +++ b/www/settings.template.js @@ -23,5 +23,16 @@ var SETTINGS = { 4: {id: 4, name: "Wind", icon: "fas fa-wind", color: "lightblue", textcolor: "black", hue: 180}, 5: {id: 5, name: "Light", icon: "fas fa-sun", color: "yellow", textcolor: "black", hue: 60}, 6: {id: 6, name: "Dark", icon: "fas fa-moon", color: "deeppurple", textcolor: "white", hue: 265} + }, + download_links: { + android: { + ' F-Droid Repository': "https://repo.netsyms.com", + ' APK File': "https://repo.netsyms.com/fdroid/TerranQuest.apk", + ' Google Play': "https://play.google.com/store/apps/details?id=com.netsyms.terranquest.TerranQuest" + }, + nwjs: { + ' Ubuntu/Debian': "https://repo.netsyms.com", + ' Other Platforms': "https://build.netsyms.net/job/TerranQuest/" + } } }; \ No newline at end of file