index.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const {app, BrowserWindow} = require('electron')
  2. const path = require('path')
  3. const url = require('url')
  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 win
  7. function createWindow() {
  8. win = new BrowserWindow({ width: 925, height: 500, icon: getPlatformIcon('WesterosSealSquare')})
  9. win.loadURL(url.format({
  10. pathname: path.join(__dirname, 'app', 'index.html'),
  11. protocol: 'file:',
  12. slashes: true
  13. }))
  14. win.setMenu(null)
  15. win.on('closed', () => {
  16. win = null
  17. })
  18. }
  19. function getPlatformIcon(filename){
  20. const opSys = process.platform
  21. if (opSys === 'darwin') {
  22. filename = filename + '.icns'
  23. } else if (opSys === 'win32') {
  24. filename = filename + '.ico'
  25. } else {
  26. filename = filename + '.png'
  27. }
  28. return path.join(__dirname, 'app', 'assets', 'images', filename)
  29. }
  30. app.on('ready', createWindow);
  31. app.on('window-all-closed', () => {
  32. // On macOS it is common for applications and their menu bar
  33. // to stay active until the user quits explicitly with Cmd + Q
  34. if (process.platform !== 'darwin') {
  35. app.quit()
  36. }
  37. })
  38. app.on('activate', () => {
  39. // On macOS it's common to re-create a window in the app when the
  40. // dock icon is clicked and there are no other windows open.
  41. if (win === null) {
  42. createWindow()
  43. }
  44. })