note window opening

This commit is contained in:
nicwands
2026-02-23 11:42:22 -05:00
parent c436488f9d
commit 660b0825c5
18 changed files with 9687 additions and 9232 deletions

View File

@@ -2,30 +2,49 @@
const electron = require("electron");
const path = require("path");
const utils = require("@electron-toolkit/utils");
const icon = path.join(__dirname, "../../resources/icon.png");
function createWindow() {
const mainWindow = new electron.BrowserWindow({
const mainWindow2 = new electron.BrowserWindow({
width: 354,
height: 549,
show: false,
autoHideMenuBar: true,
...process.platform === "linux" ? { icon } : {},
webPreferences: {
preload: path.join(__dirname, "../preload/index.js"),
sandbox: false
}
});
mainWindow.on("ready-to-show", () => {
mainWindow.show();
mainWindow2.on("ready-to-show", () => {
mainWindow2.show();
});
mainWindow.webContents.setWindowOpenHandler((details) => {
mainWindow2.webContents.setWindowOpenHandler((details) => {
electron.shell.openExternal(details.url);
return { action: "deny" };
});
if (utils.is.dev && process.env["ELECTRON_RENDERER_URL"]) {
mainWindow.loadURL(process.env["ELECTRON_RENDERER_URL"]);
mainWindow2.loadURL(process.env["ELECTRON_RENDERER_URL"]);
} else {
mainWindow.loadFile(path.join(__dirname, "../renderer/index.html"));
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(() => {
@@ -33,11 +52,14 @@ electron.app.whenReady().then(() => {
electron.app.on("browser-window-created", (_, window) => {
utils.optimizer.watchWindowShortcuts(window);
});
electron.ipcMain.on("ping", () => console.log("pong"));
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") {

View File

@@ -1,7 +1,11 @@
"use strict";
const electron = require("electron");
const preload = require("@electron-toolkit/preload");
const api = {};
const api = {
openNoteWindow: (noteId) => {
electron.ipcRenderer.send("open-note-window", noteId);
}
};
if (process.contextIsolated) {
try {
electron.contextBridge.exposeInMainWorld("electron", preload.electronAPI);