index.js 1.8 KB

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