Skip to content

Commit

Permalink
v0.0.1-alpha.9 - Added option to enable/disable prereleases.
Browse files Browse the repository at this point in the history
Added option to enable/disable prerelease updates.
Implemented launcher tab on the settings UI, as this is the only current value.
Added semver dependency.
  • Loading branch information
dscalzi committed Jun 4, 2018
1 parent 790a3e0 commit 50d85d3
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 17 deletions.
6 changes: 2 additions & 4 deletions app/assets/css/launcher.css
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ body, button {
.settingsTabHeader {
display: flex;
flex-direction: column;
margin-bottom: 20px;
}
.settingsTabHeaderText {
font-size: 20px;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1283,7 +1281,7 @@ input:checked + .toggleSwitchSlider:before {
#settingsGameResolutionContainer {
display: flex;
flex-direction: column;
margin: 20px 0px;
margin-bottom: 20px;
}
#settingsGameResolutionContent {
display: flex;
Expand Down
25 changes: 24 additions & 1 deletion app/assets/js/configmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions app/assets/js/scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion app/assets/js/scripts/uicore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions app/settings.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@
<span class="settingsTabHeaderText">Launcher Settings</span>
<span class="settingsTabHeaderDesc">Options related to the launcher itself.</span>
</div>
<div class="settingsFieldContainer">
<div class="settingsFieldLeft">
<span class="settingsFieldTitle">Allow prerelease updates.</span>
<span class="settingsFieldDesc">Prereleases contain the latest features and updates, however they may be buggy.<br>This will always be true if you are using a prerelease version.</span>
</div>
<div class="settingsFieldRight">
<label class="toggleSwitch">
<input type="checkbox" cValue="AllowPrerelease">
<span class="toggleSwitchSlider"></span>
</label>
</div>
</div>
</div>
</div>
<script src="./assets/js/scripts/settings.js"></script>
Expand Down
39 changes: 30 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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.')
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 50d85d3

Please sign in to comment.