-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.mjs
More file actions
116 lines (100 loc) · 3.21 KB
/
Copy pathmain.mjs
File metadata and controls
116 lines (100 loc) · 3.21 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
import { app, BrowserWindow, BrowserView, ipcMain, shell } from 'electron';
import path from 'path';
import { fileURLToPath } from 'url';
import RPC from 'discord-rpc';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
let mainWindow;
let rpc;
const CLIENT_ID = '1440987325340454952';
function setupDiscordRPC() {
rpc = new RPC.Client({ transport: 'ipc' });
rpc.on('ready', () => setActivity());
rpc.login({ clientId: CLIENT_ID }).catch(console.error);
}
function setActivity(details = 'Controlling with the Flight Strip Manager', state = 'Online') {
if (!rpc) return;
rpc.setActivity({
details: 'Controlling with the Flight Strip Manager',
state: 'Online',
startTimestamp: new Date(),
largeImageKey: 'icon_large',
largeImageText: 'Flight Strip Manager Desktop',
smallImageKey: 'icon_small',
smallImageText: 'Electron',
instance: false
});
}
async function createWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
icon: path.join(__dirname, 'favicon.ico'),
frame: false,
webPreferences: {
preload: path.join(__dirname, 'preload.mjs'),
contextIsolation: true,
nodeIntegration: false,
partition: 'persist:24scope'
}
});
const topBar = new BrowserView({
webPreferences: {
preload: path.join(__dirname, 'preload.mjs'),
contextIsolation: true,
nodeIntegration: false
}
});
mainWindow.setBrowserView(topBar);
topBar.setBounds({ x: 0, y: 0, width: 1200, height: 32 });
topBar.setAutoResize({ width: true });
await topBar.webContents.loadFile(path.join(__dirname, 'topbar.html'));
const contentView = new BrowserView({
webPreferences: {
preload: path.join(__dirname, 'preload.mjs'),
contextIsolation: true,
nodeIntegration: false
}
});
mainWindow.addBrowserView(contentView);
contentView.setBounds({ x: 0, y: 32, width: 1200, height: 768 });
contentView.setAutoResize({ width: true, height: true });
await contentView.webContents.loadURL('https://fsm.awdevsoftware.org/');
contentView.webContents.on('did-navigate', (_, url) => setActivity(`Viewing ${url}`, 'Online'));
mainWindow.on('closed', () => (mainWindow = null));
}
app.whenReady().then(() => {
createWindow();
setupDiscordRPC();
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});
ipcMain.handle('window-control', (event, action) => {
if (!mainWindow) return;
switch (action) {
case 'minimize':
mainWindow.minimize();
break;
case 'maximize':
mainWindow.isMaximized() ? mainWindow.unmaximize() : mainWindow.maximize();
break;
case 'close':
mainWindow.close();
break;
default:
console.error(`Unknown action: ${action}`);
}
});
ipcMain.handle('open-external', async (e, url) => await shell.openExternal(url));
ipcMain.handle('clear-cookies', async () => {
if (!mainWindow) return;
try {
await mainWindow.webContents.session.clearStorageData({ storages: ['cookies'] });
} catch (e) {
console.error(e);
}
});