const { app, BrowserWindow, globalShortcut, ipcMain } = require("electron");
const path = require("path");
let mainWindow;
let secondWindow;
const urlMain = app.isPackaged
? `file://${path.join(__dirname, "./public/index.html")}`
: "localhost:3000/";
function handleSetMinSize(event, width, height) {
const webContents = event.sender;
const window = BrowserWindow.fromWebContents(webContents);
window.setMinimumSize(width, height);
}
function handleOpenWindow(event, url, width, height) {
let windowNote = new BrowserWindow({
height: height,
width: width,
webPreferences: {
preload: path.join(__dirname, "preload.js"),
},
autoHideMenuBar: true,
});
windowNote.loadURL(url);
}
function createWindow() {
let win = new BrowserWindow({
height: 240,
width: 450,
minHeight: 240,
minWidth: 450,
maxHeight: 240,
maxWidth: 450,
webPreferences: {
preload: path.join(__dirname, "preload.js"),
},
autoHideMenuBar: true,
});
win.loadURL(`file://${path.join(__dirname, "./public/index.html")}`);
return win;
}
ipcMain.on("set-size", handleSetMinSize);
ipcMain.on("open-window", handleOpenWindow);
app.whenReady().then(() => {
mainWindow = createWindow();
const ret = globalShortcut.register("CommandOrControl+j", () => {
secondWindow = new BrowserWindow({
height: 590,
width: 550,
webPreferences: {
preload: path.join(__dirname, "preload.js"),
},
autoHideMenuBar: true,
});
secondWindow.loadURL("http://localhost:3000/note");
secondWindow.openDevTools();
});
if (!ret) {
console.log("registration failed");
}
});