main.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Modules to control application life and create native browser window
  2. const {app, BrowserWindow} = require('electron')
  3. const path = require('path')
  4. // Keep a global reference of the window object, if you don't, the window will
  5. // be closed automatically when the JavaScript object is garbage collected.
  6. let mainWindow = {}
  7. function createWindow() {
  8. // Create the browser window.
  9. mainWindow = new BrowserWindow({
  10. width: 1220,
  11. height: 840,
  12. webPreferences: {
  13. nodeIntegration: true,
  14. contextIsolation: false,
  15. preload: app.getAppPath()+"/node_setup.js"
  16. }
  17. })
  18. // Load the index.html with 'numRunsParm' to run inference multiple times.
  19. let url = `file://${__dirname}/js_image_classification_webnn_electron.html`
  20. const numRunsParm = '?' + process.argv[2]
  21. mainWindow.loadURL(url + numRunsParm)
  22. // Emitted when the window is closed.
  23. mainWindow.on('closed', function() {
  24. // Dereference the window object, usually you would store windows
  25. // in an array if your app supports multi windows, this is the time
  26. // when you should delete the corresponding element.
  27. mainWindow = null
  28. })
  29. }
  30. // This method will be called when Electron has finished
  31. // initialization and is ready to create browser windows.
  32. // Some APIs can only be used after this event occurs.
  33. app.on('ready', createWindow)
  34. // Quit when all windows are closed.
  35. app.on('window-all-closed', function() {
  36. // On macOS it is common for applications and their menu bar
  37. // to stay active until the user quits explicitly with Cmd + Q
  38. if (process.platform !== 'darwin') app.quit()
  39. })
  40. app.on(
  41. 'activate',
  42. function() {
  43. // On macOS it's common to re-create a window in the app when the
  44. // dock icon is clicked and there are no other windows open.
  45. if (mainWindow === null) createWindow()
  46. })
  47. // In this file you can include the rest of your app's specific main process
  48. // code. You can also put them in separate files and require them here.