Fix startup bug in Windows [release]

This commit is contained in:
crschnick 2023-07-21 18:39:34 +00:00
parent c92dbf762d
commit 488190bd5e
5 changed files with 40 additions and 50 deletions

View file

@ -6,7 +6,6 @@ import io.xpipe.app.core.mode.OperationMode;
import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.issue.LogErrorHandler;
import io.xpipe.app.issue.TrackEvent;
import io.xpipe.app.prefs.AppPrefs;
import io.xpipe.app.util.ThreadHelper;
import io.xpipe.beacon.BeaconServer;
import io.xpipe.beacon.exchange.FocusExchange;
@ -113,7 +112,7 @@ public class LauncherCommand implements Callable<Integer> {
return XPipeDaemonMode.get(opModeName);
}
return AppPrefs.get().startupBehaviour().getValue().getMode();
return XPipeDaemonMode.GUI;
}
@Override

View file

@ -5,7 +5,6 @@ import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.core.impl.LocalStore;
import io.xpipe.core.process.OsType;
import io.xpipe.core.process.ShellControl;
import io.xpipe.core.process.ShellDialects;
import java.nio.file.Files;
import java.nio.file.Path;
@ -91,35 +90,13 @@ public abstract class ExternalApplicationType implements PrefsChoiceValue {
}
}
public abstract static class WindowsType extends ExternalApplicationType {
public abstract static class WindowsFullPathType extends ExternalApplicationType {
private final String executable;
public WindowsType(String id, String executable) {
public WindowsFullPathType(String id) {
super(id);
this.executable = executable;
}
protected abstract Optional<Path> determineInstallationPath();
private Optional<Path> determineFromPath() {
// Try to locate if it is in the Path
try (var cc = LocalStore.getShell()
.command(ShellDialects.getPlatformDefault().getWhichCommand("code.cmd"))
.start()) {
var out = cc.readStdoutDiscardErr();
var exit = cc.getExitCode();
if (exit == 0) {
var first = out.lines().findFirst();
if (first.isPresent()) {
return first.map(Path::of);
}
}
} catch (Exception ex) {
ErrorEvent.fromThrowable(ex).omit().handle();
}
return Optional.empty();
}
protected abstract Optional<Path> determinePath();
@Override
public boolean isSelectable() {
@ -128,7 +105,7 @@ public abstract class ExternalApplicationType implements PrefsChoiceValue {
@Override
public boolean isAvailable() {
var path = determineInstallationPath();
var path = determinePath();
return path.isPresent() && Files.exists(path.get());
}
}

View file

@ -1,9 +1,12 @@
package io.xpipe.app.prefs;
import io.xpipe.app.ext.PrefsChoiceValue;
import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.util.ApplicationHelper;
import io.xpipe.app.util.WindowsRegistry;
import io.xpipe.core.impl.LocalStore;
import io.xpipe.core.process.OsType;
import io.xpipe.core.process.ShellDialects;
import java.io.IOException;
import java.nio.file.Path;
@ -14,14 +17,14 @@ import java.util.function.Supplier;
public interface ExternalEditorType extends PrefsChoiceValue {
ExternalEditorType NOTEPAD = new WindowsType("app.notepad", "notepad") {
ExternalEditorType NOTEPAD = new WindowsFullPathType("app.notepad") {
@Override
protected Optional<Path> determineInstallationPath() {
protected Optional<Path> determinePath() {
return Optional.of(Path.of(System.getenv("SystemRoot") + "\\System32\\notepad.exe"));
}
};
ExternalEditorType VSCODE_WINDOWS = new WindowsType("app.vscode", "code.cmd") {
ExternalEditorType VSCODE_WINDOWS = new WindowsFullPathType("app.vscode") {
@Override
public boolean canOpenDirectory() {
@ -29,7 +32,23 @@ public interface ExternalEditorType extends PrefsChoiceValue {
}
@Override
protected Optional<Path> determineInstallationPath() {
protected Optional<Path> determinePath() {
// Try to locate if it is in the Path
try (var cc = LocalStore.getShell()
.command(ShellDialects.getPlatformDefault().getWhichCommand("code.cmd"))
.start()) {
var out = cc.readStdoutDiscardErr();
var exit = cc.getExitCode();
if (exit == 0) {
var first = out.lines().findFirst();
if (first.isPresent()) {
return first.map(Path::of);
}
}
} catch (Exception ex) {
ErrorEvent.fromThrowable(ex).omit().handle();
}
return Optional.of(Path.of(System.getenv("LOCALAPPDATA"))
.resolve("Programs")
.resolve("Microsoft VS Code")
@ -42,10 +61,10 @@ public interface ExternalEditorType extends PrefsChoiceValue {
return false;
}
};
ExternalEditorType NOTEPADPLUSPLUS_WINDOWS = new WindowsType("app.notepad++", "notepad++") {
ExternalEditorType NOTEPADPLUSPLUS_WINDOWS = new WindowsFullPathType("app.notepad++") {
@Override
protected Optional<Path> determineInstallationPath() {
protected Optional<Path> determinePath() {
Optional<String> launcherDir;
launcherDir = WindowsRegistry.readString(WindowsRegistry.HKEY_LOCAL_MACHINE, "SOFTWARE\\Notepad++", null)
.map(p -> p + "\\notepad++.exe");
@ -156,14 +175,11 @@ public interface ExternalEditorType extends PrefsChoiceValue {
}
}
abstract class WindowsType extends ExternalApplicationType.WindowsType
abstract class WindowsFullPathType extends ExternalApplicationType.WindowsFullPathType
implements ExternalEditorType {
private final String executable;
public WindowsType(String id, String executable) {
super(id, executable);
this.executable = executable;
public WindowsFullPathType(String id) {
super(id);
}
public boolean detach() {
@ -172,7 +188,7 @@ public interface ExternalEditorType extends PrefsChoiceValue {
@Override
public void launch(Path file) throws Exception {
var path = determineInstallationPath();
var path = determinePath();
if (path.isEmpty()) {
throw new IOException("Unable to find installation of " + toTranslatedString());
}

View file

@ -99,16 +99,16 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
return OsType.getLocal().equals(OsType.WINDOWS);
}
};
abstract class WindowsType extends ExternalApplicationType.WindowsType
abstract class WindowsFullPathType extends ExternalApplicationType.WindowsFullPathType
implements ExternalTerminalType {
public WindowsType(String id, String executable) {
super(id, executable);
public WindowsFullPathType(String id) {
super(id);
}
@Override
public void launch(String name, String file, boolean elevated) throws Exception {
var path = determineInstallationPath();
var path = determinePath();
if (path.isEmpty()) {
throw new IOException("Unable to find installation of " + toTranslatedString());
}
@ -120,7 +120,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
protected abstract String createCommand(ShellControl shellControl, String name, String path, String file);
}
ExternalTerminalType TABBY_WINDOWS = new WindowsType("app.tabbyWindows", "tabby") {
ExternalTerminalType TABBY_WINDOWS = new WindowsFullPathType("app.tabbyWindows") {
@Override
protected String createCommand(ShellControl shellControl, String name, String path, String file) {
@ -129,7 +129,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
}
@Override
protected Optional<Path> determineInstallationPath() {
protected Optional<Path> determinePath() {
Optional<String> launcherDir;
launcherDir = WindowsRegistry.readString(
WindowsRegistry.HKEY_CURRENT_USER,

View file

@ -17,7 +17,6 @@ public class ShellDialects {
public static ShellDialect BASH;
public static ShellDialect ZSH;
public static ShellDialect CSH;
public static ShellDialect FISH;
public static class Loader implements ModuleLayerLoader {
@ -30,7 +29,6 @@ public class ShellDialects {
CMD = byName("cmd");
POWERSHELL = byName("powershell");
POWERSHELL_CORE = byName("pwsh");
FISH = byName("fish");
DASH = byName("dash");
BASH = byName("bash");
ZSH = byName("zsh");