2022-12-07 10:41:28 +01:00
|
|
|
const { app, BrowserWindow, ipcMain, Menu, Notification, Tray, nativeImage, dialog, webContents } = require('electron')
|
|
|
|
const { autoUpdater } = require('electron-updater')
|
|
|
|
const server = require('./server.js')
|
|
|
|
const log = require('electron-log')
|
|
|
|
const path = require('path')
|
|
|
|
const i18n = require("./lib/i18n.js")
|
2021-12-25 14:39:47 +01:00
|
|
|
|
2022-10-18 18:54:27 +02:00
|
|
|
app.commandLine.appendSwitch('js-flags', '--max-old-space-size=512')
|
2021-12-25 14:39:47 +01:00
|
|
|
|
2022-12-07 10:41:28 +01:00
|
|
|
process.env['APP_PATH'] = app.getAppPath()
|
2021-12-25 14:39:47 +01:00
|
|
|
|
2022-12-07 10:41:28 +01:00
|
|
|
autoUpdater.autoDownload = false
|
|
|
|
autoUpdater.autoInstallOnAppQuit = false
|
|
|
|
autoUpdater.logger = log
|
|
|
|
autoUpdater.logger.transports.file.level = 'info'
|
|
|
|
log.info('App starting...')
|
2021-12-25 14:39:47 +01:00
|
|
|
|
|
|
|
const editMenu = Menu.buildFromTemplate([
|
|
|
|
{
|
|
|
|
label: "Qortal",
|
|
|
|
submenu: [{
|
|
|
|
label: "Quit",
|
|
|
|
click() {
|
2022-12-07 10:41:28 +01:00
|
|
|
app.quit()
|
2021-12-25 14:39:47 +01:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Edit",
|
|
|
|
submenu: [
|
|
|
|
{label: "Undo", accelerator: "CommandOrControl+Z", selector: "undo:"},
|
|
|
|
{label: "Redo", accelerator: "CommandOrControl+Shift+Z", selector: "redo:"},
|
|
|
|
{type: "separator"},
|
|
|
|
{label: "Cut", accelerator: "CommandOrControl+X", selector: "cut:"},
|
|
|
|
{label: "Copy", accelerator: "CommandOrControl+C", selector: "copy:"},
|
|
|
|
{label: "Paste", accelerator: "CommandOrControl+V", selector: "paste:"},
|
|
|
|
{label: "Select All", accelerator: "CommandOrControl+A", selector: "selectAll:"}
|
|
|
|
]
|
|
|
|
}
|
2022-12-07 10:41:28 +01:00
|
|
|
])
|
2021-12-25 14:39:47 +01:00
|
|
|
|
2022-12-07 10:41:28 +01:00
|
|
|
Menu.setApplicationMenu(editMenu)
|
2021-12-25 14:39:47 +01:00
|
|
|
|
|
|
|
let myWindow = null;
|
|
|
|
|
2022-12-07 10:41:28 +01:00
|
|
|
const APP_ICON = path.join(__dirname, 'img', 'icons')
|
2021-12-25 14:39:47 +01:00
|
|
|
|
|
|
|
const iconPath = () => {
|
2022-12-07 10:41:28 +01:00
|
|
|
return APP_ICON + (process.platform === 'win32' ? '/ico/256x256.ico' : '/png/256x256.png')
|
|
|
|
}
|
2021-12-25 14:39:47 +01:00
|
|
|
|
|
|
|
function createWindow() {
|
|
|
|
myWindow = new BrowserWindow({
|
|
|
|
backgroundColor: '#eee',
|
|
|
|
width: 1280,
|
|
|
|
height: 720,
|
|
|
|
minWidth: 700,
|
|
|
|
minHeight: 640,
|
|
|
|
icon: iconPath(),
|
2022-10-03 11:18:39 +02:00
|
|
|
title: "Qortal UI",
|
2021-12-25 14:39:47 +01:00
|
|
|
autoHideMenuBar: true,
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: false,
|
|
|
|
partition: 'persist:webviewsession',
|
|
|
|
enableRemoteModule: false,
|
2022-10-03 11:18:39 +02:00
|
|
|
nativeWindowOpen: false,
|
2021-12-25 14:39:47 +01:00
|
|
|
sandbox: true
|
|
|
|
},
|
|
|
|
show: false
|
|
|
|
})
|
2022-10-03 11:18:39 +02:00
|
|
|
myWindow.maximize()
|
|
|
|
myWindow.show()
|
2021-12-25 14:39:47 +01:00
|
|
|
myWindow.loadURL('http://localhost:12388/app/wallet')
|
|
|
|
myWindow.on('closed', function () {
|
|
|
|
myWindow = null
|
|
|
|
})
|
2022-10-03 11:18:39 +02:00
|
|
|
myWindow.on('minimize',function(event) {
|
|
|
|
event.preventDefault()
|
|
|
|
myWindow.hide()
|
|
|
|
})
|
2021-12-25 14:39:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const createTray = () => {
|
2022-10-03 11:18:39 +02:00
|
|
|
let myTray = new Tray(__dirname + '/img/icons/png/tray/tray.png')
|
|
|
|
const contextMenu = Menu.buildFromTemplate([
|
|
|
|
{
|
|
|
|
label: `Qortal UI v${app.getVersion()}`,
|
|
|
|
enabled: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'separator',
|
|
|
|
},
|
|
|
|
{
|
2022-12-07 10:41:28 +01:00
|
|
|
label: i18n.__("electron_translate_1"),
|
2022-10-03 11:18:39 +02:00
|
|
|
click: function () {
|
|
|
|
myWindow.maximize()
|
|
|
|
myWindow.show()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-12-07 10:41:28 +01:00
|
|
|
label: i18n.__("electron_translate_2"),
|
2022-10-03 11:18:39 +02:00
|
|
|
click() {
|
|
|
|
myTray.destroy()
|
|
|
|
app.quit()
|
|
|
|
},
|
2021-12-25 14:39:47 +01:00
|
|
|
},
|
2022-10-03 11:18:39 +02:00
|
|
|
])
|
2021-12-25 14:39:47 +01:00
|
|
|
myTray.setTitle("QORTAL UI")
|
2022-10-03 11:18:39 +02:00
|
|
|
myTray.setToolTip(`Qortal UI v${app.getVersion()}`)
|
2021-12-25 14:39:47 +01:00
|
|
|
myTray.setContextMenu(contextMenu)
|
2022-10-03 11:18:39 +02:00
|
|
|
myTray.on("double-click", () => myWindow.maximize() , myWindow.show())
|
2021-12-25 14:39:47 +01:00
|
|
|
}
|
|
|
|
|
2022-12-07 10:41:28 +01:00
|
|
|
const isLock = app.requestSingleInstanceLock()
|
2021-12-25 14:39:47 +01:00
|
|
|
|
|
|
|
if (!isLock) {
|
2022-02-04 05:21:31 -08:00
|
|
|
app.quit()
|
2021-12-25 14:39:47 +01:00
|
|
|
} else {
|
|
|
|
app.on('second-instance', (event, cmd, dir) => {
|
|
|
|
if (myWindow) {
|
|
|
|
if (myWindow.isMinimized()) myWindow.restore()
|
|
|
|
myWindow.focus()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
app.allowRendererProcessReuse = true
|
|
|
|
app.on('ready', () => {
|
|
|
|
createWindow();
|
|
|
|
createTray();
|
|
|
|
if (process.platform === 'win32') {
|
2022-12-07 10:41:28 +01:00
|
|
|
app.setAppUserModelId("org.qortal.QortalUI")
|
2021-12-25 14:39:47 +01:00
|
|
|
}
|
2022-12-07 10:41:28 +01:00
|
|
|
autoUpdater.checkForUpdatesAndNotify()
|
2022-03-01 10:24:06 +01:00
|
|
|
setInterval(() => {
|
2022-12-07 10:41:28 +01:00
|
|
|
autoUpdater.checkForUpdatesAndNotify()
|
|
|
|
}, 1000 * 60 * 720)
|
2021-12-25 14:39:47 +01:00
|
|
|
})
|
|
|
|
app.on('window-all-closed', function () {
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
app.quit();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
app.on('activate', function () {
|
|
|
|
if (myWindow === null) {
|
2022-12-07 10:41:28 +01:00
|
|
|
createWindow()
|
|
|
|
createTray()
|
2021-12-25 14:39:47 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
ipcMain.on('app_version', (event) => {
|
2022-02-04 05:21:31 -08:00
|
|
|
log.info(app.getVersion());
|
2022-12-07 10:41:28 +01:00
|
|
|
mainWindow.webContents.send('app_version', { version: app.getVersion() })
|
|
|
|
})
|
|
|
|
autoUpdater.on('update-available', (event) => {
|
|
|
|
const downloadOpts = {
|
|
|
|
type: 'info',
|
|
|
|
buttons: ['YES', 'NO'],
|
|
|
|
title: i18n.__("electron_translate_3"),
|
|
|
|
detail: i18n.__("electron_translate_4")
|
|
|
|
}
|
|
|
|
dialog.showMessageBox(downloadOpts).then((returnValue) => {
|
|
|
|
if (returnValue.response === 0) {
|
|
|
|
autoUpdater.downloadUpdate()
|
|
|
|
const dl = new Notification({
|
|
|
|
title: i18n.__("electron_translate_11"),
|
|
|
|
body: i18n.__("electron_translate_12")
|
|
|
|
})
|
|
|
|
dl.show()
|
|
|
|
} else {
|
|
|
|
return
|
|
|
|
}
|
2021-12-25 14:39:47 +01:00
|
|
|
})
|
2022-12-07 10:41:28 +01:00
|
|
|
})
|
|
|
|
autoUpdater.on('download-progress', (progressObj) => {
|
|
|
|
myWindow.webContents.send('downloadProgress', progressObj)
|
2021-12-25 14:39:47 +01:00
|
|
|
})
|
2022-02-15 19:23:10 +01:00
|
|
|
autoUpdater.on('update-downloaded', (event) => {
|
|
|
|
const dialogOpts = {
|
|
|
|
type: 'info',
|
2022-12-07 10:41:28 +01:00
|
|
|
buttons: [i18n.__("electron_translate_5"), i18n.__("electron_translate_6")],
|
|
|
|
title: i18n.__("electron_translate_7"),
|
|
|
|
message: i18n.__("electron_translate_8"),
|
|
|
|
detail: i18n.__("electron_translate_9")
|
2022-02-15 19:23:10 +01:00
|
|
|
}
|
|
|
|
dialog.showMessageBox(dialogOpts).then((returnValue) => {
|
|
|
|
if (returnValue.response === 0) {
|
|
|
|
autoUpdater.quitAndInstall()
|
|
|
|
} else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2021-12-25 14:39:47 +01:00
|
|
|
autoUpdater.on('error', (err) => {
|
|
|
|
const n = new Notification({
|
2022-12-07 10:41:28 +01:00
|
|
|
title: i18n.__("electron_translate_10"),
|
2021-12-25 14:39:47 +01:00
|
|
|
body: err
|
|
|
|
})
|
2022-12-07 10:41:28 +01:00
|
|
|
n.show()
|
2021-12-25 14:39:47 +01:00
|
|
|
})
|
|
|
|
}
|