diff --git a/src/main/main.ts b/src/main/main.ts index cd0041e..fd87815 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -10,7 +10,7 @@ */ import path from 'path'; import fs from 'fs'; -import { app, BrowserWindow, shell, globalShortcut, Menu, MenuItemConstructorOptions } from 'electron'; +import { app, BrowserWindow, shell, globalShortcut } from 'electron'; import puppeteer from 'puppeteer-core'; import pie from 'puppeteer-in-electron'; import { spawnSync } from 'child_process'; @@ -22,6 +22,7 @@ import { Code } from './sub/code'; import { Judge } from './sub/judge'; import '@/error/sentry'; +import MenuBuilder from './menu'; let mainWindow: BrowserWindow | null = null; let bojView: BojView | null = null; @@ -84,24 +85,7 @@ const createWindow = async (puppeteerBroswer: Awaited { - app.quit(); - }, - }, - ], - }); - } - - Menu.setApplicationMenu(Menu.buildFromTemplate(menuOptions)); + new MenuBuilder(mainWindow).buildMenu(); mainWindow.on('ready-to-show', () => { if (!mainWindow) { diff --git a/src/main/menu.ts b/src/main/menu.ts index ba0fb77..e6aa1c9 100644 --- a/src/main/menu.ts +++ b/src/main/menu.ts @@ -1,10 +1,4 @@ -import { - app, - Menu, - shell, - BrowserWindow, - MenuItemConstructorOptions, -} from 'electron'; +import { app, Menu, shell, BrowserWindow, MenuItemConstructorOptions } from 'electron'; interface DarwinMenuItemConstructorOptions extends MenuItemConstructorOptions { selector?: string; @@ -19,17 +13,11 @@ export default class MenuBuilder { } buildMenu(): Menu { - if ( - process.env.NODE_ENV === 'development' || - process.env.DEBUG_PROD === 'true' - ) { + if (process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true') { this.setupDevelopmentEnvironment(); } - const template = - process.platform === 'darwin' - ? this.buildDarwinTemplate() - : this.buildDefaultTemplate(); + const template = process.platform === 'darwin' ? this.buildDarwinTemplate() : []; const menu = Menu.buildFromTemplate(template); Menu.setApplicationMenu(menu); @@ -163,9 +151,7 @@ export default class MenuBuilder { { label: 'Documentation', click() { - shell.openExternal( - 'https://github.com/electron/electron/tree/main/docs#readme', - ); + shell.openExternal('https://github.com/electron/electron/tree/main/docs#readme'); }, }, { @@ -184,10 +170,7 @@ export default class MenuBuilder { }; const subMenuView = - process.env.NODE_ENV === 'development' || - process.env.DEBUG_PROD === 'true' - ? subMenuViewDev - : subMenuViewProd; + process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true' ? subMenuViewDev : subMenuViewProd; return [subMenuAbout, subMenuEdit, subMenuView, subMenuWindow, subMenuHelp]; } @@ -213,8 +196,7 @@ export default class MenuBuilder { { label: '&View', submenu: - process.env.NODE_ENV === 'development' || - process.env.DEBUG_PROD === 'true' + process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true' ? [ { label: '&Reload', @@ -227,9 +209,7 @@ export default class MenuBuilder { label: 'Toggle &Full Screen', accelerator: 'F11', click: () => { - this.mainWindow.setFullScreen( - !this.mainWindow.isFullScreen(), - ); + this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen()); }, }, { @@ -245,9 +225,7 @@ export default class MenuBuilder { label: 'Toggle &Full Screen', accelerator: 'F11', click: () => { - this.mainWindow.setFullScreen( - !this.mainWindow.isFullScreen(), - ); + this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen()); }, }, ], @@ -264,9 +242,7 @@ export default class MenuBuilder { { label: 'Documentation', click() { - shell.openExternal( - 'https://github.com/electron/electron/tree/main/docs#readme', - ); + shell.openExternal('https://github.com/electron/electron/tree/main/docs#readme'); }, }, {