Skip to content

Commit 2e54c93

Browse files
committed
Determine vscode installation directory on windows from Path
1 parent b3f299d commit 2e54c93

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

app/src/main/java/io/xpipe/app/prefs/ExternalEditorType.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package io.xpipe.app.prefs;
22

33
import io.xpipe.app.ext.PrefsChoiceValue;
4+
import io.xpipe.app.issue.ErrorEvent;
45
import io.xpipe.app.util.ApplicationHelper;
56
import io.xpipe.app.util.WindowsRegistry;
7+
import io.xpipe.core.impl.LocalStore;
68
import io.xpipe.core.process.OsType;
9+
import io.xpipe.core.process.ShellDialects;
710

811
import java.io.IOException;
912
import java.nio.file.Path;
@@ -30,6 +33,22 @@ public boolean canOpenDirectory() {
3033

3134
@Override
3235
protected Optional<Path> determinePath() {
36+
// Try to locate if it is in the Path
37+
try (var cc = LocalStore.getShell()
38+
.command(ShellDialects.getPlatformDefault().getWhichCommand("code.cmd"))
39+
.start()) {
40+
var out = cc.readStdoutDiscardErr();
41+
var exit = cc.getExitCode();
42+
if (exit == 0) {
43+
var first = out.lines().findFirst();
44+
if (first.isPresent()) {
45+
return first.map(Path::of);
46+
}
47+
}
48+
} catch (Exception ex) {
49+
ErrorEvent.fromThrowable(ex).omit().handle();
50+
}
51+
3352
return Optional.of(Path.of(System.getenv("LOCALAPPDATA"))
3453
.resolve("Programs")
3554
.resolve("Microsoft VS Code")

0 commit comments

Comments
 (0)