-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
86 lines (77 loc) · 2.14 KB
/
Copy pathindex.js
File metadata and controls
86 lines (77 loc) · 2.14 KB
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
const { app, BrowserWindow, Menu, ipcMain, dialog } = require('electron');
const { autoUpdater } = require('electron-updater');
const RPC = new require('./modules/rpc');
let discordRpc = new RPC('827268290417131540', {
verb: "idle", // edit | new | idle
});
let winMain;
function createWindow() {
app.allowRendererProcessReuse = false;
const win = new BrowserWindow({
width: 1280,
height: 720,
webPreferences: {
nodeIntegration: true
},
icon: './icon.ico'
});
win.loadFile('./editor/dist/index.html');
win.maximize();
Menu.setApplicationMenu(null);
winMain = win;
winMain.on('close', e => {
closeEvent(winMain, e);
});
}
let eventSent = false;
let t = setTimeout(() => {}, 1);
function closeEvent(winMain, e) {
if(!eventSent) {
winMain.webContents.send('close');
e.preventDefault();
eventSent = true;
clearTimeout(t);
t = setTimeout(() => {
eventSent = false;
}, 1000);
}
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform != 'darwin') app.quit();
});
app.on('browser-window-focus', () => {
winMain = BrowserWindow.getFocusedWindow();
winMain.on('close', e => {
closeEvent(winMain, e);
});
})
app.on('activate', () => {
if(BrowserWindow.getAllWindows().length == 0) createWindow();
});
ipcMain.handle('openDevTools', (e) => {
winMain.webContents.toggleDevTools();
});
ipcMain.handle('toggleFullscreen', (e) => {
winMain.setFullScreen(!winMain.fullScreen);
});
ipcMain.handle('checkUpdates', () => {
//check for updates
autoUpdater.checkForUpdatesAndNotify();
});
ipcMain.handle('restartApp', () => {
autoUpdater.quitAndInstall();
});
ipcMain.handle('updateRPC', (e, obj) => {
discordRpc.opts = obj;
});
ipcMain.on('pickFiles', (e, obj) => {
let r = dialog.showOpenDialogSync(winMain, obj[0]);
e.returnValue = r ? r[0] : null;
});
autoUpdater.on('update-availible', () => {
winMain.webContents.send('updates');
});
autoUpdater.on('update-downloaded', () => {
winMain.webContents.send('updates_done');
});