index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. require('./app/assets/js/launchprocess.js').launchMinecraft(data, basePath)
  25. })
  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. })