index.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. /*const assetdl = require('./app/assets/js/assetdownload.js')
  17. const basePath = path.join(__dirname, 'mcfiles')
  18. const dataPromise = assetdl.parseVersionData('1.11.2', basePath)
  19. dataPromise.then(function(data){
  20. assetdl.downloadAssets(data, basePath)
  21. assetdl.downloadClient(data, basePath)
  22. assetdl.downloadLogConfig(data, basePath)
  23. assetdl.downloadLibraries(data, basePath)
  24. })*/
  25. win.on('closed', () => {
  26. win = null
  27. })
  28. }
  29. function getPlatformIcon(filename){
  30. const opSys = process.platform
  31. if (opSys === 'darwin') {
  32. filename = filename + '.icns'
  33. } else if (opSys === 'win32') {
  34. filename = filename + '.ico'
  35. } else {
  36. filename = filename + '.png'
  37. }
  38. return path.join(__dirname, 'app', 'assets', 'images', filename)
  39. }
  40. app.on('ready', createWindow);
  41. app.on('window-all-closed', () => {
  42. // On macOS it is common for applications and their menu bar
  43. // to stay active until the user quits explicitly with Cmd + Q
  44. if (process.platform !== 'darwin') {
  45. app.quit()
  46. }
  47. })
  48. app.on('activate', () => {
  49. // On macOS it's common to re-create a window in the app when the
  50. // dock icon is clicked and there are no other windows open.
  51. if (win === null) {
  52. createWindow()
  53. }
  54. })