- Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathplotter-frontend-contribution.ts
132 lines (121 loc) · 4.06 KB
/
plotter-frontend-contribution.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import{Endpoint}from'@theia/core/lib/browser/endpoint';
import{ThemeService}from'@theia/core/lib/browser/theming';
import{Command,CommandRegistry}from'@theia/core/lib/common/command';
import{DisposableCollection}from'@theia/core/lib/common/disposable';
importtype{MenuModelRegistry}from'@theia/core/lib/common/menu';
import{nls}from'@theia/core/lib/common/nls';
import{inject,injectable}from'@theia/core/shared/inversify';
importqueryStringfrom'query-string';
import{MonitorManagerProxyClient}from'../../../common/protocol';
import{Contribution}from'../../contributions/contribution';
import{ArduinoMenus}from'../../menu/arduino-menus';
import{MonitorModel}from'../../monitor-model';
import{ArduinoToolbar}from'../../toolbar/arduino-toolbar';
exportnamespaceSerialPlotterContribution{
exportnamespaceCommands{
exportconstOPEN: Command=Command.toLocalizedCommand(
{
id: 'serial-plotter-open',
label: 'Serial Plotter',
category: 'Arduino',
},
'arduino/serial/openSerialPlotter'
);
exportconstRESET: Command={
id: 'serial-plotter-reset',
};
exportconstOPEN_TOOLBAR: Command={
id: 'serial-plotter-open-toolbar',
};
}
}
@injectable()
exportclassPlotterFrontendContributionextendsContribution{
privatereadonlyendpointUrl=newEndpoint({path: '/plotter'})
.getRestUrl()
.toString();
privatereadonlytoDispose=newDisposableCollection();
private_plotterUrl: string|undefined;
@inject(MonitorModel)
privatereadonlymodel: MonitorModel;
@inject(ThemeService)
privatereadonlythemeService: ThemeService;
@inject(MonitorManagerProxyClient)
privatereadonlymonitorManagerProxy: MonitorManagerProxyClient;
overrideonStart(): void{
this.toDispose.push(
window.electronArduino.registerPlotterWindowCloseHandler(()=>{
this._plotterUrl=undefined;
})
);
this.monitorManagerProxy.onMonitorShouldReset(()=>this.reset());
}
overrideregisterCommands(registry: CommandRegistry): void{
registry.registerCommand(SerialPlotterContribution.Commands.OPEN,{
execute: ()=>this.startPlotter(),
});
registry.registerCommand(SerialPlotterContribution.Commands.RESET,{
execute: ()=>this.reset(),
});
registry.registerCommand(
{id: SerialPlotterContribution.Commands.OPEN_TOOLBAR.id},
{
isVisible: (widget)=>
ArduinoToolbar.is(widget)&&widget.side==='right',
execute: ()=>this.startPlotter(),
}
);
}
overrideregisterMenus(menus: MenuModelRegistry): void{
menus.registerMenuAction(ArduinoMenus.TOOLS__MAIN_GROUP,{
commandId: SerialPlotterContribution.Commands.OPEN.id,
label: SerialPlotterContribution.Commands.OPEN.label,
order: '7',
});
}
privateasyncstartPlotter(forceReload=false): Promise<void>{
awaitthis.monitorManagerProxy.startMonitor();
if(this._plotterUrl){
window.electronArduino.showPlotterWindow({
url: this._plotterUrl,
forceReload,
});
return;
}
constwsPort=this.monitorManagerProxy.getWebSocketPort();
if(wsPort){
this.open(wsPort);
}else{
this.messageService.error(
nls.localize(
'arduino/contributions/plotter/couldNotOpen',
"Couldn't open serial plotter"
)
);
}
}
privateopen(wsPort: number): void{
constinitConfig={
darkTheme: this.isDarkTheme,
wsPort,
serialPort: this.model.serialPort,
};
this._plotterUrl=queryString.stringifyUrl(
{
url: this.endpointUrl,
query: initConfig,
},
{arrayFormat: 'comma'}
);
window.electronArduino.showPlotterWindow({url: this._plotterUrl});
}
privategetisDarkTheme(): boolean{
constthemeType=this.themeService.getCurrentTheme().type;
returnthemeType==='dark'||themeType==='hc';
}
privateasyncreset(): Promise<void>{
if(this._plotterUrl){
awaitthis.startPlotter(true);
}
}
}