Skip to content

Commit

Permalink
chore: erb default menu 설정 사용하도록 설정 (Mac의 경우에만)
Browse files Browse the repository at this point in the history
  • Loading branch information
junghyunbak committed Dec 11, 2024
1 parent e3b94ba commit e3cb196
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 52 deletions.
22 changes: 3 additions & 19 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -84,24 +85,7 @@ const createWindow = async (puppeteerBroswer: Awaited<ReturnType<typeof pie.conn

mainWindow.loadURL(resolveHtmlPath('index.html'));

const menuOptions: MenuItemConstructorOptions[] = [];

if (process.platform === 'darwin') {
menuOptions.push({
label: 'BOJ IDE',
submenu: [
{
label: 'Quit',
accelerator: 'Command+Q',
click: () => {
app.quit();
},
},
],
});
}

Menu.setApplicationMenu(Menu.buildFromTemplate(menuOptions));
new MenuBuilder(mainWindow).buildMenu();

mainWindow.on('ready-to-show', () => {
if (!mainWindow) {
Expand Down
42 changes: 9 additions & 33 deletions src/main/menu.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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');
},
},
{
Expand All @@ -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];
}
Expand All @@ -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',
Expand All @@ -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());
},
},
{
Expand All @@ -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());
},
},
],
Expand All @@ -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');
},
},
{
Expand Down

0 comments on commit e3cb196

Please sign in to comment.