Skip to content

Commit d809daa

Browse files
committed
Use sketch folder as workspace
Signed-off-by: jbicker <jan.bicker@typefox.io>
1 parent f9641a3 commit d809daa

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,16 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
133133

134134
@inject(LabelProvider)
135135
protected readonly labelProvider: LabelProvider;
136-
136+
137137
@inject(QuickOpenService)
138138
protected readonly quickOpenService: QuickOpenService;
139139

140+
@inject(WorkspaceService)
141+
protected readonly workspaceService: WorkspaceService;
142+
140143
protected boardsToolbarItem: BoardsToolBarItem | null;
141144
protected wsSketchCount: number = 0;
142145

143-
constructor(@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService) {
144-
this.workspaceService.onWorkspaceChanged(() => {
145-
if (this.workspaceService.workspace) {
146-
this.registerSketchesInMenu(this.menuRegistry);
147-
}
148-
})
149-
}
150-
151146
@postConstruct()
152147
protected async init(): Promise<void> {
153148
// This is a hack. Otherwise, the backend services won't bind.
@@ -161,6 +156,8 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
161156
}
162157
this.boardsServiceClient.onBoardsConfigChanged(updateStatusBar);
163158
updateStatusBar(this.boardsServiceClient.boardsConfig);
159+
160+
this.registerSketchesInMenu(this.menuRegistry);
164161
}
165162

166163
registerToolbarItems(registry: TabBarToolbarRegistry): void {
@@ -453,21 +450,37 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
453450
}
454451

455452
protected async getWorkspaceSketches(): Promise<Sketch[]> {
456-
const sketches = this.sketches.getSketches(this.workspaceService.workspace);
453+
454+
let sketches: Sketch[] = [];
455+
const userHome = await this.fileSystem.getCurrentUserHome();
456+
console.log('userHome', userHome);
457+
if (!!userHome) {
458+
// TODO: get this from the backend
459+
const result = new URI(userHome.uri).resolve('Arduino-PoC').resolve('Sketches').toString();
460+
const stat = await this.fileSystem.getFileStat(result);
461+
if (!!stat) {
462+
sketches = await this.sketches.getSketches(stat);
463+
}
464+
}
457465
return sketches;
458466
}
459467

460468
protected async openSketchFilesInNewWindow(uri: string) {
461469
const url = new URL(window.location.href);
462470
const currentSketch = url.searchParams.get('sketch');
463471
// Nothing to do if we want to open the same sketch which is already opened.
464-
if (!!currentSketch && new URI(currentSketch).toString() === new URI(uri).toString()) {
465-
this.messageService.info(`The '${this.labelProvider.getLongName(new URI(uri))}' is already opened.`);
472+
const sketchUri = new URI(uri);
473+
if (!!currentSketch && new URI(currentSketch).toString() === sketchUri.toString()) {
474+
this.messageService.info(`The '${this.labelProvider.getLongName(sketchUri)}' is already opened.`);
466475
// NOOP.
467476
return;
468477
}
469478
// Preserve the current window if the `sketch` is not in the `searchParams`.
470479
url.searchParams.set('sketch', uri);
480+
const hash = await this.fileSystem.getFsPath(sketchUri.toString());
481+
if (hash) {
482+
url.hash = hash;
483+
}
471484
if (!currentSketch) {
472485
setTimeout(() => window.location.href = url.toString(), 100);
473486
return;

arduino-ide-extension/src/browser/sketch-factory.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export class SketchFactory {
3838
const sketchDir = parent.resolve(sketchName);
3939
const sketchFile = sketchDir.resolve(`${sketchName}.ino`);
4040
this.fileSystem.createFolder(sketchDir.toString());
41-
this.fileSystem.createFile(sketchFile.toString(), { content: `
41+
this.fileSystem.createFile(sketchFile.toString(), {
42+
content: `
4243
void setup() {
4344
// put your setup code here, to run once:
4445
@@ -51,6 +52,10 @@ void loop() {
5152
` });
5253
const location = new URL(window.location.href);
5354
location.searchParams.set('sketch', sketchFile.toString());
55+
const hash = await this.fileSystem.getFsPath(sketchDir.toString());
56+
if (hash) {
57+
location.hash = hash;
58+
}
5459
this.windowService.openNewWindow(location.toString());
5560
} catch (e) {
5661
throw new Error("Cannot create new sketch: " + e);

0 commit comments

Comments
 (0)