69 lines
2.0 KiB
JavaScript
69 lines
2.0 KiB
JavaScript
"use strict";
|
|
const electron = require("electron");
|
|
const path = require("path");
|
|
const utils = require("@electron-toolkit/utils");
|
|
function createWindow() {
|
|
const mainWindow2 = new electron.BrowserWindow({
|
|
width: 354,
|
|
height: 549,
|
|
show: false,
|
|
autoHideMenuBar: true,
|
|
webPreferences: {
|
|
preload: path.join(__dirname, "../preload/index.js"),
|
|
sandbox: false
|
|
}
|
|
});
|
|
mainWindow2.on("ready-to-show", () => {
|
|
mainWindow2.show();
|
|
});
|
|
mainWindow2.webContents.setWindowOpenHandler((details) => {
|
|
electron.shell.openExternal(details.url);
|
|
return { action: "deny" };
|
|
});
|
|
if (utils.is.dev && process.env["ELECTRON_RENDERER_URL"]) {
|
|
mainWindow2.loadURL(process.env["ELECTRON_RENDERER_URL"]);
|
|
} else {
|
|
mainWindow2.loadFile(path.join(__dirname, "../renderer/index.html"));
|
|
}
|
|
}
|
|
function createNoteWindow(noteId) {
|
|
const noteWindow = new electron.BrowserWindow({
|
|
width: 354,
|
|
height: 549,
|
|
autoHideMenuBar: true,
|
|
webPreferences: {
|
|
preload: path.join(__dirname, "preload.js"),
|
|
contextIsolation: true,
|
|
nodeIntegration: false
|
|
}
|
|
});
|
|
if (utils.is.dev && process.env["ELECTRON_RENDERER_URL"]) {
|
|
noteWindow.loadURL(
|
|
`${process.env["ELECTRON_RENDERER_URL"]}/note/${noteId}`
|
|
);
|
|
} else {
|
|
mainWindow.loadFile(path.join(__dirname, "../renderer/index.html"), {
|
|
path: `/notes/${noteId}`
|
|
});
|
|
}
|
|
}
|
|
electron.app.whenReady().then(() => {
|
|
utils.electronApp.setAppUserModelId("com.electron");
|
|
electron.app.on("browser-window-created", (_, window) => {
|
|
utils.optimizer.watchWindowShortcuts(window);
|
|
});
|
|
console.log(electron.app.getPath("userData"));
|
|
createWindow();
|
|
electron.app.on("activate", function() {
|
|
if (electron.BrowserWindow.getAllWindows().length === 0) createWindow();
|
|
});
|
|
electron.ipcMain.on("open-note-window", (_, noteId) => {
|
|
createNoteWindow(noteId);
|
|
});
|
|
});
|
|
electron.app.on("window-all-closed", () => {
|
|
if (process.platform !== "darwin") {
|
|
electron.app.quit();
|
|
}
|
|
});
|