-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
107 lines (89 loc) · 2.99 KB
/
index.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
104
105
106
107
const { app, BrowserWindow, Menu, shell } = require('electron');
const { autoUpdater } = require('electron-updater');
const windowStateKeeper = require('electron-window-state');
const path = require('path');
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
const createMenu = () => {
const menu = Menu.getApplicationMenu();
const viewMenu = menu.items.find(item => item.role === 'viewmenu');
if (viewMenu) {
const filteredItems = viewMenu.submenu.items;
Menu.setApplicationMenu(Menu.buildFromTemplate(filteredItems));
}
};
const createWindow = () => {
const mainWindowState = windowStateKeeper({
defaultWidth: 1040,
defaultHeight: 730,
});
const mainWindow = new BrowserWindow({
...mainWindowState,
show: false,
autoHideMenuBar: true,
webPreferences: {
contextIsolation: true,
plugins: true,
},
});
// Show the main window when it's ready
mainWindow.once('ready-to-show', () => mainWindow.show());
// Open external links in the user's default browser
mainWindow.webContents.on('new-window', (event, url) => {
event.preventDefault();
shell.openExternal(url);
});
// Display context menu
mainWindow.webContents.on('context-menu', (event, params) => {
Menu.getApplicationMenu().popup(mainWindow, params.x, params.y);
});
// Load the URL into the main window
mainWindow.loadURL('https://www.panfu.us/play');
// Manage window state
mainWindowState.manage(mainWindow);
};
const initializeFlashPlugin = () => {
let pluginName;
switch (process.platform) {
case 'win32':
pluginName = app.isPackaged ? 'pepflashplayer.dll' : 'win/x64/pepflashplayer.dll';
break;
case 'darwin':
pluginName = 'PepperFlashPlayer.plugin';
break;
default:
pluginName = 'libpepflashplayer.so';
}
const resourcesPath = app.isPackaged ? process.resourcesPath : __dirname;
if (['freebsd', 'linux', 'netbsd', 'openbsd'].includes(process.platform)) {
app.commandLine.appendSwitch('no-sandbox');
}
app.commandLine.appendSwitch('ppapi-flash-path', path.join(resourcesPath, 'plugins', pluginName));
app.commandLine.appendSwitch('ppapi-flash-version', '32.0.0.465');
};
app.on('second-instance', () => {
const mainWindow = BrowserWindow.getAllWindows()[0];
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
}
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
initializeFlashPlugin();
app.whenReady().then(() => {
createMenu();
createWindow();
autoUpdater.checkForUpdates();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
}