2017-11-29 22:40:56 -08:00
|
|
|
/**
|
|
|
|
* Core UI functions are initialized in this file. This prevents
|
2017-12-02 19:41:47 -08:00
|
|
|
* unexpected errors from breaking the core features. Specifically,
|
|
|
|
* actions in this file should not require the usage of any internal
|
|
|
|
* modules, excluding dependencies.
|
2017-11-29 22:40:56 -08:00
|
|
|
*/
|
2018-04-25 14:40:46 -07:00
|
|
|
// Requirements
|
2018-07-22 10:31:15 -07:00
|
|
|
const $ = require('jquery')
|
2018-04-28 13:26:38 -07:00
|
|
|
const {ipcRenderer, remote, shell, webFrame} = require('electron')
|
2018-09-22 23:19:16 -07:00
|
|
|
const isDev = require('./assets/js/isdev')
|
2018-08-22 11:21:49 -07:00
|
|
|
const LoggerUtil = require('./assets/js/loggerutil')
|
|
|
|
|
|
|
|
const loggerUICore = LoggerUtil('%c[UICore]', 'color: #000668; font-weight: bold')
|
|
|
|
const loggerAutoUpdater = LoggerUtil('%c[AutoUpdater]', 'color: #000668; font-weight: bold')
|
|
|
|
const loggerAutoUpdaterSuccess = LoggerUtil('%c[AutoUpdater]', 'color: #209b07; font-weight: bold')
|
2018-04-12 15:13:09 -07:00
|
|
|
|
2018-09-22 02:07:18 -07:00
|
|
|
// Log deprecation and process warnings.
|
|
|
|
process.traceProcessWarnings = true
|
|
|
|
process.traceDeprecation = true
|
|
|
|
|
2018-04-25 14:51:10 -07:00
|
|
|
// Disable eval function.
|
|
|
|
// eslint-disable-next-line
|
|
|
|
window.eval = global.eval = function () {
|
|
|
|
throw new Error('Sorry, this app does not support window.eval().')
|
|
|
|
}
|
|
|
|
|
2018-04-25 23:01:46 -07:00
|
|
|
// Display warning when devtools window is opened.
|
|
|
|
remote.getCurrentWebContents().on('devtools-opened', () => {
|
|
|
|
console.log('%cThe console is dark and full of terrors.', 'color: white; -webkit-text-stroke: 4px #a02d2a; font-size: 60px; font-weight: bold')
|
|
|
|
console.log('%cIf you\'ve been told to paste something here, you\'re being scammed.', 'font-size: 16px')
|
|
|
|
console.log('%cUnless you know exactly what you\'re doing, close this window.', 'font-size: 16px')
|
|
|
|
})
|
|
|
|
|
2018-04-12 15:13:09 -07:00
|
|
|
// Disable zoom, needed for darwin.
|
2018-04-12 15:39:31 -07:00
|
|
|
webFrame.setZoomLevel(0)
|
2018-04-12 15:13:09 -07:00
|
|
|
webFrame.setVisualZoomLevelLimits(1, 1)
|
2017-11-29 22:40:56 -08:00
|
|
|
|
2018-04-28 13:26:38 -07:00
|
|
|
// Initialize auto updates in production environments.
|
2018-04-28 15:45:19 -07:00
|
|
|
let updateCheckListener
|
2018-04-28 13:26:38 -07:00
|
|
|
if(!isDev){
|
|
|
|
ipcRenderer.on('autoUpdateNotification', (event, arg, info) => {
|
|
|
|
switch(arg){
|
|
|
|
case 'checking-for-update':
|
2018-08-22 11:21:49 -07:00
|
|
|
loggerAutoUpdater.log('Checking for update..')
|
2018-08-13 03:13:13 -07:00
|
|
|
settingsUpdateButtonStatus('Checking for Updates..', true)
|
2018-04-28 13:26:38 -07:00
|
|
|
break
|
|
|
|
case 'update-available':
|
2018-08-22 11:21:49 -07:00
|
|
|
loggerAutoUpdaterSuccess.log('New update available', info.version)
|
2018-11-18 18:51:48 -08:00
|
|
|
|
|
|
|
if(process.platform === 'darwin'){
|
2019-09-05 13:08:47 -07:00
|
|
|
info.darwindownload = `https://github.com/dscalzi/HeliosLauncher/releases/download/v${info.version}/helioslauncher-${info.version}.dmg`
|
2018-11-18 18:51:48 -08:00
|
|
|
showUpdateUI(info)
|
|
|
|
}
|
|
|
|
|
2018-08-13 03:13:13 -07:00
|
|
|
populateSettingsUpdateInformation(info)
|
2018-04-28 13:26:38 -07:00
|
|
|
break
|
|
|
|
case 'update-downloaded':
|
2018-08-22 11:21:49 -07:00
|
|
|
loggerAutoUpdaterSuccess.log('Update ' + info.version + ' ready to be installed.')
|
2018-08-13 03:13:13 -07:00
|
|
|
settingsUpdateButtonStatus('Install Now', false, () => {
|
|
|
|
if(!isDev){
|
|
|
|
ipcRenderer.send('autoUpdateAction', 'installUpdateNow')
|
|
|
|
}
|
|
|
|
})
|
2018-04-28 13:26:38 -07:00
|
|
|
showUpdateUI(info)
|
|
|
|
break
|
|
|
|
case 'update-not-available':
|
2018-08-22 11:21:49 -07:00
|
|
|
loggerAutoUpdater.log('No new update found.')
|
2018-08-13 03:13:13 -07:00
|
|
|
settingsUpdateButtonStatus('Check for Updates')
|
2018-04-28 13:26:38 -07:00
|
|
|
break
|
|
|
|
case 'ready':
|
2018-04-28 15:45:19 -07:00
|
|
|
updateCheckListener = setInterval(() => {
|
|
|
|
ipcRenderer.send('autoUpdateAction', 'checkForUpdate')
|
|
|
|
}, 1800000)
|
2018-04-28 13:26:38 -07:00
|
|
|
ipcRenderer.send('autoUpdateAction', 'checkForUpdate')
|
2018-07-22 10:31:15 -07:00
|
|
|
break
|
2018-04-28 15:45:19 -07:00
|
|
|
case 'realerror':
|
|
|
|
if(info != null && info.code != null){
|
|
|
|
if(info.code === 'ERR_UPDATER_INVALID_RELEASE_FEED'){
|
2018-08-22 11:21:49 -07:00
|
|
|
loggerAutoUpdater.log('No suitable releases found.')
|
2018-04-28 15:45:19 -07:00
|
|
|
} else if(info.code === 'ERR_XML_MISSED_ELEMENT'){
|
2018-08-22 11:21:49 -07:00
|
|
|
loggerAutoUpdater.log('No releases found.')
|
2018-04-28 15:45:19 -07:00
|
|
|
} else {
|
2018-08-22 11:21:49 -07:00
|
|
|
loggerAutoUpdater.error('Error during update check..', info)
|
|
|
|
loggerAutoUpdater.debug('Error Code:', info.code)
|
2018-04-28 15:07:39 -07:00
|
|
|
}
|
2018-04-28 13:26:38 -07:00
|
|
|
}
|
|
|
|
break
|
|
|
|
default:
|
2018-08-22 11:21:49 -07:00
|
|
|
loggerAutoUpdater.log('Unknown argument', arg)
|
2018-04-28 13:26:38 -07:00
|
|
|
break
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-06-04 16:34:47 -07:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
}
|
|
|
|
|
2018-04-28 13:26:38 -07:00
|
|
|
function showUpdateUI(info){
|
|
|
|
//TODO Make this message a bit more informative `${info.version}`
|
|
|
|
document.getElementById('image_seal_container').setAttribute('update', true)
|
|
|
|
document.getElementById('image_seal_container').onclick = () => {
|
2018-08-13 03:13:13 -07:00
|
|
|
/*setOverlayContent('Update Available', 'A new update for the launcher is available. Would you like to install now?', 'Install', 'Later')
|
2018-04-28 13:26:38 -07:00
|
|
|
setOverlayHandler(() => {
|
|
|
|
if(!isDev){
|
|
|
|
ipcRenderer.send('autoUpdateAction', 'installUpdateNow')
|
|
|
|
} else {
|
|
|
|
console.error('Cannot install updates in development environment.')
|
|
|
|
toggleOverlay(false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
setDismissHandler(() => {
|
|
|
|
toggleOverlay(false)
|
|
|
|
})
|
2018-08-13 03:13:13 -07:00
|
|
|
toggleOverlay(true, true)*/
|
|
|
|
switchView(getCurrentView(), VIEWS.settings, 500, 500, () => {
|
|
|
|
settingsNavItemListener(document.getElementById('settingsNavUpdate'), false)
|
|
|
|
})
|
2018-04-28 13:26:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-29 22:40:56 -08:00
|
|
|
/* jQuery Example
|
|
|
|
$(function(){
|
2018-08-22 11:21:49 -07:00
|
|
|
loggerUICore.log('UICore Initialized');
|
2017-11-29 22:40:56 -08:00
|
|
|
})*/
|
|
|
|
|
2017-11-30 00:00:06 -08:00
|
|
|
document.addEventListener('readystatechange', function () {
|
|
|
|
if (document.readyState === 'interactive'){
|
2018-08-22 11:21:49 -07:00
|
|
|
loggerUICore.log('UICore Initializing..')
|
2017-11-29 22:40:56 -08:00
|
|
|
|
|
|
|
// Bind close button.
|
2018-04-14 13:54:10 -07:00
|
|
|
Array.from(document.getElementsByClassName('fCb')).map((val) => {
|
|
|
|
val.addEventListener('click', e => {
|
|
|
|
const window = remote.getCurrentWindow()
|
|
|
|
window.close()
|
|
|
|
})
|
2017-11-29 22:40:56 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
// Bind restore down button.
|
2018-04-14 13:54:10 -07:00
|
|
|
Array.from(document.getElementsByClassName('fRb')).map((val) => {
|
|
|
|
val.addEventListener('click', e => {
|
|
|
|
const window = remote.getCurrentWindow()
|
|
|
|
if(window.isMaximized()){
|
|
|
|
window.unmaximize()
|
|
|
|
} else {
|
|
|
|
window.maximize()
|
|
|
|
}
|
|
|
|
document.activeElement.blur()
|
|
|
|
})
|
2017-11-29 22:40:56 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
// Bind minimize button.
|
2018-04-14 13:54:10 -07:00
|
|
|
Array.from(document.getElementsByClassName('fMb')).map((val) => {
|
|
|
|
val.addEventListener('click', e => {
|
|
|
|
const window = remote.getCurrentWindow()
|
|
|
|
window.minimize()
|
|
|
|
document.activeElement.blur()
|
|
|
|
})
|
2017-11-29 22:40:56 -08:00
|
|
|
})
|
|
|
|
|
2018-05-10 01:36:52 -07:00
|
|
|
// Remove focus from social media buttons once they're clicked.
|
|
|
|
Array.from(document.getElementsByClassName('mediaURL')).map(val => {
|
|
|
|
val.addEventListener('click', e => {
|
|
|
|
document.activeElement.blur()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-11-30 00:00:06 -08:00
|
|
|
} else if(document.readyState === 'complete'){
|
|
|
|
|
2018-04-02 15:40:32 -07:00
|
|
|
//266.01
|
|
|
|
//170.8
|
|
|
|
//53.21
|
2017-11-29 22:40:56 -08:00
|
|
|
// Bind progress bar length to length of bot wrapper
|
2018-04-02 15:40:32 -07:00
|
|
|
//const targetWidth = document.getElementById("launch_content").getBoundingClientRect().width
|
|
|
|
//const targetWidth2 = document.getElementById("server_selection").getBoundingClientRect().width
|
|
|
|
//const targetWidth3 = document.getElementById("launch_button").getBoundingClientRect().width
|
|
|
|
|
2018-07-22 10:31:15 -07:00
|
|
|
document.getElementById('launch_details').style.maxWidth = 266.01
|
|
|
|
document.getElementById('launch_progress').style.width = 170.8
|
|
|
|
document.getElementById('launch_details_right').style.maxWidth = 170.8
|
|
|
|
document.getElementById('launch_progress_label').style.width = 53.21
|
2017-11-30 00:00:06 -08:00
|
|
|
|
2017-11-29 22:40:56 -08:00
|
|
|
}
|
2017-11-30 00:00:06 -08:00
|
|
|
|
|
|
|
}, false)
|
2017-11-29 22:40:56 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Open web links in the user's default browser.
|
|
|
|
*/
|
|
|
|
$(document).on('click', 'a[href^="http"]', function(event) {
|
2018-07-22 10:31:15 -07:00
|
|
|
event.preventDefault()
|
2017-11-29 22:40:56 -08:00
|
|
|
shell.openExternal(this.href)
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
2018-01-18 20:37:59 -08:00
|
|
|
* Opens DevTools window if you hold (ctrl + shift + i).
|
2017-11-29 22:40:56 -08:00
|
|
|
* This will crash the program if you are using multiple
|
|
|
|
* DevTools, for example the chrome debugger in VS Code.
|
|
|
|
*/
|
|
|
|
document.addEventListener('keydown', function (e) {
|
2018-05-06 18:45:20 -07:00
|
|
|
if((e.key === 'I' || e.key === 'i') && e.ctrlKey && e.shiftKey){
|
2018-01-18 20:37:59 -08:00
|
|
|
let window = remote.getCurrentWindow()
|
2017-11-29 22:40:56 -08:00
|
|
|
window.toggleDevTools()
|
|
|
|
}
|
|
|
|
})
|