-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
200 lines (179 loc) · 5.85 KB
/
main.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
const { app, BrowserWindow, Menu, dialog, shell, ipcMain } = require('electron');
const { autoUpdater } = require('electron-updater');
const path = require('path');
const log = require('electron-log');
const Store = require('electron-store');
const UPDATE_MENU_ITEM_ID = 'UPDATE_MENU_ITEM';
let win;
let menu;
let updateMenuItem;
const UPDATE_RUN_ON_STARTUP = 1;
const UPDATE_RUN_FROM_MENU = 2;
let updateRunFrom;
const store = new Store();
setAppOptions();
app.on('ready', () => {
createWindow();
autoUpdater.autoDownload = false
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = 'info';
if (app.isPackaged) {
updateRunFrom = UPDATE_RUN_ON_STARTUP;
updateMenuItem = menu.getMenuItemById(UPDATE_MENU_ITEM_ID);
updateMenuItem.enabled = false;
autoUpdater.checkForUpdates();
}
});
// on macOS, closing the window doesn't quit the app
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
// initialize the app's main window
app.on('activate', () => {
if (win === null) {
createWindow();
}
});
ipcMain.on('SETTINGS_CHANGED', (event, electronSettings) => {
const unsafeRequestsEnabled = store.get('enableUnsafeRequests');
if (electronSettings && electronSettings.enableUnsafeRequests !== unsafeRequestsEnabled) {
store.set('enableUnsafeRequests', electronSettings.enableUnsafeRequests);
dialog.showMessageBox(win, {
title: 'Restart required',
message: 'You must restart the application for Allow unsafe request setting to be applied!',
buttons: ['Restart now', 'Restart later']
}).then(res => {
const buttonIndex = res.response;
if (buttonIndex === 0) {
app.relaunch();
app.quit();
}
});;
}
});
autoUpdater.on('update-available', (updateInfo) => {
dialog.showMessageBox(win, {
type: 'question',
title: 'New version found',
message: `Current version: ${app.getVersion()}\nNew version: ${updateInfo.version}\nDo you want to update now?`,
buttons: ['Yes', 'No']
}).then(res => {
const buttonIndex = res.response;
if (buttonIndex === 0) {
autoUpdater.downloadUpdate();
dialog.showMessageBox(win, {
title: 'Downloading updates',
message: 'Updates are being downloaded in background. You will be notified when they are ready to install.'
});
}
else {
updateMenuItem.enabled = true;
updateMenuItem = null;
}
});
});
autoUpdater.on('update-not-available', () => {
updateMenuItem.enabled = true;
updateMenuItem = null;
if (updateRunFrom !== UPDATE_RUN_ON_STARTUP) {
dialog.showMessageBox(win, {
title: 'No updates found',
message: 'Current version is up to date.'
});
}
});
autoUpdater.on('update-downloaded', () => {
dialog.showMessageBox(win, {
title: 'Install Updates',
message: 'Updates downloaded, application will quit for update...'
}).then(() => {
setImmediate(() => autoUpdater.quitAndInstall());
});
});
autoUpdater.on('error', (error) => {
updateMenuItem.enabled = true;
updateMenuItem = null;
if (updateRunFrom !== UPDATE_RUN_ON_STARTUP) {
dialog.showErrorBox('Error: ', error == null ? "unknown" : (error.stack || error).toString());
}
});
function buildMenu() {
let menu = Menu.buildFromTemplate([
{
label: 'File',
submenu: [
{ role: 'quit' }
]
},
{
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'forcereload' },
{ role: 'toggledevtools' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
]
},
{
role: 'help',
submenu: [
{
label: 'Learn More',
click() { shell.openExternal('https://github.com/evilsloth/gitlab-ce-tools') }
},
{
label: 'Search Issues',
click() { shell.openExternal('https://github.com/evilsloth/gitlab-ce-tools/issues') }
},
{
id: UPDATE_MENU_ITEM_ID,
label: 'Check for updates',
click(menuItem) {
updateMenuItem = menuItem;
updateMenuItem.enabled = false;
updateRunFrom = UPDATE_RUN_FROM_MENU;
autoUpdater.checkForUpdates();
}
},
{
label: 'About',
click() { dialog.showMessageBox({
type: 'info',
'title': 'About',
message: `Gitlab CE Tools\nVersion ${app.getVersion()}`
}) }
}
]
}
]);
return menu;
}
function createWindow() {
win = new BrowserWindow({
width: 1280,
height: 720,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
webviewTag: true
}
});
menu = buildMenu();
Menu.setApplicationMenu(menu);
// load the index file from dist folder
win.loadFile(path.join(__dirname, 'index.html'));
// The following is optional and will open the DevTools:
// win.webContents.openDevTools()
win.on('closed', () => {
win = null;
});
}
function setAppOptions() {
if (store.get('enableUnsafeRequests')) {
log.warn('ignore-certificate-errors options is enabled!');
app.commandLine.appendSwitch('ignore-certificate-errors', 'true');
}
}