-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
131 lines (107 loc) · 4.06 KB
/
main.js
File metadata and controls
131 lines (107 loc) · 4.06 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
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
/*
* Filename: main.js
* Author: SaturdayNightDead (BeanedTaco)
* Created: 21 February 2020
* Description: The main process of Vision. This file handles updates, windows, and basically all other functions the Browser uses.
* Originally from electron/electron-quick-start
*/
// Load Electron modules
const { app, BrowserWindow, globalShortcut, ipcMain, Notification, BrowserView } = require('electron')
const {autoUpdater} = require("electron-updater");
const path = require('path')
require('v8-compile-cache');
app.on('ready', () => {
autoUpdater.checkForUpdatesAndNotify();
const mainWindow = new BrowserWindow({
width: 1024,
height: 512,
minHeight: 512,
minWidth: 1024,
frame: false,
show: true,
webPreferences: {
webviewTag: true,
nodeIntegration: false,
enableRemoteModule: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js')
}
});
// Load browser
const webpage = new BrowserView();
mainWindow.loadFile('browser.html')
globalShortcut.register('Control+Shift+I', () => {
return mainWindow.webContents.executeJavaScript(`
document.getElementsByTagName("webview")[0].openDevTools();
`)
})
globalShortcut.register('Control+W', () => {
return app.quit();
})
globalShortcut.register('Alt+Shift+I', () => {
return mainWindow.webContents.openDevTools();
})
globalShortcut.register('Control+R', () => {
mainWindow.webContents.executeJavaScript(`
window.api.webFunctions.reload()
`)
})
const visionApi = mainWindow.webContents.api
// Handback reference example:
// visionApi.ipc.handback("example", responseObj);
// Functions
ipcMain.on('about', (e, message) => {
console.log('Opening vision://about window..', e, message);
const aboutWindow = new BrowserWindow({
width: 1024,
height: 512,
frame: false,
show: true,
webPreferences: {
webviewTag: false,
nodeIntegration: false,
enableRemoteModule: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js')
}
})
aboutWindow.loadFile('version.html')
});
ipcMain.on('devTools', (e, message) => {
mainWindow.webContents.openDevTools()
});
ipcMain.on('reload', (e, message) => {
return mainWindow.webContents.executeJavaScript("navigateTo(`${document.getElementsByTagName('webview')[0].getURL()}`)")
});
ipcMain.on('panic', (e, message) => {
return mainWindow.webContents.executeJavaScript("document.getElementsByTagName('webview')[0].executeJavaScript(`window.close()`)")
});
ipcMain.on('reloadMain', (e, message) => {
mainWindow.webContents.reload();
});
/* THIS OLD METHOD IS DEPRECATED
* ipcMain.on('go', async (URL) => {
mainWindow.webContents.executeJavaScript(`document.getElementsByTagName('webview')[0].src = ${URL}`)
}); */
ipcMain.on('forward', (e, message) => {
mainWindow.webContents.executeJavaScript(`
document.getElementsByTagName('webview')[0].goForward();
`)
});
ipcMain.on('back', (e, message) => {
mainWindow.webContents.executeJavaScript(`document.getElementsByTagName('webview')[0].goBack()`)
});
ipcMain.on('close', (e, message) => {
console.log('Closing Vision..', e, message);
app.quit();
});
});
app.on('window-all-closed', function () {
// When all windows are closed, the app quits unless if platform = Darwin (macOS)
if (process.platform !== 'darwin') app.quit()
})
app.on('activate', function () {
// For macOS: If app is still open, when program launched, just create a new window.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
// NOTE TO SELF: include more code if needed