2018-06-04 16:34:47 -07:00
|
|
|
// Requirements
|
2018-04-28 13:26:38 -07:00
|
|
|
const {app, BrowserWindow, ipcMain} = require('electron')
|
2018-10-25 09:51:51 -07:00
|
|
|
const autoUpdater = require('electron-updater').autoUpdater
|
2018-06-04 16:34:47 -07:00
|
|
|
const ejse = require('ejs-electron')
|
|
|
|
const fs = require('fs')
|
2018-09-22 23:19:16 -07:00
|
|
|
const isDev = require('./app/assets/js/isdev')
|
2018-06-04 16:34:47 -07:00
|
|
|
const path = require('path')
|
|
|
|
const semver = require('semver')
|
|
|
|
const url = require('url')
|
2017-05-16 23:26:46 -07:00
|
|
|
|
2018-04-28 15:45:19 -07:00
|
|
|
// Setup auto updater.
|
2018-06-04 17:06:34 -07:00
|
|
|
function initAutoUpdater(event, data) {
|
|
|
|
|
|
|
|
if(data){
|
2018-06-04 16:34:47 -07:00
|
|
|
autoUpdater.allowPrerelease = true
|
|
|
|
} else {
|
|
|
|
// Defaults to true if application version contains prerelease components (e.g. 0.12.1-alpha.1)
|
|
|
|
// autoUpdater.allowPrerelease = true
|
|
|
|
}
|
|
|
|
|
2018-04-28 13:26:38 -07:00
|
|
|
if(isDev){
|
|
|
|
autoUpdater.autoInstallOnAppQuit = false
|
|
|
|
autoUpdater.updateConfigPath = path.join(__dirname, 'dev-app-update.yml')
|
|
|
|
}
|
|
|
|
autoUpdater.on('update-available', (info) => {
|
|
|
|
event.sender.send('autoUpdateNotification', 'update-available', info)
|
|
|
|
})
|
|
|
|
autoUpdater.on('update-downloaded', (info) => {
|
|
|
|
event.sender.send('autoUpdateNotification', 'update-downloaded', info)
|
|
|
|
})
|
|
|
|
autoUpdater.on('update-not-available', (info) => {
|
|
|
|
event.sender.send('autoUpdateNotification', 'update-not-available', info)
|
|
|
|
})
|
|
|
|
autoUpdater.on('checking-for-update', () => {
|
|
|
|
event.sender.send('autoUpdateNotification', 'checking-for-update')
|
2018-11-01 14:37:05 -07:00
|
|
|
})
|
|
|
|
autoUpdater.on('error', () => {
|
|
|
|
event.sender.send('autoUpdateNotification', 'realerror', err)
|
|
|
|
})
|
2018-04-28 13:26:38 -07:00
|
|
|
}
|
|
|
|
|
2018-04-28 15:45:19 -07:00
|
|
|
// Open channel to listen for update actions.
|
2018-06-04 16:34:47 -07:00
|
|
|
ipcMain.on('autoUpdateAction', (event, arg, data) => {
|
2018-04-28 13:26:38 -07:00
|
|
|
switch(arg){
|
|
|
|
case 'initAutoUpdater':
|
|
|
|
console.log('Initializing auto updater.')
|
2018-06-04 17:06:34 -07:00
|
|
|
initAutoUpdater(event, data)
|
2018-04-28 13:26:38 -07:00
|
|
|
event.sender.send('autoUpdateNotification', 'ready')
|
|
|
|
break
|
|
|
|
case 'checkForUpdate':
|
|
|
|
autoUpdater.checkForUpdates()
|
|
|
|
.catch(err => {
|
2018-04-28 15:45:19 -07:00
|
|
|
event.sender.send('autoUpdateNotification', 'realerror', err)
|
2018-04-28 13:26:38 -07:00
|
|
|
})
|
|
|
|
break
|
2018-06-04 16:34:47 -07:00
|
|
|
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
|
2018-04-28 13:26:38 -07:00
|
|
|
case 'installUpdateNow':
|
|
|
|
autoUpdater.quitAndInstall()
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
console.log('Unknown argument', arg)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
})
|
2018-05-06 22:34:57 -07:00
|
|
|
// Redirect distribution index event from preloader to renderer.
|
2018-07-22 08:40:15 -07:00
|
|
|
ipcMain.on('distributionIndexDone', (event, res) => {
|
|
|
|
event.sender.send('distributionIndexDone', res)
|
2018-05-06 22:34:57 -07:00
|
|
|
})
|
2018-04-28 13:26:38 -07:00
|
|
|
|
2018-04-06 09:33:20 -07:00
|
|
|
// Disable hardware acceleration.
|
|
|
|
// https://electronjs.org/docs/tutorial/offscreen-rendering
|
|
|
|
app.disableHardwareAcceleration()
|
|
|
|
|
2017-05-16 23:26:46 -07:00
|
|
|
// Keep a global reference of the window object, if you don't, the window will
|
|
|
|
// be closed automatically when the JavaScript object is garbage collected.
|
|
|
|
let win
|
|
|
|
|
|
|
|
function createWindow() {
|
2018-04-06 09:33:20 -07:00
|
|
|
|
2017-12-01 23:59:25 -08:00
|
|
|
win = new BrowserWindow({
|
|
|
|
width: 980,
|
|
|
|
height: 552,
|
|
|
|
icon: getPlatformIcon('WesterosSealSquare'),
|
|
|
|
frame: false,
|
|
|
|
webPreferences: {
|
|
|
|
preload: path.join(__dirname, 'app', 'assets', 'js', 'preloader.js')
|
2018-04-29 15:05:59 -07:00
|
|
|
},
|
2018-05-08 03:34:16 -07:00
|
|
|
backgroundColor: '#171614'
|
2017-12-01 23:59:25 -08:00
|
|
|
})
|
2017-05-16 23:26:46 -07:00
|
|
|
|
2017-11-22 02:48:40 -08:00
|
|
|
ejse.data('bkid', Math.floor((Math.random() * fs.readdirSync(path.join(__dirname, 'app', 'assets', 'images', 'backgrounds')).length)))
|
2017-11-19 12:08:52 -08:00
|
|
|
|
2017-05-16 23:26:46 -07:00
|
|
|
win.loadURL(url.format({
|
2018-04-02 13:05:48 -07:00
|
|
|
pathname: path.join(__dirname, 'app', 'app.ejs'),
|
2017-05-16 23:26:46 -07:00
|
|
|
protocol: 'file:',
|
|
|
|
slashes: true
|
|
|
|
}))
|
|
|
|
|
2018-04-29 15:05:59 -07:00
|
|
|
/*win.once('ready-to-show', () => {
|
|
|
|
win.show()
|
|
|
|
})*/
|
|
|
|
|
2017-05-16 23:26:46 -07:00
|
|
|
win.setMenu(null)
|
|
|
|
|
2017-08-26 22:13:48 -07:00
|
|
|
win.setResizable(true)
|
|
|
|
|
2017-05-16 23:26:46 -07:00
|
|
|
win.on('closed', () => {
|
|
|
|
win = null
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPlatformIcon(filename){
|
|
|
|
const opSys = process.platform
|
|
|
|
if (opSys === 'darwin') {
|
|
|
|
filename = filename + '.icns'
|
|
|
|
} else if (opSys === 'win32') {
|
|
|
|
filename = filename + '.ico'
|
|
|
|
} else {
|
|
|
|
filename = filename + '.png'
|
|
|
|
}
|
|
|
|
|
|
|
|
return path.join(__dirname, 'app', 'assets', 'images', filename)
|
|
|
|
}
|
|
|
|
|
2018-07-22 10:31:15 -07:00
|
|
|
app.on('ready', createWindow)
|
2017-05-16 23:26:46 -07:00
|
|
|
|
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
// On macOS it is common for applications and their menu bar
|
|
|
|
// to stay active until the user quits explicitly with Cmd + Q
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
app.quit()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
app.on('activate', () => {
|
|
|
|
// On macOS it's common to re-create a window in the app when the
|
|
|
|
// dock icon is clicked and there are no other windows open.
|
|
|
|
if (win === null) {
|
|
|
|
createWindow()
|
|
|
|
}
|
|
|
|
})
|