-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.js
87 lines (87 loc) · 1.97 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
+import electron from 'electron';
import path from 'path';
// if (require.main !== module) {
// import('update-electron-app')({
// logger: require('electron-log')
// });KKK
// }
import schemes from './schemes/index.js';
import stateFactory from './state/index.js';
import universalWebSocket from './browser/protocol/';
const state = stateFactory('browser', {
electron
});
const { file: { readJson, } } = state;
const config = await readJson('./config/index.json');
const {
app,
BrowserWindow,
dialog,
protocol
} = electron;
protocol.registerSchemesAsPrivileged(schemes);
dialog.showErrorBox = function(title, content) {
console.log(`${title}\n${content}`);
};
if (process.platform === 'darwin') {
console.log('MAC BUILD');
} else if (process.platform === 'linux') {
console.log('Linux BUILD');
} else if (process.platform === 'win32') {
console.log('Windows BUILD');
}
if (process.mas) {
app.setName('Universal Web Browser');
console.log('MAC OSX STORE BUILD');
}
let mainWindow = null;
function initialize() {
if (process.mas) {
return;
}
app.requestSingleInstanceLock();
app.on('second-instance', () => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
mainWindow.focus();
}
});
function createWindow() {
const windowOptions = {
width: 1500,
minWidth: 500,
height: 900,
title: app.name,
webPreferences: {
webviewTag: true,
nodeIntegration: true
},
};
mainWindow = new BrowserWindow(windowOptions);
mainWindow.loadURL(path.join('file://', __dirname, '/index.html'));
mainWindow.on('closed', () => {
mainWindow = null;
});
console.log(config);
if (config.mainDev) {
mainWindow.webContents.openDevTools();
}
}
app.on('ready', async () => {
await universalWebSocket(state);
createWindow();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});
}
initialize();