index.js 1.9 KB

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