electron launcher
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.6 KiB

4 years ago
  1. const { app, BrowserWindow, dialog, protocol } = require('electron')
  2. const { create: createMainWindow } = require('./windows/main')
  3. const { MANUAL_CREATED_FLAG } = require('./constant')
  4. const handleIPC = require('./ipc')
  5. app.commandLine.appendSwitch("--disable-http-cache");
  6. app.whenReady().then(() => {
  7. protocol.registerFileProtocol('file', (request, callback) => {
  8. const pathname = decodeURI(request.url.replace('file:///', ''));
  9. callback(pathname);
  10. });
  11. handleIPC();
  12. createMainWindow()
  13. app.on('browser-window-created', (event, window) => {
  14. setTimeout(() => {
  15. if (window[MANUAL_CREATED_FLAG]) { // allow safe created manually
  16. return
  17. }
  18. dialog.showMessageBox({
  19. type: "warning",
  20. title: "提示",
  21. message: "新开窗口必须使用内置openWindow接口",
  22. })
  23. try {
  24. window.destroy()
  25. } catch (e) {
  26. console.error(e)
  27. }
  28. }, 100)
  29. })
  30. app.on('activate', () => {
  31. // On macOS it's common to re-create a window in the app when the
  32. // dock icon is clicked and there are no other windows open.
  33. if (BrowserWindow.getAllWindows().length === 0) {
  34. createMainWindow()
  35. }
  36. })
  37. })
  38. // Quit when all windows are closed, except on macOS. There, it's common
  39. // for applications and their menu bar to stay active until the user quits
  40. // explicitly with Cmd + Q.
  41. app.on('window-all-closed', function () {
  42. if (process.platform !== 'darwin') app.quit()
  43. })