(base) 192:WebstormProjects achao$ npx create-electron-app@latest simple-electron Need to install the following packages: create-electron-app@7.8.0 Ok to proceed? (y)
// and load the index.html of the app. mainWindow.loadFile(path.join(__dirname, 'index.html'));
// Open the DevTools. // mainWindow.webContents.openDevTools(); };
// This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.whenReady().then(() => { createWindow();
// ✅ 注册 handler! ipcMain.handle('add', (_, a, b) => { console.log('native.add called with:', a, b); return native.add(a, b); });
ipcMain.handle('multiply', (_, a, b) => { console.log('native.multiply called with:', a, b); return native.multiply(a, b); });
// On OS X it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow(); } }); });
// Quit when all windows are closed, except on macOS. There, it's common // for applications and their menu bar to stay active until the user quits // explicitly with Cmd + Q. app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } });
// In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and import them here.
// See the Electron documentation for details on how to use preload scripts: // https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('api', { add: (a, b) => ipcRenderer.invoke('add', a, b), multiply: (a, b) => ipcRenderer.invoke('multiply', a, b), });
81 packages are looking for funding run `npm fund` for details
found 0 vulnerabilities (base) 192:simple-electron achao$ npx node-gyp configure gyp info it worked if it ends with ok gyp info using node-gyp@11.1.0 gyp info using node@20.6.1 | darwin | arm64 gyp info find Python using Python version 3.12.7 found at "/opt/homebrew/Caskroom/miniconda/base/bin/python3"
gyp info spawn /opt/homebrew/Caskroom/miniconda/base/bin/python3 gyp info spawn args [ gyp info spawn args '/Users/achao/WebstormProjects/simple-electron/node_modules/node-gyp/gyp/gyp_main.py', gyp info spawn args 'binding.gyp', gyp info spawn args '-f', gyp info spawn args 'make', gyp info spawn args '-I', gyp info spawn args '/Users/achao/WebstormProjects/simple-electron/build/config.gypi', gyp info spawn args '-I', gyp info spawn args '/Users/achao/WebstormProjects/simple-electron/node_modules/node-gyp/addon.gypi', gyp info spawn args '-I', gyp info spawn args '/Users/achao/Library/Caches/node-gyp/20.6.1/include/node/common.gypi', gyp info spawn args '-Dlibrary=shared_library', gyp info spawn args '-Dvisibility=default', gyp info spawn args '-Dnode_root_dir=/Users/achao/Library/Caches/node-gyp/20.6.1', gyp info spawn args '-Dnode_gyp_dir=/Users/achao/WebstormProjects/simple-electron/node_modules/node-gyp', gyp info spawn args '-Dnode_lib_file=/Users/achao/Library/Caches/node-gyp/20.6.1/<(target_arch)/node.lib', gyp info spawn args '-Dmodule_root_dir=/Users/achao/WebstormProjects/simple-electron', gyp info spawn args '-Dnode_engine=v8', gyp info spawn args '--depth=.', gyp info spawn args '--no-parallel', gyp info spawn args '--generator-output', gyp info spawn args 'build', gyp info spawn args '-Goutput_dir=.' gyp info spawn args ] gyp info ok (base) 192:simple-electron achao$ npx node-gyp build gyp info it worked if it ends with ok gyp info using node-gyp@11.1.0 gyp info using node@20.6.1 | darwin | arm64 gyp info spawn make gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ] CXX(target) Release/obj.target/hello/src/hello.o SOLINK_MODULE(target) Release/hello.node gyp info ok