-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.js
More file actions
74 lines (59 loc) · 2.06 KB
/
Copy pathmain.js
File metadata and controls
74 lines (59 loc) · 2.06 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
import { readServices } from './lib/read-services' with { type: 'macro' };
import { dirname, resolve } from 'node:path';
import { app, BrowserWindow, globalShortcut, ipcMain } from 'electron';
import { serial } from './lib/serial';
import { bluetooth } from './lib/bluetooth';
import { readLoaclBlocks } from './lib/local-blocks';
import { readLoaclEditors } from './lib/local-editors';
import { readLoaclTutorials } from './lib/local-tutorials';
import * as localPath from './lib/local-path';
import './lib/menu';
const isMac = process.platform === 'darwin';
const __dirname = dirname(require.resolve('./main.js'));
const winConfig = {
width: 1100,
height: 760,
webPreferences: {
preload: resolve(__dirname, 'preload.js'),
},
};
// 如果是 macOS 系统,隐藏标题栏
if (isMac) {
winConfig.titleBarStyle = 'hidden';
// 修改“🚥”位置
winConfig.trafficLightPosition = { x: 8, y: 16 };
}
app.whenReady().then(() => {
const mainWindow = new BrowserWindow(winConfig);
// 注册重载快捷键
// globalShortcut.register('CommandOrControl+R', () => {
// mainWindow.reload();
// });
globalShortcut.register('CommandOrControl+Shift+I', () => {
mainWindow.webContents.openDevTools();
});
serial.setBrowserWindow(mainWindow);
bluetooth.setBrowserWindow(mainWindow);
mainWindow.on('enter-full-screen', () => {
mainWindow.webContents.send('window:fullscreen', true);
});
mainWindow.on('leave-full-screen', () => {
mainWindow.webContents.send('window:fullscreen', false);
});
mainWindow.loadFile(resolve(__dirname, 'index.html'));
ipcMain.on('local:cwd', (event) => (event.returnValue = __dirname));
ipcMain.on('local:home', (event) => (event.returnValue = localPath.home));
// 读取本地资源
readLoaclBlocks();
readLoaclEditors();
readLoaclTutorials();
// 启动扩展服务
const services = readServices();
for (const { service } of services) {
if (service) {
const { default: startService } = require(service);
startService();
}
}
});
app.on('window-all-closed', () => app.quit());