index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const {app, BrowserWindow} = require('electron')
  2. const path = require('path')
  3. const url = require('url')
  4. const fs = require('fs')
  5. const ejse = require('ejs-electron')
  6. // Keep a global reference of the window object, if you don't, the window will
  7. // be closed automatically when the JavaScript object is garbage collected.
  8. let win
  9. function createWindow() {
  10. win = new BrowserWindow({ width: 980, height: 552, icon: getPlatformIcon('WesterosSealSquare'), frame: false})
  11. ejse.data('bkid', Math.floor((Math.random() * fs.readdirSync(path.join(__dirname, 'app', 'assets', 'images', 'backgrounds')).length)))
  12. win.loadURL(url.format({
  13. pathname: path.join(__dirname, 'app', 'index.ejs'),
  14. protocol: 'file:',
  15. slashes: true
  16. }))
  17. win.setMenu(null)
  18. win.setResizable(true)
  19. win.on('closed', () => {
  20. win = null
  21. })
  22. }
  23. function getPlatformIcon(filename){
  24. const opSys = process.platform
  25. if (opSys === 'darwin') {
  26. filename = filename + '.icns'
  27. } else if (opSys === 'win32') {
  28. filename = filename + '.ico'
  29. } else {
  30. filename = filename + '.png'
  31. }
  32. return path.join(__dirname, 'app', 'assets', 'images', filename)
  33. }
  34. app.on('ready', createWindow);
  35. app.on('window-all-closed', () => {
  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') {
  39. app.quit()
  40. }
  41. })
  42. app.on('activate', () => {
  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 (win === null) {
  46. createWindow()
  47. }
  48. })