| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- const { app, BrowserWindow, Menu, shell } = require('electron');
- const path = require('path');
- // Keep a global reference of the window object
- let mainWindow;
- function createWindow() {
- // Create the browser window
- mainWindow = new BrowserWindow({
- width: 1200,
- height: 800,
- minWidth: 800,
- minHeight: 600,
- icon: path.join(__dirname, 'img/logo.png'),
- webPreferences: {
- nodeIntegration: false,
- contextIsolation: true,
- enableRemoteModule: false,
- webSecurity: true
- },
- show: false // Don't show until ready
- });
- // Load the home page
- mainWindow.loadFile(path.join(__dirname, 'home.html'));
- // Show window when ready to prevent visual flash
- mainWindow.once('ready-to-show', () => {
- mainWindow.show();
- });
- // Handle external links
- mainWindow.webContents.setWindowOpenHandler(({ url }) => {
- shell.openExternal(url);
- return { action: 'deny' };
- });
- // Emitted when the window is closed
- mainWindow.on('closed', () => {
- mainWindow = null;
- });
- // Create application menu
- createMenu();
- }
- function createMenu() {
- const template = [
- {
- label: 'File',
- submenu: [
- {
- label: 'New Note',
- accelerator: 'CmdOrCtrl+N',
- click: () => {
- mainWindow.loadFile(path.join(__dirname, 'index.html'));
- }
- },
- {
- label: 'Home',
- accelerator: 'CmdOrCtrl+H',
- click: () => {
- mainWindow.loadFile(path.join(__dirname, 'home.html'));
- }
- },
- { type: 'separator' },
- {
- label: 'Quit',
- accelerator: process.platform === 'darwin' ? 'Cmd+Q' : 'Ctrl+Q',
- click: () => {
- app.quit();
- }
- }
- ]
- },
- {
- label: 'Edit',
- submenu: [
- { role: 'undo' },
- { role: 'redo' },
- { type: 'separator' },
- { role: 'cut' },
- { role: 'copy' },
- { role: 'paste' },
- { role: 'selectall' }
- ]
- },
- {
- label: 'View',
- submenu: [
- { role: 'reload' },
- { role: 'forceReload' },
- { role: 'toggleDevTools' },
- { type: 'separator' },
- { role: 'resetZoom' },
- { role: 'zoomIn' },
- { role: 'zoomOut' },
- { type: 'separator' },
- { role: 'togglefullscreen' }
- ]
- },
- {
- label: 'Window',
- submenu: [
- { role: 'minimize' },
- { role: 'close' }
- ]
- }
- ];
- // macOS specific menu adjustments
- if (process.platform === 'darwin') {
- template.unshift({
- label: app.getName(),
- submenu: [
- { role: 'about' },
- { type: 'separator' },
- { role: 'services' },
- { type: 'separator' },
- { role: 'hide' },
- { role: 'hideothers' },
- { role: 'unhide' },
- { type: 'separator' },
- { role: 'quit' }
- ]
- });
- // Window menu
- template[4].submenu = [
- { role: 'close' },
- { role: 'minimize' },
- { role: 'zoom' },
- { type: 'separator' },
- { role: 'front' }
- ];
- }
- const menu = Menu.buildFromTemplate(template);
- Menu.setApplicationMenu(menu);
- }
- // This method will be called when Electron has finished initialization
- app.whenReady().then(() => {
- createWindow();
- app.on('activate', () => {
- // On macOS, re-create a window when the dock icon is clicked
- if (BrowserWindow.getAllWindows().length === 0) {
- createWindow();
- }
- });
- });
- // Quit when all windows are closed
- app.on('window-all-closed', () => {
- // On macOS, keep the app running even when all windows are closed
- if (process.platform !== 'darwin') {
- app.quit();
- }
- });
- // Security: Prevent new window creation
- app.on('web-contents-created', (event, contents) => {
- contents.on('new-window', (event, url) => {
- event.preventDefault();
- shell.openExternal(url);
- });
- });
|