Skip to content

Commit

Permalink
Retrieve values from PreferenceService as required
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Grant <colin.grant@ericsson.com>
  • Loading branch information
colin-grant-work authored and MatthewKhouzam committed Jun 29, 2021
1 parent 8be47f8 commit ad82d36
Showing 1 changed file with 10 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { injectable, inject, postConstruct } from 'inversify';
import { injectable, inject } from 'inversify';
import { CommandRegistry, CommandContribution, MessageService } from '@theia/core';
import { WidgetOpenerOptions, WidgetOpenHandler } from '@theia/core/lib/browser';
import URI from '@theia/core/lib/common/uri';
Expand All @@ -22,8 +22,6 @@ interface TraceViewerWidgetOpenerOptions extends WidgetOpenerOptions {
export class TraceViewerContribution extends WidgetOpenHandler<TraceViewerWidget> implements CommandContribution {

private tspClient: TspClient;
protected path: string | undefined;
protected port: number | undefined;

private constructor(
@inject(TspClientProvider) private tspClientProvider: TspClientProvider
Expand All @@ -44,21 +42,12 @@ export class TraceViewerContribution extends WidgetOpenHandler<TraceViewerWidget
readonly id = TraceViewerWidget.ID;
readonly label = 'Trace Viewer';

@postConstruct()
init(): void {

this.preferenceService.onPreferenceChanged(event => {
if (event.preferenceName === TRACE_PORT) {
this.port = event.newValue;
}
if (event.preferenceName === TRACE_PATH) {
this.path = event.newValue;
}
});

this.path = this.preferenceService.get(TRACE_PATH);
this.port = this.preferenceService.get(TRACE_PORT);
protected get path(): string | undefined {
return this.preferenceService.get(TRACE_PATH);
}

protected get port(): number | undefined {
return this.preferenceService.get(TRACE_PORT);
}

protected createWidgetOptions(uri: URI, options?: TraceViewerWidgetOpenerOptions): TraceViewerWidgetOptions {
Expand Down Expand Up @@ -94,11 +83,12 @@ export class TraceViewerContribution extends WidgetOpenHandler<TraceViewerWidget
this.messageService.showProgress({
text: ''
}).then(async progress => {
const { path, port } = this;
progress.report({ message: 'Launching trace server... ', work: { done: 10, total: 100 } });
try {
const resolve = await this.traceServerConfigService.startTraceServer(this.path, this.port);
const resolve = await this.traceServerConfigService.startTraceServer(path, port);
if (resolve === 'success') {
progress.report({ message: `Trace server started on port: ${this.port}.`, work: { done: 100, total: 100 } });
progress.report({ message: `Trace server started on port: ${port}.`, work: { done: 100, total: 100 } });
progress.cancel();
const widget = super.open(traceURI, traceUUID);
return widget;
Expand All @@ -107,7 +97,7 @@ export class TraceViewerContribution extends WidgetOpenHandler<TraceViewerWidget
catch (err) {
if (PortBusy.is(err)) {
this.messageService.error(
`Error opening serial port ${this.port}. (Port busy)`);
`Error opening serial port ${port}. (Port busy)`);
} else {
this.messageService.error(
'Failed to start the trace server: no such file or directory. Please make sure that the path is correct in Trace Viewer settings and retry');
Expand Down

0 comments on commit ad82d36

Please sign in to comment.