init
This commit is contained in:
68
app.js
Normal file
68
app.js
Normal file
@@ -0,0 +1,68 @@
|
||||
import { app, BrowserWindow, globalShortcut } from 'electron';
|
||||
import paths from 'path'
|
||||
import "./server/index.js"
|
||||
|
||||
import { fileURLToPath } from 'url';
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = paths.dirname(__filename);
|
||||
|
||||
function createWindow() {
|
||||
const win = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
frame: false,
|
||||
titleBarStyle: "hidden",
|
||||
webPreferences: {
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
webviewTag: true,
|
||||
}
|
||||
});
|
||||
|
||||
win.loadFile('server/index.html');
|
||||
|
||||
win.webContents.on('did-fail-load', (e, code, desc) => {
|
||||
console.log('Webview failed:', desc);
|
||||
});
|
||||
}
|
||||
|
||||
let devToolsOpened = false;
|
||||
|
||||
function toggleDevTools(win) {
|
||||
if (devToolsOpened) {
|
||||
win.closeDevTools();
|
||||
} else {
|
||||
win.openDevTools();
|
||||
}
|
||||
devToolsOpened = !devToolsOpened;
|
||||
}
|
||||
|
||||
app.on("ready", async () => {
|
||||
// await Forms.init();
|
||||
createWindow();
|
||||
|
||||
// Register global shortcuts
|
||||
app.on("browser-window-focus", () => {
|
||||
const reloadShortcut = process.platform === "darwin" ? "Command+R" : "Control+R";
|
||||
globalShortcut.register(reloadShortcut, () => {
|
||||
BrowserWindow.getFocusedWindow().reload();
|
||||
});
|
||||
globalShortcut.register("\\", () => {
|
||||
toggleDevTools(BrowserWindow.getFocusedWindow());
|
||||
});
|
||||
});
|
||||
|
||||
app.on("browser-window-blur", () => {
|
||||
globalShortcut.unregisterAll();
|
||||
});
|
||||
});
|
||||
|
||||
app.on("activate", () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') app.quit();
|
||||
});
|
||||
Reference in New Issue
Block a user