-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
core.js
95 lines (75 loc) · 3.25 KB
/
core.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
const { app, Menu } = require('electron');
const path = require("path");
const fs = require('fs');
const settings = require("electron-settings");
const defaultSettings = require("./defaultSettings.json");
class Core {
constructor() {
return (async () => {
this.app = app;
global.app = app;
this.appReady = false;
this.ppapi_flash_path;
this.ppapi();
this.settings();
if (!settings.getSync().Settings.HardwareAcceleration) {
this.app.disableHardwareAcceleration();
}
if (settings.getSync().Settings.NoSandbox) {
this.app.commandLine.appendSwitch('--no-sandbox');
}
this.app.commandLine.appendSwitch('ignore-certificate-errors');
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
this.app.setAsDefaultProtocolClient('darkorbit-client');
Menu.setApplicationMenu(Menu.buildFromTemplate([{ label: "File", submenu: [{ role: "reload" }, { role: "close" }] }]));
await this.app.whenReady();
this.appReady = true;
// https://github.com/advisories/GHSA-3p22-ghq8-v749
this.app.on('web-contents-created', (event, webContents) => {
webContents.on('select-bluetooth-device', (event, devices, callback) => {
event.preventDefault();
callback('');
});
});
return this;
})()
}
ppapi() {
if (process.platform == 'win32') {
this.ppapi_flash_path = path.join(app.getAppPath(), '../flash/pepflashplayer.dll');
if (!fs.existsSync(this.ppapi_flash_path)) {
this.ppapi_flash_path = path.join(app.getAppPath(), './flash/pepflashplayer.dll');
}
} else if (process.platform == 'linux') {
this.ppapi_flash_path = path.join(process.resourcesPath.split("/")[1] === "tmp" ? process.resourcesPath : app.getAppPath(), './flash/libpepflashplayer.so');
this.app.commandLine.appendSwitch("--no-sandbox");
} else if (process.platform == 'darwin') {
this.ppapi_flash_path = path.join(app.getAppPath(), `../flash/PepperFlashPlayer.plugin`);
if (!fs.existsSync(this.ppapi_flash_path)) {
this.ppapi_flash_path = path.join(app.getAppPath(), './flash/PepperFlashPlayer.plugin');
}
}
this.app.commandLine.appendSwitch('ppapi-flash-path', this.ppapi_flash_path);
}
settings() {
settings.configure({
atomicSave: true,
fileName: 'settings.json',
prettify: true
});
if (!settings.getSync().check) {
settings.setSync(defaultSettings);
} else {
let backup = settings.getSync();
const isObject = x =>
Object(x) === x
const merge = (left = {}, right = {}) =>
Object.entries(right)
.reduce((acc, [k, v]) =>
isObject(v) && isObject(left[k]) ? { ...acc, [k]: merge(left[k], v) } : { ...acc, [k]: v }, left
)
settings.setSync(merge(defaultSettings, backup))
}
}
}
module.exports = Core;