index.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. const {app, BrowserWindow} = require('electron')
  2. //const autoUpdater = require("electron-updater").autoUpdater
  3. const path = require('path')
  4. const url = require('url')
  5. const fs = require('fs')
  6. const ejse = require('ejs-electron')
  7. // Disable hardware acceleration.
  8. // https://electronjs.org/docs/tutorial/offscreen-rendering
  9. app.disableHardwareAcceleration()
  10. // Keep a global reference of the window object, if you don't, the window will
  11. // be closed automatically when the JavaScript object is garbage collected.
  12. let win
  13. function createWindow() {
  14. win = new BrowserWindow({
  15. width: 980,
  16. height: 552,
  17. icon: getPlatformIcon('WesterosSealSquare'),
  18. frame: false,
  19. webPreferences: {
  20. preload: path.join(__dirname, 'app', 'assets', 'js', 'preloader.js')
  21. }
  22. })
  23. ejse.data('bkid', Math.floor((Math.random() * fs.readdirSync(path.join(__dirname, 'app', 'assets', 'images', 'backgrounds')).length)))
  24. win.loadURL(url.format({
  25. pathname: path.join(__dirname, 'app', 'app.ejs'),
  26. protocol: 'file:',
  27. slashes: true
  28. }))
  29. win.setMenu(null)
  30. win.setResizable(true)
  31. win.on('closed', () => {
  32. win = null
  33. })
  34. }
  35. function getPlatformIcon(filename){
  36. const opSys = process.platform
  37. if (opSys === 'darwin') {
  38. filename = filename + '.icns'
  39. } else if (opSys === 'win32') {
  40. filename = filename + '.ico'
  41. } else {
  42. filename = filename + '.png'
  43. }
  44. return path.join(__dirname, 'app', 'assets', 'images', filename)
  45. }
  46. app.on('ready', createWindow);
  47. app.on('window-all-closed', () => {
  48. // On macOS it is common for applications and their menu bar
  49. // to stay active until the user quits explicitly with Cmd + Q
  50. if (process.platform !== 'darwin') {
  51. app.quit()
  52. }
  53. })
  54. app.on('activate', () => {
  55. // On macOS it's common to re-create a window in the app when the
  56. // dock icon is clicked and there are no other windows open.
  57. if (win === null) {
  58. createWindow()
  59. }
  60. })