moe-settings.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * This file is part of Moeditor.
  3. *
  4. * Copyright (c) 2016 Menci <huanghaorui301@gmail.com>
  5. *
  6. * Moeditor is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Moeditor is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Moeditor. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. 'use strict';
  20. const {BrowserWindow, ipcMain} = require('electron');
  21. let settingsWindow;
  22. function showSettingsWindow() {
  23. if (typeof settingsWindow !== 'undefined') {
  24. if (settingsWindow.isMinimized())
  25. settingsWindow.restore();
  26. settingsWindow.focus();
  27. return;
  28. }
  29. const debug = (moeApp.flag.debug | moeApp.config.get('debug')) != 0;
  30. const conf = {
  31. icon: Const.path + "/icons/HexoEditor.ico",
  32. autoHideMenuBar: true,
  33. width: 600,
  34. height: 325,
  35. webPreferences: {
  36. zoomFactor: moeApp.config.get('scale-factor')
  37. },
  38. resizable: false,
  39. maximizable: false,
  40. show: debug
  41. };
  42. if (process.platform == 'darwin') conf.titleBarStyle = 'hidden-inset';
  43. else conf.frame = false;
  44. settingsWindow = new BrowserWindow(conf);
  45. settingsWindow.loadURL('file://' + Const.path + '/views/settings/settings.html');
  46. if (debug) settingsWindow.webContents.openDevTools();
  47. settingsWindow.webContents.on('close', () => {
  48. settingsWindow = undefined;
  49. })
  50. }
  51. function closeWindow() {
  52. console.log('close setting')
  53. if (typeof settingsWindow !== 'undefined')
  54. settingsWindow.close()
  55. }
  56. ipcMain.on('show-settings-window', showSettingsWindow);
  57. ipcMain.on('close-all-window', closeWindow);
  58. module.exports = showSettingsWindow;