This repository has been archived by the owner on Nov 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
103 lines (86 loc) · 2.82 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
/* jshint esversion: 6 */
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const path = require('path');
const url = require('url');
const windowStateKeeper = require('electron-window-state');
const fs = require('fs');
let mainWindow;
function createWindow () {
let mainWindowState = windowStateKeeper({
defaultWidth: 800,
defaultHeight: 600
});
mainWindow = new BrowserWindow({
title: app.getName(),
x: mainWindowState.x,
y: mainWindowState.y,
width: mainWindowState.width,
height: mainWindowState.height,
minWidth: 768,
minHeight: 600,
center: true,
titleBarStyle: 'hidden',
autoHideMenuBar: true,
backgroundColor: '#000',
webPreferences: {
webviewTag: true,
nodeIntegration: true
}
});
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true,
}));
mainWindow.on('closed', function () {
mainWindow = null;
});
mainWindowState.manage(mainWindow);
require(__dirname + '/assets/js/menu');
}
app.on('ready', createWindow);
app.on('window-all-closed', function () {
if(process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', function () {
if(mainWindow === null) {
createWindow();
}
});
app.on('web-contents-created', (e, contents) => {
if(contents.getType() == 'webview') {
contents.on('will-navigate', (e, reqUrl) => {
let getHost = url=>require('url').parse(url).host;
let reqHost = getHost(reqUrl);
let isExternal = reqHost && reqHost != getHost(contents.getURL());
if(isExternal) {
electron.shell.openExternal(reqUrl);
e.preventDefault();
}
});
contents.on('new-window', (e, url) => {
electron.shell.openExternal(url);
e.preventDefault();
});
contents.on('dom-ready', function() {
fs.readFile(__dirname + '/assets/js/plugins/keypress-2.1.5.min.js', 'utf-8', function(error, data) {
contents.executeJavaScript(data);
});
fs.readFile(__dirname + '/assets/js/inject-all.js', 'utf-8', function(error, data) {
contents.executeJavaScript(data);
});
fs.readFile(__dirname + '/assets/css/inject-all.css', 'utf-8', function(error, data) {
contents.insertCSS(data);
});
if(process.platform === 'darwin') {
fs.readFile(__dirname + '/assets/css/inject-macos.css', 'utf-8', function(error, data) {
contents.insertCSS(data);
});
}
});
}
});