electron-main.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { app, BrowserWindow, nativeTheme, ipcMain } from 'electron'
  2. import logger from '../../src/util/log'
  3. ipcMain.on('window-max', () => {
  4. console.log('AAAA1')
  5. if (mainWindow.isMaximized()) {
  6. mainWindow.restore()
  7. } else {
  8. mainWindow.maximize()
  9. }
  10. })
  11. ipcMain.on('window-min', function () {
  12. console.log('AAAA1')
  13. mainWindow.minimize()
  14. })
  15. ipcMain.on('window-close', function (e) {
  16. console.log('AAAA')
  17. mainWindow.destroy()
  18. })
  19. ipcMain.handle('log', async (event, arg) => {
  20. return new Promise((resolve, reject) => {
  21. logger.info(arg)
  22. })
  23. })
  24. try {
  25. if (process.platform === 'win32' && nativeTheme.shouldUseDarkColors === true) {
  26. require('fs').unlinkSync(require('path').join(app.getPath('userData'), 'DevTools Extensions'))
  27. }
  28. } catch (_) {
  29. }
  30. /**
  31. * Set `__statics` path to static files in production;
  32. * The reason we are setting it here is that the path needs to be evaluated at runtime
  33. */
  34. if (process.env.PROD) {
  35. global.__statics = __dirname
  36. }
  37. let mainWindow
  38. function createWindow () {
  39. /**
  40. * Initial window options
  41. */
  42. mainWindow = new BrowserWindow({
  43. width: 1000,
  44. height: 800,
  45. minWidth: 1000,
  46. frame: false,
  47. webPreferences: {
  48. contextIsolation: false,
  49. // Change from /quasar.conf.js > electron > nodeIntegration;
  50. // More info: https://quasar.dev/quasar-cli/developing-electron-apps/node-integration
  51. nodeIntegration: true,
  52. nodeIntegrationInWorker: process.env.QUASAR_NODE_INTEGRATION,
  53. // More info: /quasar-cli/developing-electron-apps/electron-preload-script
  54. // preload: path.resolve(__dirname, 'electron-preload.js')
  55. }
  56. })
  57. mainWindow.menuBarVisible = false
  58. mainWindow.loadURL(process.env.APP_URL)
  59. mainWindow.on('closed', () => {
  60. mainWindow = null
  61. })
  62. }
  63. app.on('ready', createWindow)
  64. app.on('window-all-closed', () => {
  65. if (process.platform !== 'darwin') {
  66. app.quit()
  67. }
  68. })
  69. app.on('activate', () => {
  70. if (mainWindow === null) {
  71. createWindow()
  72. }
  73. })