Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2c1d125

Browse files
author
Akos Kitta
committed
feat: show cloud prefix in window title
Closes #1878 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 512dad5 commit 2c1d125

File tree

2 files changed

+68
-5
lines changed

2 files changed

+68
-5
lines changed

‎arduino-ide-extension/src/browser/theia/core/window-title-updater.ts‎

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1+
import { nls } from '@theia/core';
12
import * as remote from '@theia/core/electron-shared/@electron/remote';
3+
import { FrontendApplication } from '@theia/core/lib/browser/frontend-application';
24
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
35
import { NavigatableWidget } from '@theia/core/lib/browser/navigatable-types';
46
import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell';
57
import { Widget } from '@theia/core/lib/browser/widgets/widget';
68
import { WindowTitleUpdater as TheiaWindowTitleUpdater } from '@theia/core/lib/browser/window/window-title-updater';
79
import { ApplicationServer } from '@theia/core/lib/common/application-protocol';
10+
import { DisposableCollection } from '@theia/core/lib/common/disposable';
811
import { isOSX } from '@theia/core/lib/common/os';
912
import {
1013
inject,
1114
injectable,
1215
postConstruct,
1316
} from '@theia/core/shared/inversify';
17+
import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
1418
import { EditorWidget } from '@theia/editor/lib/browser/editor-widget';
1519
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
20+
import { ConfigServiceClient } from '../../config/config-service-client';
21+
import { CreateFeatures } from '../../create/create-features';
22+
import {
23+
CurrentSketch,
24+
SketchesServiceClientImpl,
25+
} from '../../sketches-service-client-impl';
1626

1727
@injectable()
1828
export class WindowTitleUpdater extends TheiaWindowTitleUpdater {
@@ -22,12 +32,22 @@ export class WindowTitleUpdater extends TheiaWindowTitleUpdater {
2232
private readonly applicationShell: ApplicationShell;
2333
@inject(WorkspaceService)
2434
private readonly workspaceService: WorkspaceService;
25-
26-
private _previousRepresentedFilename: string | undefined;
35+
@inject(SketchesServiceClientImpl)
36+
private readonly sketchesServiceClient: SketchesServiceClientImpl;
37+
@inject(ConfigServiceClient)
38+
private readonly configServiceClient: ConfigServiceClient;
39+
@inject(CreateFeatures)
40+
private readonly createFeatures: CreateFeatures;
41+
@inject(EditorManager)
42+
private readonly editorManager: EditorManager;
2743

2844
private readonly applicationName =
2945
FrontendApplicationConfigProvider.get().applicationName;
46+
private readonly toDispose = new DisposableCollection();
47+
48+
private previousRepresentedFilename: string | undefined;
3049
private applicationVersion: string | undefined;
50+
private hasCloudPrefix: boolean | undefined;
3151

3252
@postConstruct()
3353
protected init(): void {
@@ -43,6 +63,18 @@ export class WindowTitleUpdater extends TheiaWindowTitleUpdater {
4363
);
4464
}
4565

66+
override onStart(app: FrontendApplication): void {
67+
super.onStart(app);
68+
this.toDispose.pushAll([
69+
this.sketchesServiceClient.onCurrentSketchDidChange(() =>
70+
this.maybeSetCloudPrefix()
71+
),
72+
this.configServiceClient.onDidChangeDataDirUri(() =>
73+
this.maybeSetCloudPrefix()
74+
),
75+
]);
76+
}
77+
4678
protected override handleWidgetChange(widget?: Widget | undefined): void {
4779
if (isOSX) {
4880
this.maybeUpdateRepresentedFilename(widget);
@@ -54,7 +86,7 @@ export class WindowTitleUpdater extends TheiaWindowTitleUpdater {
5486

5587
protected override updateTitleWidget(widget?: Widget | undefined): void {
5688
let activeEditorShort = '';
57-
const rootName = this.workspaceService.workspace?.name ?? '';
89+
let rootName = this.workspaceService.workspace?.name ?? '';
5890
let appName = `${this.applicationName}${
5991
this.applicationVersion ? ` ${this.applicationVersion}` : ''
6092
}`;
@@ -69,6 +101,12 @@ export class WindowTitleUpdater extends TheiaWindowTitleUpdater {
69101
activeEditorShort = ` - ${base} `;
70102
}
71103
}
104+
if (this.hasCloudPrefix) {
105+
rootName = `[${nls.localize(
106+
'arduino/title/cloud',
107+
'Cloud'
108+
)}] ${rootName}`;
109+
}
72110
this.windowTitleService.update({ rootName, appName, activeEditorShort });
73111
}
74112

@@ -77,10 +115,32 @@ export class WindowTitleUpdater extends TheiaWindowTitleUpdater {
77115
const { uri } = widget.editor;
78116
const filename = uri.path.toString();
79117
// Do not necessarily require the current window if not needed. It's a synchronous, blocking call.
80-
if (this._previousRepresentedFilename !== filename) {
118+
if (this.previousRepresentedFilename !== filename) {
81119
const currentWindow = remote.getCurrentWindow();
82120
currentWindow.setRepresentedFilename(uri.path.toString());
83-
this._previousRepresentedFilename = filename;
121+
this.previousRepresentedFilename = filename;
122+
}
123+
}
124+
}
125+
126+
private maybeSetCloudPrefix(): void {
127+
if (typeof this.hasCloudPrefix === 'boolean') {
128+
return;
129+
}
130+
const sketch = this.sketchesServiceClient.tryGetCurrentSketch();
131+
if (!CurrentSketch.isValid(sketch)) {
132+
return;
133+
}
134+
const dataDirUri = this.configServiceClient.tryGetDataDirUri();
135+
if (!dataDirUri) {
136+
return;
137+
}
138+
this.hasCloudPrefix = this.createFeatures.isCloud(sketch, dataDirUri);
139+
if (typeof this.hasCloudPrefix === 'boolean') {
140+
const editor =
141+
this.editorManager.activeEditor ?? this.editorManager.currentEditor;
142+
if (editor) {
143+
this.updateTitleWidget(editor);
84144
}
85145
}
86146
}

‎i18n/en.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@
460460
"dismissSurvey": "Don't show again",
461461
"surveyMessage": "Please help us improve by answering this super short survey. We value our community and would like to get to know our supporters a little better."
462462
},
463+
"title": {
464+
"cloud": "Cloud"
465+
},
463466
"updateIndexes": {
464467
"updateIndexes": "Update Indexes",
465468
"updateLibraryIndex": "Update Library Index",

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /