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 2d8267d

Browse files
author
Akos Kitta
committed
feat: configure sketchbook location without restart
Closes #1764 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 1d342cd commit 2d8267d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+827
-470
lines changed

‎arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
SketchesService,
2424
SketchesServicePath,
2525
} from '../common/protocol/sketches-service';
26-
import { SketchesServiceClientImpl } from '../common/protocol/sketches-service-client-impl';
26+
import { SketchesServiceClientImpl } from './sketches-service-client-impl';
2727
import { CoreService, CoreServicePath } from '../common/protocol/core-service';
2828
import { BoardsListWidget } from './boards/boards-list-widget';
2929
import { BoardsListWidgetFrontendContribution } from './boards/boards-widget-frontend-contribution';
@@ -343,6 +343,7 @@ import { DebugWidget } from '@theia/debug/lib/browser/view/debug-widget';
343343
import { DebugViewModel } from '@theia/debug/lib/browser/view/debug-view-model';
344344
import { DebugSessionWidget } from '@theia/debug/lib/browser/view/debug-session-widget';
345345
import { DebugConfigurationWidget } from '@theia/debug/lib/browser/view/debug-configuration-widget';
346+
import { ConfigServiceClient } from './config/config-service-client';
346347

347348
export default new ContainerModule((bind, unbind, isBound, rebind) => {
348349
// Commands and toolbar items
@@ -404,6 +405,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
404405
)
405406
)
406407
.inSingletonScope();
408+
bind(ConfigServiceClient).toSelf().inSingletonScope();
409+
bind(FrontendApplicationContribution).toService(ConfigServiceClient);
407410

408411
// Boards service
409412
bind(BoardsService)
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application';
2+
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
3+
import { DisposableCollection } from '@theia/core/lib/common/disposable';
4+
import { Emitter, Event } from '@theia/core/lib/common/event';
5+
import { MessageService } from '@theia/core/lib/common/message-service';
6+
import { Deferred } from '@theia/core/lib/common/promise-util';
7+
import URI from '@theia/core/lib/common/uri';
8+
import { inject, injectable } from '@theia/core/shared/inversify';
9+
import { Config, ConfigService, ConfigState } from '../../common/protocol';
10+
import { NotificationCenter } from '../notification-center';
11+
12+
@injectable()
13+
export class ConfigServiceClient implements FrontendApplicationContribution {
14+
@inject(ConfigService)
15+
private readonly delegate: ConfigService;
16+
@inject(NotificationCenter)
17+
private readonly notificationCenter: NotificationCenter;
18+
@inject(FrontendApplicationStateService)
19+
private readonly appStateService: FrontendApplicationStateService;
20+
@inject(MessageService)
21+
private readonly messageService: MessageService;
22+
23+
private readonly didChangeSketchDirUriEmitter = new Emitter<
24+
URI | undefined
25+
>();
26+
private readonly didChangeDataDirUriEmitter = new Emitter<URI | undefined>();
27+
private readonly toDispose = new DisposableCollection(
28+
this.didChangeSketchDirUriEmitter,
29+
this.didChangeDataDirUriEmitter
30+
);
31+
32+
private configFileUri: Deferred<URI> | undefined;
33+
private _config: ConfigState | undefined;
34+
private _dataDirUri: string | undefined;
35+
private _sketchDirUri: string | undefined;
36+
37+
onStart(): void {
38+
this.appStateService.reachedState('ready').then(async () => {
39+
const config = await this.fetchConfig();
40+
this.use(config);
41+
});
42+
this.notificationCenter.onConfigDidChange((config) => this.use(config));
43+
}
44+
45+
onStop(): void {
46+
this.toDispose.dispose();
47+
}
48+
49+
get onDidChangeSketchDirUri(): Event<URI | undefined> {
50+
return this.didChangeSketchDirUriEmitter.event;
51+
}
52+
53+
get onDidChangeDataDirUri(): Event<URI | undefined> {
54+
return this.didChangeSketchDirUriEmitter.event;
55+
}
56+
57+
async getCliConfigFileUri(): Promise<URI> {
58+
if (!this.configFileUri) {
59+
this.configFileUri = new Deferred();
60+
setTimeout(async () => {
61+
try {
62+
const uri = await this.delegate.configFileUri();
63+
this.configFileUri?.resolve(new URI(uri));
64+
} catch (err) {
65+
console.error(
66+
`Could not retrieve the URI of the CLI configuration file`,
67+
err
68+
);
69+
this.configFileUri?.reject(err);
70+
this.configFileUri = undefined;
71+
}
72+
});
73+
}
74+
return this.configFileUri.promise;
75+
}
76+
77+
async fetchConfig(): Promise<ConfigState> {
78+
return this.delegate.config();
79+
}
80+
81+
tryGetConfig(): Config | undefined {
82+
return this._config?.config;
83+
}
84+
85+
tryGetMessages(): string[] | undefined {
86+
return this._config?.messages;
87+
}
88+
89+
/**
90+
* `directories.user`
91+
*/
92+
tryGetSketchDirUri(): URI | undefined {
93+
return this._sketchDirUri ? new URI(this._sketchDirUri) : undefined;
94+
}
95+
96+
/**
97+
* `directories.data`
98+
*/
99+
tryGetDataDirUri(): URI | undefined {
100+
return this._dataDirUri ? new URI(this._dataDirUri) : undefined;
101+
}
102+
103+
private use(config: ConfigState): void {
104+
this._config = config;
105+
if (this._dataDirUri !== this._config?.config?.dataDirUri) {
106+
this._dataDirUri = this._config?.config?.dataDirUri;
107+
this.didChangeDataDirUriEmitter.fire(
108+
this._dataDirUri ? new URI(this._dataDirUri) : undefined
109+
);
110+
}
111+
if (this._sketchDirUri !== this._config?.config?.sketchDirUri) {
112+
this._sketchDirUri = this._config?.config?.sketchDirUri;
113+
this.didChangeSketchDirUriEmitter.fire(
114+
this._sketchDirUri ? new URI(this._sketchDirUri) : undefined
115+
);
116+
}
117+
if (this._config.messages?.length) {
118+
this.messageService.error(this._config.messages.join(' '));
119+
}
120+
}
121+
}

