Skip to content
This repository was archived by the owner on Jul 15, 2022. It is now read-only.

Commit 844efb2

Browse files
author
Leonardo Chaia
committed
feat: added application menu
1 parent 63ff70e commit 844efb2

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

src/app/app-menu/app-menu.module.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { ElectronToolsModule } from '../electron-tools/electron-tools.module';
4+
import { TabsModule } from '../tabs/tabs.module';
5+
6+
@NgModule({
7+
imports: [
8+
CommonModule,
9+
10+
ElectronToolsModule,
11+
TabsModule,
12+
],
13+
declarations: []
14+
})
15+
export class AppMenuModule { }

src/app/app-menu/app-menu.service.ts

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { Injectable, NgZone } from '@angular/core';
2+
import { ElectronService } from '../electron-tools/electron.service';
3+
import { MenuItemConstructorOptions } from 'electron';
4+
import { environment } from '../../environments/environment';
5+
import { TabService } from '../tabs/tab.service';
6+
import { TimoneerTabs } from '../timoneer-tabs';
7+
8+
@Injectable({
9+
providedIn: 'root'
10+
})
11+
export class AppMenuService {
12+
13+
constructor(private electronService: ElectronService,
14+
private ngZone: NgZone,
15+
private tabService: TabService) { }
16+
17+
public loadMenu() {
18+
const { Menu } = this.electronService.remote;
19+
20+
const template: MenuItemConstructorOptions[] = [
21+
{
22+
label: 'File',
23+
submenu: [
24+
{ role: 'reload', accelerator: '' },
25+
{ role: 'close', accelerator: '' },
26+
]
27+
},
28+
{
29+
label: 'Edit',
30+
submenu: [
31+
{
32+
label: 'Settings',
33+
click: () => {
34+
this.openTab(TimoneerTabs.SETTINGS);
35+
}
36+
}
37+
]
38+
},
39+
{
40+
label: 'Docker',
41+
submenu: [
42+
{
43+
label: 'Images',
44+
click: () => {
45+
this.openTab(TimoneerTabs.DOCKER_IMAGES);
46+
}
47+
},
48+
{
49+
label: 'Volumes',
50+
click: () => {
51+
this.openTab(TimoneerTabs.DOCKER_VOLUMES);
52+
}
53+
},
54+
{
55+
label: 'System',
56+
click: () => {
57+
this.openTab(TimoneerTabs.DOCKER_SYSTEM);
58+
}
59+
},
60+
]
61+
},
62+
{
63+
label: 'Window',
64+
submenu: [
65+
{ role: 'togglefullscreen' },
66+
]
67+
},
68+
{
69+
label: 'Help',
70+
submenu: [
71+
{
72+
label: 'Learn More',
73+
click: () => {
74+
const shell = this.electronService.remote.shell;
75+
shell.openExternal('https://github.com/leonardochaia/timoneer');
76+
}
77+
}
78+
]
79+
}
80+
];
81+
82+
if (!environment.production) {
83+
template.push({
84+
label: 'Development',
85+
submenu: [
86+
{ role: 'reload' },
87+
{ role: 'forcereload' },
88+
{ role: 'toggledevtools' },
89+
]
90+
});
91+
}
92+
93+
const menu = Menu.buildFromTemplate(template);
94+
Menu.setApplicationMenu(menu);
95+
}
96+
97+
private openTab(tab: string) {
98+
this.ngZone.run(() => {
99+
this.tabService.add(tab);
100+
});
101+
}
102+
}

src/app/app.module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ApplicationTemplatesModule } from './application-templates/application-
1111
import { HotkeyModule } from 'angular2-hotkeys';
1212
import { AppTabsModule } from './app-tabs.module';
1313
import { GlobalShortcutsModule } from './global-shortcuts.module';
14+
import { AppMenuModule } from './app-menu/app-menu.module';
1415

1516
@NgModule({
1617
imports: [
@@ -19,6 +20,7 @@ import { GlobalShortcutsModule } from './global-shortcuts.module';
1920
HotkeyModule.forRoot(),
2021

2122
AppTabsModule,
23+
AppMenuModule,
2224
GlobalShortcutsModule,
2325

2426
HomeModule,

0 commit comments

Comments
 (0)