From 4f73527eff4b1043ad7524c10c94f8dd492c0b1d Mon Sep 17 00:00:00 2001 From: BenShelton Date: Fri, 7 May 2021 12:55:34 +0100 Subject: [PATCH] feat(media): add custom menu, refactor events into separate module --- packages/media/app/main/src/events.ts | 17 +++++++++++++++++ packages/media/app/main/src/index.ts | 22 +++++++++------------- packages/media/app/main/src/menu.ts | 17 +++++++++++++++++ 3 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 packages/media/app/main/src/events.ts create mode 100644 packages/media/app/main/src/menu.ts diff --git a/packages/media/app/main/src/events.ts b/packages/media/app/main/src/events.ts new file mode 100644 index 0000000..ce6e875 --- /dev/null +++ b/packages/media/app/main/src/events.ts @@ -0,0 +1,17 @@ +import { app } from 'electron' + +import { refocusWindows } from './window' + +export function initEvents (): void { + app.on('activate', async () => { + await refocusWindows() + }) + + app.on('second-instance', async () => { + await refocusWindows() + }) + + app.on('window-all-closed', () => { + app.quit() + }) +} diff --git a/packages/media/app/main/src/index.ts b/packages/media/app/main/src/index.ts index 0e43291..d58d387 100644 --- a/packages/media/app/main/src/index.ts +++ b/packages/media/app/main/src/index.ts @@ -1,27 +1,21 @@ import { app } from 'electron' import { createDir } from '@library-api/core' +import { initEvents } from './events' import { initIPC } from './ipc' -import { createWindows, refocusWindows } from './window' +import { initMenu } from './menu' +import { createWindows } from './window' import { DOWNLOAD_DIR, VIDEO_DIR } from './constants' if (!app.requestSingleInstanceLock()) { app.quit() } -app.on('activate', async () => { - await refocusWindows() -}) +(async () => { + // configure app + initMenu() + initEvents() -app.on('second-instance', async () => { - await refocusWindows() -}) - -app.on('window-all-closed', () => { - app.quit() -}) - -;(async () => { // setup system files await createDir(DOWNLOAD_DIR) await createDir(VIDEO_DIR) @@ -29,5 +23,7 @@ app.on('window-all-closed', () => { // setup everything else await app.whenReady() initIPC() + + // start app await createWindows() })() diff --git a/packages/media/app/main/src/menu.ts b/packages/media/app/main/src/menu.ts new file mode 100644 index 0000000..b03a713 --- /dev/null +++ b/packages/media/app/main/src/menu.ts @@ -0,0 +1,17 @@ +import { Menu } from 'electron' +import { MenuItemConstructorOptions } from 'electron/main' + +const appName = 'Library Media' +const template: MenuItemConstructorOptions[] = [ + { + label: appName, + submenu: [ + { role: 'quit', label: `Quit ${appName}` } + ] + } +] + +export function initMenu (): void { + const menu = Menu.buildFromTemplate(template) + Menu.setApplicationMenu(menu) +}