‎arduino-ide-extension/src/browser/contributions/add-file.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from './contribution';
1111
import { FileDialogService } from '@theia/filesystem/lib/browser';
1212
import { nls } from '@theia/core/lib/common';
13-
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
13+
import { CurrentSketch } from '../sketches-service-client-impl';
1414

1515
@injectable()
1616
export class AddFile extends SketchContribution {

‎arduino-ide-extension/src/browser/contributions/archive-sketch.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
MenuModelRegistry,
1111
} from './contribution';
1212
import { nls } from '@theia/core/lib/common';
13-
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
13+
import { CurrentSketch } from '../sketches-service-client-impl';
1414

1515
@injectable()
1616
export class ArchiveSketch extends SketchContribution {
@@ -29,10 +29,12 @@ export class ArchiveSketch extends SketchContribution {
2929
}
3030

3131
private async archiveSketch(): Promise<void> {
32-
const [sketch, config] = await Promise.all([
33-
this.sketchServiceClient.currentSketch(),
34-
this.configService.getConfiguration(),
35-
]);
32+
const config = this.configService.tryGetConfig();
33+
if (!config) {
34+
return;
35+
}
36+
const sketch = await this.sketchServiceClient.currentSketch();
37+
3638
if (!CurrentSketch.isValid(sketch)) {
3739
return;
3840
}

‎arduino-ide-extension/src/browser/contributions/board-selection.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,7 @@ PID: ${PID}`;
155155
);
156156

157157
// Ports submenu
158-
const portsSubmenuPath = [
159-
...ArduinoMenus.TOOLS__BOARD_SELECTION_GROUP,
160-
'2_ports',
161-
];
158+
const portsSubmenuPath = ArduinoMenus.PORTS_SUBMENU;
162159
const portsSubmenuLabel = config.selectedPort?.address;
163160
this.menuModelRegistry.registerSubmenu(
164161
portsSubmenuPath,

‎arduino-ide-extension/src/browser/contributions/close.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
URI,
2121
} from './contribution';
2222
import { Dialog } from '@theia/core/lib/browser/dialogs';
23-
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
23+
import { CurrentSketch } from '../sketches-service-client-impl';
2424
import { SaveAsSketch } from './save-as-sketch';
2525

2626
/**

‎arduino-ide-extension/src/browser/contributions/contribution.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ import { SettingsService } from '../dialogs/settings/settings';
4040
import {
4141
CurrentSketch,
4242
SketchesServiceClientImpl,
43-
} from '../../common/protocol/sketches-service-client-impl';
43+
} from '../sketches-service-client-impl';
4444
import {
4545
SketchesService,
46-
ConfigService,
4746
FileSystemExt,
4847
Sketch,
4948
CoreService,
@@ -62,6 +61,7 @@ import { NotificationManager } from '../theia/messages/notifications-manager';
6261
import { MessageType } from '@theia/core/lib/common/message-service-protocol';
6362
import { WorkspaceService } from '../theia/workspace/workspace-service';
6463
import { MainMenuManager } from '../../common/main-menu-manager';
64+
import { ConfigServiceClient } from '../config/config-service-client';
6565

6666
export {
6767
Command,
@@ -142,8 +142,8 @@ export abstract class SketchContribution extends Contribution {
142142
@inject(FileSystemExt)
143143
protected readonly fileSystemExt: FileSystemExt;
144144

145-
@inject(ConfigService)
146-
protected readonly configService: ConfigService;
145+
@inject(ConfigServiceClient)
146+
protected readonly configService: ConfigServiceClient;
147147

148148
@inject(SketchesService)
149149
protected readonly sketchService: SketchesService;

‎arduino-ide-extension/src/browser/contributions/debug.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
TabBarToolbarRegistry,
1414
} from './contribution';
1515
import { MaybePromise, MenuModelRegistry, nls } from '@theia/core/lib/common';
16-
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
16+
import { CurrentSketch } from '../sketches-service-client-impl';
1717
import { ArduinoMenus } from '../menu/arduino-menus';
1818

1919
import { MainMenuManager } from '../../common/main-menu-manager';

‎arduino-ide-extension/src/browser/contributions/examples.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export abstract class Examples extends SketchContribution {
3636
private readonly commandRegistry: CommandRegistry;
3737

3838
@inject(MenuModelRegistry)
39-
private readonly menuRegistry: MenuModelRegistry;
39+
protected readonly menuRegistry: MenuModelRegistry;
4040

4141
@inject(ExamplesService)
4242
protected readonly examplesService: ExamplesService;

‎arduino-ide-extension/src/browser/contributions/include-library.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { SketchContribution, Command, CommandRegistry } from './contribution';
1717
import { NotificationCenter } from '../notification-center';
1818
import { nls } from '@theia/core/lib/common';
1919
import * as monaco from '@theia/monaco-editor-core';
20-
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
20+
import { CurrentSketch } from '../sketches-service-client-impl';
2121

2222
@injectable()
2323
export class IncludeLibrary extends SketchContribution {

0 commit comments

Comments
(0)

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