refactor: some improvements in app menu

Improved the class structure of menu
and added "Settings" as new menu item
This commit is contained in:
4gray committed 2021-02-27 13:37:43 +01:00
1 parent 83ed4cf442
commit e29f09d18c
3 files changed
+117 -67

No files matched your search

+2 -2
View File
@@ -94,8 +94,8 @@ try {
app.on('ready', () => {
// create main window and set menu
const win = createWindow();
const menu = AppMenu.createMenu(win);
Menu.setApplicationMenu(menu);
const menu = new AppMenu(win);
Menu.setApplicationMenu(menu.getMenu());
api.setMainWindow(win);
// create hidden window for epg worker
+106 -65
View File
@@ -3,80 +3,121 @@ import * as path from 'path';
const openAboutWindow = require('about-window').default;
export class AppMenu {
/** Application menu */
menu: Menu = new Menu();
/** Application window */
window: BrowserWindow;
constructor(appWindow: BrowserWindow) {
this.window = appWindow;
this.initMenu();
}
/**
* Creates context menu
* @param win browser window object
*/
static createMenu(win: BrowserWindow): Menu {
const menu = new Menu();
menu.append(
new MenuItem({
label: 'File',
submenu: [
{
label: 'Add playlist',
click: () => win.webContents.send('add-playlist-view'),
},
{
type: 'separator',
},
{
label: 'Exit',
click: () => app.quit(),
},
],
})
);
initMenu(): void {
this.menu.append(this.getFileMenu());
// copy-paste shortcuts workaround for mac os
if (process.platform === 'darwin') {
menu.append(
new MenuItem({
label: 'Edit',
submenu: [
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'delete' },
],
})
);
this.menu.append(this.getEditMenu());
}
menu.append(
new MenuItem({
label: 'Help',
submenu: [
{
label: 'Report a bug',
click: () =>
shell.openExternal(
'https://github.com/4gray/iptvnator'
),
},
{
label: 'Open DevTools',
click: () => win.webContents.openDevTools(),
},
{
type: 'separator',
},
{
label: 'About',
click: () =>
openAboutWindow({
icon_path: path.join(
__dirname,
'dist/assets/icons/icon.png'
),
copyright: 'Copyright (c) 2020 4gray',
package_json_dir: __dirname,
}),
},
],
})
);
this.menu.append(this.getHelpMenu());
}
return menu;
/**
* Return the application menu
*/
getMenu(): Menu {
return this.menu;
}
/**
* Creates and returns the file menu
* @param win application window
*/
private getFileMenu(): MenuItem {
return new MenuItem({
label: 'File',
submenu: [
{
label: 'Add playlist',
click: () =>
this.window.webContents.send('add-playlist-view'),
},
{
type: 'separator',
},
{
label: 'Settings',
click: () => this.window.webContents.send('settings-view'),
},
{
type: 'separator',
},
{
label: 'Exit',
click: () => app.quit(),
},
],
});
}
/**
* Creates and returns the edit menu
* @param win application window
*/
private getHelpMenu(): MenuItem {
return new MenuItem({
label: 'Help',
submenu: [
{
label: 'Report a bug',
click: () =>
shell.openExternal(
'https://github.com/4gray/iptvnator'
),
},
{
label: 'Open DevTools',
click: () => this.window.webContents.openDevTools(),
},
{
type: 'separator',
},
{
label: 'About',
click: () =>
openAboutWindow({
icon_path: path.join(
__dirname,
'dist/assets/icons/icon.png'
),
copyright: 'Copyright (c) 2020-2021 4gray',
package_json_dir: __dirname,
}),
},
],
});
}
/**
* Creates and returns the help menu
* @param win application window
*/
private getEditMenu(): MenuItem {
return new MenuItem({
label: 'Edit',
submenu: [
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'delete' },
],
});
}
}
+9
View File
@@ -53,6 +53,14 @@ export class AppComponent {
});
});
this.electronService.ipcRenderer.on('settings-view', () => {
this.ngZone.run(() => {
this.router.navigateByUrl('/settings', {
skipLocationChange: true,
});
});
});
this.electronService.ipcRenderer.on(EPG_FETCH_DONE, () => {
this.ngZone.run(() => {
this.channelStore.setEpgAvailableFlag(true);
@@ -120,5 +128,6 @@ export class AppComponent {
this.electronService.ipcRenderer.removeAllListeners(
'add-playlist-view'
);
this.electronService.ipcRenderer.removeAllListeners('settings-view');
}
}