From 71e4694ff6a3de9a4d1173eae615cb535e4466a5 Mon Sep 17 00:00:00 2001 From: CakeLancelot Date: Tue, 19 Sep 2023 08:51:19 -0500 Subject: [PATCH] Misc comment cleanup, correct holiday date range, simplify JSON loading --- assets/js/easter-eggs.js | 6 ++---- assets/js/server-selector.js | 28 +++++++++++++--------------- index.js | 7 +++---- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/assets/js/easter-eggs.js b/assets/js/easter-eggs.js index d7fc527..51c3141 100644 --- a/assets/js/easter-eggs.js +++ b/assets/js/easter-eggs.js @@ -1,10 +1,8 @@ // You're kind of ruining the surprise by reading this, but whatever var today = new Date(); -// Check Christmas season: Date constructor in Javascript uses an index -// so 11 is Dec. of this year, and 12 is Jan. of the next -var christmasBegin = new Date(today.getFullYear(), 11, 23); -var christmasEnd = new Date(today.getFullYear(), 12, 8); +var christmasBegin = new Date(today.getFullYear(), 11, 21); +var christmasEnd = new Date(today.getFullYear(), 11, 31); var sf; if (today >= christmasBegin && today <= christmasEnd) { diff --git a/assets/js/server-selector.js b/assets/js/server-selector.js index 2c87b80..4b1bb26 100644 --- a/assets/js/server-selector.js +++ b/assets/js/server-selector.js @@ -33,7 +33,7 @@ function disableServerListButtons() { function getAppVersion() { appVersion = remote.require("app").getVersion(); - // simplify version, ex. 1.4.0 -> 1.4, + // Simplify version, ex. 1.4.0 -> 1.4, // but only if a revision number isn't present if (appVersion.endsWith(".0")) { return appVersion.substr(0, appVersion.length - 2); @@ -48,7 +48,7 @@ function setAppVersionText() { } function addServer() { - var jsonToModify = JSON.parse(remotefs.readFileSync(serversPath)); + var jsonToModify = remotefs.readJsonSync(serversPath); var server = {}; server["uuid"] = uuidv4(); @@ -70,7 +70,7 @@ function addServer() { } function editServer() { - var jsonToModify = JSON.parse(remotefs.readFileSync(serversPath)); + var jsonToModify = remotefs.readJsonSync(serversPath); $.each(jsonToModify["servers"], function (key, value) { if (value["uuid"] == getSelectedServer()) { value["description"] = @@ -92,7 +92,7 @@ function editServer() { } function deleteServer() { - var jsonToModify = JSON.parse(remotefs.readFileSync(serversPath)); + var jsonToModify = remotefs.readJsonSync(serversPath); var result = jsonToModify["servers"].filter(function (obj) { return obj.uuid === getSelectedServer(); })[0]; @@ -114,7 +114,7 @@ function restoreDefaultServers() { } function loadGameVersions() { - var versionJson = JSON.parse(remotefs.readFileSync(versionsPath)); + var versionJson = remotefs.readJsonSync(versionsPath); versionArray = versionJson["versions"]; $.each(versionArray, function (key, value) { $(new Option(value.name, "val")).appendTo("#addserver-versionselect"); @@ -123,12 +123,12 @@ function loadGameVersions() { } function loadConfig() { - // load config object globally - config = JSON.parse(remotefs.readFileSync(configPath)); + // Load config object globally + config = remotefs.readJsonSync(configPath); } function loadServerList() { - var serverJson = JSON.parse(remotefs.readFileSync(serversPath)); + var serverJson = remotefs.readJsonSync(serversPath); serverArray = serverJson["servers"]; $(".server-listing-entry").remove(); // Clear out old stuff, if any @@ -168,16 +168,16 @@ function performCacheSwap(newVersion) { var record = path.join(userData, ".lastver"); var lastVersion = remotefs.readFileSync(record, (encoding = "utf8")); - // make note of what version we are launching for next launch + // Make note of what version we are launching for next launch remotefs.writeFileSync(record, newVersion); // If cache renaming would result in a no-op (ex. launching the same version - // two times), then skip it. this avoids permissions errors with multiple clients + // two times), then skip it. This avoids permissions errors with multiple clients // (file/folder is already open in another process) var skip = false; if (remotefs.existsSync(currentCache)) { - // cache already exists, find out what version it belongs to + // Cache already exists, find out what version it belongs to if (remotefs.existsSync(record)) { if (lastVersion != newVersion) { // Remove the directory we're trying to store the @@ -214,7 +214,7 @@ function setGameInfo(serverUUID) { return obj.name === result.version; })[0]; - // if cache swapping property exists AND is `true`, run cache swapping logic + // If cache swapping property exists AND is `true`, run cache swapping logic if (config["cache-swapping"]) { try { performCacheSwap(gameVersion.name); @@ -333,9 +333,7 @@ $("#server-table").on("dblclick", ".server-listing-entry", function (event) { }); $("#of-editservermodal").on("show.bs.modal", function (e) { - var jsonToModify = JSON.parse( - remotefs.readFileSync(path.join(userData, "servers.json")) - ); + var jsonToModify = remotefs.readJsonSync(path.join(userData, "servers.json")); $.each(jsonToModify["servers"], function (key, value) { if (value["uuid"] == getSelectedServer()) { $("#editserver-descinput")[0].value = value["description"]; diff --git a/index.js b/index.js index ea301ce..1654ed8 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,7 @@ var BrowserWindow = require("browser-window"); var mainWindow = null; var unityHomeDir = path.join(__dirname, "../../WebPlayer"); -// if running in non-packaged / development mode, this dir will be slightly different +// If running in non-packaged / development mode, this dir will be slightly different if (process.env.npm_node_execpath) { unityHomeDir = path.join(app.getAppPath(), "/build/WebPlayer"); } @@ -31,13 +31,13 @@ var versionsPath = path.join(userData, "versions.json"); function initialSetup(firstTime) { if (!firstTime) { - // migration from pre-1.4 + // Migration from pre-1.4 // Back everything up, just in case fs.copySync(configPath, configPath + ".bak"); fs.copySync(serversPath, serversPath + ".bak"); fs.copySync(versionsPath, versionsPath + ".bak"); } else { - // first-time setup + // First-time setup // Copy default servers fs.copySync( path.join(__dirname, "/defaults/servers.json"), @@ -141,7 +141,6 @@ function showMainWindow() { mainWindow.webContents.on("will-navigate", function (event, url) { event.preventDefault(); - // TODO: showMessageBox rather than showErrorBox? switch (url) { case "https://audience.fusionfall.com/ff/regWizard.do?_flowId=fusionfall-registration-flow": var errorMessage =