2017-11-30 06:40:56 +00:00
|
|
|
/**
|
|
|
|
* Core UI functions are initialized in this file. This prevents
|
2017-12-03 03:41:47 +00: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-30 06:40:56 +00:00
|
|
|
*/
|
2018-04-25 21:40:46 +00:00
|
|
|
// Requirements
|
|
|
|
const $ = require('jquery');
|
2018-04-28 20:26:38 +00:00
|
|
|
const {ipcRenderer, remote, shell, webFrame} = require('electron')
|
|
|
|
const isDev = require('electron-is-dev')
|
2018-04-12 22:13:09 +00:00
|
|
|
|
2018-04-25 21:51:10 +00: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-26 06:01:46 +00: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 22:13:09 +00:00
|
|
|
// Disable zoom, needed for darwin.
|
2018-04-12 22:39:31 +00:00
|
|
|
webFrame.setZoomLevel(0)
|
2018-04-12 22:13:09 +00:00
|
|
|
webFrame.setVisualZoomLevelLimits(1, 1)
|
|
|
|
webFrame.setLayoutZoomLevelLimits(0, 0)
|
2017-11-30 06:40:56 +00:00
|
|
|
|
2018-04-28 20:26:38 +00:00
|
|
|
// Initialize auto updates in production environments.
|
|
|
|
// TODO Make this the case after implementation is done.
|
|
|
|
if(!isDev){
|
|
|
|
ipcRenderer.on('autoUpdateNotification', (event, arg, info) => {
|
|
|
|
switch(arg){
|
|
|
|
case 'checking-for-update':
|
|
|
|
console.log('Checking for update..')
|
|
|
|
break
|
|
|
|
case 'update-available':
|
|
|
|
console.log('New update available', info.version)
|
|
|
|
break
|
|
|
|
case 'update-downloaded':
|
|
|
|
console.log('Update ' + info.version + ' ready to be installed.')
|
|
|
|
showUpdateUI(info)
|
|
|
|
break
|
|
|
|
case 'update-not-available':
|
|
|
|
console.log('No new update found.')
|
|
|
|
break
|
|
|
|
case 'ready':
|
|
|
|
ipcRenderer.send('autoUpdateAction', 'checkForUpdate')
|
|
|
|
case 'error':
|
|
|
|
console.log('Error during update check..')
|
|
|
|
console.debug('Error Code:', info != null ? info.code : null)
|
2018-04-28 22:07:39 +00:00
|
|
|
if(err != null && err.code != null){
|
|
|
|
if(err.code === 'ERR_UPDATER_INVALID_RELEASE_FEED'){
|
|
|
|
console.log('No suitable releases found.')
|
|
|
|
}
|
2018-04-28 20:26:38 +00:00
|
|
|
}
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
console.log('Unknown argument', arg)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
})
|
|
|
|
ipcRenderer.send('autoUpdateAction', 'initAutoUpdater')
|
|
|
|
}
|
|
|
|
|
|
|
|
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 = () => {
|
|
|
|
setOverlayContent('Update Available', 'A new update for the launcher is available. Would you like to install now?', 'Install', 'Later')
|
|
|
|
setOverlayHandler(() => {
|
|
|
|
if(!isDev){
|
|
|
|
ipcRenderer.send('autoUpdateAction', 'installUpdateNow')
|
|
|
|
} else {
|
|
|
|
console.error('Cannot install updates in development environment.')
|
|
|
|
toggleOverlay(false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
setDismissHandler(() => {
|
|
|
|
toggleOverlay(false)
|
|
|
|
})
|
|
|
|
toggleOverlay(true, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-30 06:40:56 +00:00
|
|
|
/* jQuery Example
|
|
|
|
$(function(){
|
|
|
|
console.log('UICore Initialized');
|
|
|
|
})*/
|
|
|
|
|
2017-11-30 08:00:06 +00:00
|
|
|
document.addEventListener('readystatechange', function () {
|
|
|
|
if (document.readyState === 'interactive'){
|
2017-11-30 06:40:56 +00:00
|
|
|
console.log('UICore Initializing..');
|
|
|
|
|
|
|
|
// Bind close button.
|
2018-04-14 20:54:10 +00:00
|
|
|
Array.from(document.getElementsByClassName('fCb')).map((val) => {
|
|
|
|
val.addEventListener('click', e => {
|
|
|
|
const window = remote.getCurrentWindow()
|
|
|
|
window.close()
|
|
|
|
})
|
2017-11-30 06:40:56 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Bind restore down button.
|
2018-04-14 20:54:10 +00: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-30 06:40:56 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Bind minimize button.
|
2018-04-14 20:54:10 +00:00
|
|
|
Array.from(document.getElementsByClassName('fMb')).map((val) => {
|
|
|
|
val.addEventListener('click', e => {
|
|
|
|
const window = remote.getCurrentWindow()
|
|
|
|
window.minimize()
|
|
|
|
document.activeElement.blur()
|
|
|
|
})
|
2017-11-30 06:40:56 +00:00
|
|
|
})
|
|
|
|
|
2017-11-30 08:00:06 +00:00
|
|
|
} else if(document.readyState === 'complete'){
|
|
|
|
|
2018-04-02 22:40:32 +00:00
|
|
|
//266.01
|
|
|
|
//170.8
|
|
|
|
//53.21
|
2017-11-30 06:40:56 +00:00
|
|
|
// Bind progress bar length to length of bot wrapper
|
2018-04-02 22:40:32 +00: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
|
|
|
|
|
|
|
|
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 08:00:06 +00:00
|
|
|
|
2017-11-30 06:40:56 +00:00
|
|
|
}
|
2017-11-30 08:00:06 +00:00
|
|
|
|
|
|
|
}, false)
|
2017-11-30 06:40:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Open web links in the user's default browser.
|
|
|
|
*/
|
|
|
|
$(document).on('click', 'a[href^="http"]', function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
//console.log(os.homedir())
|
|
|
|
shell.openExternal(this.href)
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
2018-01-19 04:37:59 +00:00
|
|
|
* Opens DevTools window if you hold (ctrl + shift + i).
|
2017-11-30 06:40:56 +00: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-04-27 04:04:09 +00:00
|
|
|
if(e.key === 'I' && e.ctrlKey && e.shiftKey){
|
2018-01-19 04:37:59 +00:00
|
|
|
let window = remote.getCurrentWindow()
|
2017-11-30 06:40:56 +00:00
|
|
|
window.toggleDevTools()
|
|
|
|
}
|
|
|
|
})
|