index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * This file is part of Moeditor.
  3. *
  4. * Copyright (c) 2016 Menci <huanghaorui301@gmail.com>
  5. * Copyright (c) 2015 Thomas Brouard (for codes from Abricotine)
  6. *
  7. * Moeditor is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Moeditor is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Moeditor. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. 'use strict';
  21. // on darwin, to rewrite path
  22. if (process.platform === "darwin") {
  23. const shellEnvs = require('shell-env').sync()
  24. process.env.PATH = shellEnvs.PATH;
  25. }
  26. const app = require('electron').app,
  27. MoeditorApplication = require('./moe-app');
  28. var moeApp = null, openFile = null;
  29. app.on("ready", () => {
  30. moeApp = new MoeditorApplication();
  31. global.moeApp = moeApp;
  32. global.app = app;
  33. app.moeApp = moeApp;
  34. if (openFile !== null)
  35. moeApp.osxOpenFile = openFile;
  36. moeApp.run();
  37. });
  38. app.on('window-all-closed', () => {
  39. if (process.platform !== 'darwin') {
  40. app.quit();
  41. }
  42. });
  43. app.on('open-file', (e, file) => {
  44. if (moeApp === null) openFile = file;
  45. else moeApp.open(file);
  46. });
  47. app.on('activate', () => {
  48. if (moeApp != null && moeApp.windows && moeApp.windows.length == 0) {
  49. moeApp.open();
  50. }
  51. });