-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmain.js
More file actions
96 lines (87 loc) · 2.63 KB
/
main.js
File metadata and controls
96 lines (87 loc) · 2.63 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
/*
RPG Paper Maker Copyright (C) 2017-2020 Wano
RPG Paper Maker engine is under proprietary license.
This source code is also copyrighted.
Use Commercial edition for commercial use of your games.
See RPG Paper Maker EULA here:
http://rpg-paper-maker.com/index.php/eula.
*/
import { app, BrowserWindow, dialog, globalShortcut, ipcMain } from 'electron';
import { promises as fs } from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
app.commandLine.appendSwitch('high-dpi-support', 'true');
app.commandLine.appendSwitch('force-device-scale-factor', '1');
app.commandLine.appendSwitch('ignore-gpu-blocklist');
if (process.platform === 'darwin') {
if (process.arch === 'arm64') {
// Apple Silicon: Metal works well
app.commandLine.appendSwitch('use-angle', 'metal');
app.commandLine.appendSwitch('use-gl', 'angle');
app.commandLine.appendSwitch('enable-features', 'Metal');
} else {
// Intel Mac: Metal/ANGLE causes BindToCurrentSequence failures, fall back to OpenGL
app.commandLine.appendSwitch('use-angle', 'gl');
}
}
let window;
function createWindow() {
window = new BrowserWindow({
title: '',
width: 640,
height: 480,
resizable: false,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
contextIsolation: false,
preload: path.join(__dirname, 'preload.js'),
},
});
ipcMain.on('window-error', function (event, err) {
window.webContents.openDevTools();
window.setFullScreen(false);
});
ipcMain.on('dialog-error-message', function (event, err) {
dialog.showMessageBoxSync({ title: 'Error', type: 'error', message: err });
});
ipcMain.on('change-window-title', function (event, title) {
window.setTitle(title);
});
ipcMain.on('change-window-size', function (event, w, h, f) {
if (f) {
window.setResizable(true);
window.setFullScreen(true);
} else {
window.setContentSize(w, h);
window.center();
window.setFullScreen(false);
}
});
ipcMain.on('save-file', async (event, path, content) => {
await fs.writeFile(path, content, 'utf-8');
return true;
});
window.loadFile('index.html');
window.removeMenu();
}
app.whenReady().then(() => {
const shortcuts = ['CommandOrControl+Alt+I', 'CommandOrControl+Shift+I'];
for (const shortcut of shortcuts) {
globalShortcut.register(shortcut, () => {
window.openDevTools({ mode: 'undocked' });
});
}
createWindow();
});
app.on('window-all-closed', () => {
app.quit();
});
// Mac OS open new window if clicking on dock again
app.on('activate', () => {
if (!window) {
createWindow();
}
});