Skip to content

Commit 437caeb

Browse files
authored
Open Save as... dialog when saving sketches for the first time (#579)
* Properly recognize temporary sketches in macOS Without this fix, sketches report their URI path as /private/var/xxx whereas `os.tmpdir()` returns /var/xxx. The second path can be turned into the first by resolving symlinks, which gives a canonical path to compare against. * Open Save as... dialog when saving sketches for the first time
1 parent 3b04d8d commit 437caeb

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: arduino-ide-extension/src/browser/contributions/save-sketch.ts

+17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { injectable } from 'inversify';
22
import { CommonCommands } from '@theia/core/lib/browser/common-frontend-contribution';
33
import { ArduinoMenus } from '../menu/arduino-menus';
44
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
5+
import { SaveAsSketch } from './save-as-sketch';
56
import {
67
SketchContribution,
78
Command,
@@ -51,6 +52,22 @@ export class SaveSketch extends SketchContribution {
5152
}
5253

5354
async saveSketch(): Promise<void> {
55+
const sketch = await this.sketchServiceClient.currentSketch();
56+
if (!sketch) {
57+
return;
58+
}
59+
const isTemp = await this.sketchService.isTemp(sketch);
60+
if (isTemp) {
61+
return this.commandService.executeCommand(
62+
SaveAsSketch.Commands.SAVE_AS_SKETCH.id,
63+
{
64+
execOnlyIfTemp: false,
65+
openAfterMove: true,
66+
wipeOriginal: true,
67+
}
68+
);
69+
}
70+
5471
return this.commandService.executeCommand(CommonCommands.SAVE_ALL.id);
5572
}
5673
}

Diff for: arduino-ide-extension/src/node/sketches-service-impl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ void loop() {
387387

388388
async isTemp(sketch: Sketch): Promise<boolean> {
389389
let sketchPath = FileUri.fsPath(sketch.uri);
390-
let temp = os.tmpdir();
390+
let temp = await promisify(fs.realpath)(os.tmpdir());
391391
// Note: VS Code URI normalizes the drive letter. `C:` will be converted into `c:`.
392392
// https://github.com/Microsoft/vscode/issues/68325#issuecomment-462239992
393393
if (isWindows) {

0 commit comments

Comments
 (0)