-
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathabout.ts
74 lines (63 loc) · 2.66 KB
/
about.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { inject, injectable } from 'inversify';
import { remote } from 'electron';
import { isOSX, isWindows } from '@theia/core/lib/common/os';
import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
import { Contribution, Command, MenuModelRegistry, CommandRegistry } from './contribution';
import { ArduinoMenus } from '../menu/arduino-menus';
import { ConfigService } from '../../common/protocol';
@injectable()
export class About extends Contribution {
@inject(ClipboardService)
protected readonly clipboardService: ClipboardService;
@inject(ConfigService)
protected readonly configService: ConfigService;
registerCommands(registry: CommandRegistry): void {
registry.registerCommand(About.Commands.ABOUT_APP, {
execute: () => this.showAbout()
});
}
registerMenus(registry: MenuModelRegistry): void {
// On macOS we will get the `Quit ${YOUR_APP_NAME}` menu item natively, no need to duplicate it.
registry.registerMenuAction(ArduinoMenus.HELP__ABOUT_GROUP, {
commandId: About.Commands.ABOUT_APP.id,
label: `About${isOSX ? ` ${this.applicationName}` : ''}`,
order: '0'
});
}
async showAbout(): Promise<void> {
const ideStatus = FrontendApplicationConfigProvider.get()['status'];
const { version, commit, status: cliStatus } = await this.configService.getVersion();
const detail = `
Version: ${remote.app.getVersion()}
CLI Version: ${version}${cliStatus ? ` ${cliStatus}` : ''} [${commit}]
Copyright © ${new Date().getFullYear()} Arduino SA
`;
const ok = 'OK';
const copy = 'Copy';
const buttons = !isWindows && !isOSX ? [copy, ok] : [ok, copy];
const { response } = await remote.dialog.showMessageBox(remote.getCurrentWindow(), {
message: `${this.applicationName}${ideStatus ? ` – ${ideStatus}` : ''}`,
title: `${this.applicationName}${ideStatus ? ` – ${ideStatus}` : ''}`,
type: 'info',
detail,
buttons,
noLink: true,
defaultId: buttons.indexOf(ok),
cancelId: buttons.indexOf(ok)
});
if (buttons[response] === copy) {
await this.clipboardService.writeText(detail);
}
}
protected get applicationName(): string {
return FrontendApplicationConfigProvider.get().applicationName;
}
}
export namespace About {
export namespace Commands {
export const ABOUT_APP: Command = {
id: 'arduino-about'
};
}
}