From 50d85d30cc2d7a5c9a91c6fbc77fba2086b3ceea Mon Sep 17 00:00:00 2001 From: Daniel Scalzi Date: Mon, 4 Jun 2018 19:34:47 -0400 Subject: [PATCH] v0.0.1-alpha.9 - Added option to enable/disable prereleases. Added option to enable/disable prerelease updates. Implemented launcher tab on the settings UI, as this is the only current value. Added semver dependency. --- app/assets/css/launcher.css | 6 ++--- app/assets/js/configmanager.js | 25 +++++++++++++++++++- app/assets/js/scripts/settings.js | 5 ++++ app/assets/js/scripts/uicore.js | 13 ++++++++++- app/settings.ejs | 12 ++++++++++ index.js | 39 ++++++++++++++++++++++++------- package-lock.json | 2 +- package.json | 3 ++- 8 files changed, 88 insertions(+), 17 deletions(-) diff --git a/app/assets/css/launcher.css b/app/assets/css/launcher.css index bef1a99c..7cf91cce 100644 --- a/app/assets/css/launcher.css +++ b/app/assets/css/launcher.css @@ -1017,6 +1017,7 @@ body, button { .settingsTabHeader { display: flex; flex-direction: column; + margin-bottom: 20px; } .settingsTabHeaderText { font-size: 20px; @@ -1126,9 +1127,6 @@ input:checked + .toggleSwitchSlider:before { * * */ /* Add account button styles. */ -#settingsAddAccountContainer { - margin-top: 20px; -} #settingsAddAccount { background: rgba(0, 0, 0, 0.25); border: 1px solid rgba(126, 126, 126, 0.57); @@ -1283,7 +1281,7 @@ input:checked + .toggleSwitchSlider:before { #settingsGameResolutionContainer { display: flex; flex-direction: column; - margin: 20px 0px; + margin-bottom: 20px; } #settingsGameResolutionContent { display: flex; diff --git a/app/assets/js/configmanager.js b/app/assets/js/configmanager.js index 83437827..dc27734f 100644 --- a/app/assets/js/configmanager.js +++ b/app/assets/js/configmanager.js @@ -40,7 +40,9 @@ const DEFAULT_CONFIG = { autoConnect: true, launchDetached: true }, - launcher: {} + launcher: { + allowPrerelease: false + } }, commonDirectory: path.join(dataPath, 'common'), instanceDirectory: path.join(dataPath, 'instances'), @@ -507,4 +509,25 @@ exports.getLaunchDetached = function(def = false){ */ exports.setLaunchDetached = function(launchDetached){ config.settings.game.launchDetached = launchDetached +} + +// Launcher Settings + +/** + * Check if the launcher should download prerelease versions. + * + * @param {boolean} def Optional. If true, the default value will be returned. + * @returns {boolean} Whether or not the launcher should download prerelease versions. + */ +exports.getAllowPrerelease = function(def = false){ + return !def ? config.settings.launcher.allowPrerelease : DEFAULT_CONFIG.settings.launcher.allowPrerelease +} + +/** + * Change the status of Whether or not the launcher should download prerelease versions. + * + * @param {boolean} launchDetached Whether or not the launcher should download prerelease versions. + */ +exports.setAllowPrerelease = function(allowPrerelease){ + config.settings.launcher.allowPrerelease = allowPrerelease } \ No newline at end of file diff --git a/app/assets/js/scripts/settings.js b/app/assets/js/scripts/settings.js index ebd7f5f4..d40e59d8 100644 --- a/app/assets/js/scripts/settings.js +++ b/app/assets/js/scripts/settings.js @@ -86,6 +86,11 @@ function saveSettingsValues(){ sFn(v.value) } else if(v.type === 'checkbox'){ sFn(v.checked) + // Special Conditions + const cVal = v.getAttribute('cValue') + if(cVal === 'AllowPrerelease'){ + changeAllowPrerelease(v.checked) + } } } } diff --git a/app/assets/js/scripts/uicore.js b/app/assets/js/scripts/uicore.js index def368c6..a3d89965 100644 --- a/app/assets/js/scripts/uicore.js +++ b/app/assets/js/scripts/uicore.js @@ -28,7 +28,6 @@ webFrame.setVisualZoomLevelLimits(1, 1) webFrame.setLayoutZoomLevelLimits(0, 0) // Initialize auto updates in production environments. -// TODO Make this the case after implementation is done. let updateCheckListener if(!isDev){ ipcRenderer.on('autoUpdateNotification', (event, arg, info) => { @@ -71,6 +70,18 @@ if(!isDev){ ipcRenderer.send('autoUpdateAction', 'initAutoUpdater') } +/** + * Send a notification to the main process changing the value of + * allowPrerelease. If we are running a prerelease version, then + * this will always be set to true, regardless of the current value + * of val. + * + * @param {boolean} val The new allow prerelease value. + */ +function changeAllowPrerelease(val){ + ipcRenderer.send('autoUpdateAction', 'allowPrereleaseChange', val) +} + function showUpdateUI(info){ //TODO Make this message a bit more informative `${info.version}` document.getElementById('image_seal_container').setAttribute('update', true) diff --git a/app/settings.ejs b/app/settings.ejs index 5471e657..a9136b5a 100644 --- a/app/settings.ejs +++ b/app/settings.ejs @@ -98,6 +98,18 @@ Launcher Settings Options related to the launcher itself. +
+
+ Allow prerelease updates. + Prereleases contain the latest features and updates, however they may be buggy.
This will always be true if you are using a prerelease version.
+
+
+ +
+
diff --git a/index.js b/index.js index 9f1692be..e9e931b2 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,24 @@ +// Requirements const {app, BrowserWindow, ipcMain} = require('electron') -const autoUpdater = require('electron-updater').autoUpdater -const isDev = require('electron-is-dev') -const path = require('path') -const url = require('url') -const fs = require('fs') -const ejse = require('ejs-electron') +const autoUpdater = require('electron-updater').autoUpdater +const ConfigManager = require('./app/assets/js/configmanager.js') +const ejse = require('ejs-electron') +const fs = require('fs') +const isDev = require('electron-is-dev') +const path = require('path') +const semver = require('semver') +const url = require('url') // Setup auto updater. function initAutoUpdater(event) { - // Defaults to true if application version contains prerelease components (e.g. 0.12.1-alpha.1) - // autoUpdater.allowPrerelease = true + + if(ConfigManager.getAllowPrerelease()){ + autoUpdater.allowPrerelease = true + } else { + // Defaults to true if application version contains prerelease components (e.g. 0.12.1-alpha.1) + // autoUpdater.allowPrerelease = true + } + if(isDev){ autoUpdater.autoInstallOnAppQuit = false autoUpdater.updateConfigPath = path.join(__dirname, 'dev-app-update.yml') @@ -29,7 +38,7 @@ function initAutoUpdater(event) { } // Open channel to listen for update actions. -ipcMain.on('autoUpdateAction', (event, arg) => { +ipcMain.on('autoUpdateAction', (event, arg, data) => { switch(arg){ case 'initAutoUpdater': console.log('Initializing auto updater.') @@ -42,6 +51,18 @@ ipcMain.on('autoUpdateAction', (event, arg) => { event.sender.send('autoUpdateNotification', 'realerror', err) }) break + case 'allowPrereleaseChange': + if(!data){ + const preRelComp = semver.prerelease(app.getVersion()) + if(preRelComp != null && preRelComp.length > 0){ + autoUpdater.allowPrerelease = true + } else { + autoUpdater.allowPrerelease = data + } + } else { + autoUpdater.allowPrerelease = data + } + break case 'installUpdateNow': autoUpdater.quitAndInstall() break diff --git a/package-lock.json b/package-lock.json index c4d8c4c7..80724579 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "westeroscraftlauncher", - "version": "0.0.1-alpha.8", + "version": "0.0.1-alpha.9", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9678e299..8bdb4770 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "westeroscraftlauncher", - "version": "0.0.1-alpha.8", + "version": "0.0.1-alpha.9", "description": "Custom modded launcher for Westeroscraft", "productName": "WesterosCraft Launcher", "main": "index.js", @@ -39,6 +39,7 @@ "mkdirp": "^0.5.1", "request": "^2.87.0", "rimraf": "^2.6.2", + "semver": "^5.5.0", "tar-fs": "^1.16.2", "uuid": "^3.2.1", "winreg": "^1.2.4"