forked from Qortal/qortal-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
electron.js
158 lines (145 loc) · 4.04 KB
/
electron.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
const { app, BrowserWindow, ipcMain, Menu, Notification, Tray, nativeImage, dialog } = require('electron');
const { autoUpdater } = require('electron-updater');
const server = require('./server.js');
const log = require('electron-log');
const path = require('path');
// THOUGHTS: Make this APP more modularize and platform agnostic...
process.env['APP_PATH'] = app.getAppPath();
autoUpdater.logger = log;
log.info('App starting...');
const editMenu = Menu.buildFromTemplate([
{
label: "Qortal",
submenu: [{
label: "Quit",
click() {
app.quit();
}
}]
},
{
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:"}
]
}
]);
Menu.setApplicationMenu(editMenu);
let myWindow = null;
// TODO: Move the Tray function into another file (maybe Tray.js) -_-
// const tray = new Tray(nativeImage.createEmpty());
const APP_ICON = path.join(__dirname, 'img', 'icons');
const iconPath = () => {
return APP_ICON + (process.platform === 'win32' ? '/ico/256x256.ico' : '/png/256x256.png');
};
function createWindow() {
myWindow = new BrowserWindow({
backgroundColor: '#eee',
width: 1280,
height: 720,
minWidth: 700,
minHeight: 640,
icon: iconPath(),
title: "Qortal",
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: false,
partition: 'persist:webviewsession',
enableRemoteModule: false,
nativeWindowOpen: false,
sandbox: true
},
show: false
})
myWindow.maximize();
myWindow.show();
myWindow.loadURL('http://localhost:12388/app/wallet')
myWindow.on('closed', function () {
myWindow = null
})
}
const createTray = () => {
let myTray = new Tray(path.join(__dirname, 'img', 'icons', 'png', '32x32.png'))
const contextMenu = Menu.buildFromTemplate([{
label: "Quit", click() {
myTray.destroy();
app.quit();
},
}])
myTray.setTitle("QORTAL UI")
myTray.setToolTip("QORTAL UI")
myTray.setContextMenu(contextMenu)
}
const isLock = app.requestSingleInstanceLock();
if (!isLock) {
app.quit()
} 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') {
app.setAppUserModelId("org.qortal.QortalUI");
}
autoUpdater.checkForUpdatesAndNotify();
setInterval(() => {
autoUpdater.checkForUpdatesAndNotify();
}, 1000 * 60 * 15)
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
})
app.on('activate', function () {
if (myWindow === null) {
createWindow();
createTray();
}
})
ipcMain.on('app_version', (event) => {
log.info(app.getVersion());
mainWindow.webContents.send('app_version', { version: app.getVersion() });
});
autoUpdater.on('update-available', () => {
const n = new Notification({
title: 'Update Available!',
body: 'It will be downloaded ⌛️ in the background!'
})
n.show();
})
autoUpdater.on('update-downloaded', (event) => {
const dialogOpts = {
type: 'info',
buttons: ['Restart now', 'Install after close Qortal UI'],
title: 'Update available',
detail: 'A new Qortal UI version has been downloaded. Click RESTART NOW to apply update, or INSTALL AFTER CLOSE QORTAL UI to install after you quit the UI.'
}
dialog.showMessageBox(dialogOpts).then((returnValue) => {
if (returnValue.response === 0) {
autoUpdater.quitAndInstall()
} else {
return
}
})
})
autoUpdater.on('error', (err) => {
const n = new Notification({
title: 'Error while Updating...',
body: err
})
n.show();
})
}