index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. //Code for testing, marked for removal one it's properly implemented.
  16. //require('./app/assets/js/assetdownload.js').getMojangAssets('1.11', path.join(__dirname, 'mcfiles'))
  17. win.on('closed', () => {
  18. win = null
  19. })
  20. }
  21. function getPlatformIcon(filename){
  22. if (process.platform === 'darwin') {
  23. filename = filename + '.icns'
  24. } else if (process.platform === 'win32') {
  25. filename = filename + '.ico'
  26. } else {
  27. filename = filename + '.png'
  28. }
  29. return path.join(__dirname, 'app', 'assets', 'images', filename)
  30. }
  31. app.on('ready', createWindow);
  32. app.on('window-all-closed', () => {
  33. // On macOS it is common for applications and their menu bar
  34. // to stay active until the user quits explicitly with Cmd + Q
  35. if (process.platform !== 'darwin') {
  36. app.quit()
  37. }
  38. })
  39. app.on('activate', () => {
  40. // On macOS it's common to re-create a window in the app when the
  41. // dock icon is clicked and there are no other windows open.
  42. if (win === null) {
  43. createWindow()
  44. }
  45. })