mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-19 22:01:12 +00:00
More mac integration fixes
This commit is contained in:
parent
480b8d37ff
commit
ded82617e6
|
@ -83,10 +83,7 @@ public class StoreEntrySection implements StorageFilter.Filterable {
|
||||||
return new HorizontalComp(topEntryList);
|
return new HorizontalComp(topEntryList);
|
||||||
}
|
}
|
||||||
|
|
||||||
var all = BindingsHelper.orderedContentBinding(
|
var all = children;
|
||||||
children,
|
|
||||||
Comparator.comparing(storeEntrySection ->
|
|
||||||
storeEntrySection.entry.lastAccessProperty().getValue()));
|
|
||||||
var shown = BindingsHelper.filteredContentBinding(
|
var shown = BindingsHelper.filteredContentBinding(
|
||||||
all,
|
all,
|
||||||
StoreViewState.get()
|
StoreViewState.get()
|
||||||
|
|
|
@ -160,7 +160,7 @@ public class AppInstaller {
|
||||||
"/qb"));
|
"/qb"));
|
||||||
var start = ShellTypes.getPlatformDefault().flatten(List.of("start", "\"\"", exec));
|
var start = ShellTypes.getPlatformDefault().flatten(List.of("start", "\"\"", exec));
|
||||||
var command = installer + "\r\n" + start;
|
var command = installer + "\r\n" + start;
|
||||||
var script = ScriptHelper.createExecScript(shellProcessControl, command, true);
|
var script = ScriptHelper.createExecScript(shellProcessControl, command);
|
||||||
shellProcessControl.executeSimpleCommand("start /min " + script);
|
shellProcessControl.executeSimpleCommand("start /min " + script);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,21 @@ public abstract class ExternalApplicationType implements PrefsChoiceValue {
|
||||||
this.applicationName = applicationName;
|
this.applicationName = applicationName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Optional<Path> getApplicationPath() {
|
||||||
|
try (ShellProcessControl pc = ShellStore.local().create().start()) {
|
||||||
|
try (var c = pc.command(String.format("osascript -e 'POSIX path of (path to application \"%s\")'", applicationName)).start()) {
|
||||||
|
var path = c.readOnlyStdout();
|
||||||
|
if (!c.waitFor()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
return Optional.of(Path.of(path));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
ErrorEvent.fromThrowable(e).omit().handle();
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSelectable() {
|
public boolean isSelectable() {
|
||||||
return OsType.getLocal().equals(OsType.MAC);
|
return OsType.getLocal().equals(OsType.MAC);
|
||||||
|
@ -43,14 +58,7 @@ public abstract class ExternalApplicationType implements PrefsChoiceValue {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
try {
|
return getApplicationPath().isPresent();
|
||||||
return ShellStore.local()
|
|
||||||
.create()
|
|
||||||
.executeBooleanSimpleCommand(String.format("mdfind -name '%s.app'", applicationName));
|
|
||||||
} catch (Exception e) {
|
|
||||||
ErrorEvent.fromThrowable(e).omit().handle();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ public interface ExternalEditorType extends PrefsChoiceValue {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launch(Path file) throws Exception {
|
public void launch(Path file) throws Exception {
|
||||||
ApplicationHelper.executeLocalApplication(List.of("open", "-a", applicationName, file.toString()));
|
ApplicationHelper.executeLocalApplication(List.of("open", "-a", getApplicationPath().orElseThrow().toString(), file.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import io.xpipe.core.impl.FileNames;
|
||||||
import io.xpipe.core.process.OsType;
|
import io.xpipe.core.process.OsType;
|
||||||
import io.xpipe.core.process.ShellProcessControl;
|
import io.xpipe.core.process.ShellProcessControl;
|
||||||
import io.xpipe.core.process.ShellType;
|
import io.xpipe.core.process.ShellType;
|
||||||
|
import io.xpipe.core.process.ShellTypes;
|
||||||
import io.xpipe.core.store.ShellStore;
|
import io.xpipe.core.store.ShellStore;
|
||||||
import io.xpipe.core.util.SecretValue;
|
import io.xpipe.core.util.SecretValue;
|
||||||
import io.xpipe.extension.event.TrackEvent;
|
import io.xpipe.extension.event.TrackEvent;
|
||||||
|
@ -23,10 +24,58 @@ public class ScriptHelper {
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static String createLocalExecScript(String content) {
|
public static String createLocalExecScript(String content) {
|
||||||
try (var l = ShellStore.local().create().start()) {
|
try (var l = ShellStore.local().create().start()) {
|
||||||
return createExecScript(l, content, false);
|
return createExecScript(l, content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final String ZSHI =
|
||||||
|
"""
|
||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
emulate -L zsh -o no_unset
|
||||||
|
|
||||||
|
if (( ARGC == 0 )); then
|
||||||
|
print -ru2 -- 'Usage: zshi <init-command> [zsh-flag]...
|
||||||
|
The same as plain `zsh [zsh-flag]...` except that an additional
|
||||||
|
<init-command> gets executed after all standard Zsh startup files
|
||||||
|
have been sourced.'
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
() {
|
||||||
|
local init=$1
|
||||||
|
shift
|
||||||
|
local tmp
|
||||||
|
{
|
||||||
|
tmp=$(mktemp -d ${TMPDIR:-/tmp}/zsh.XXXXXXXXXX) || return
|
||||||
|
local rc
|
||||||
|
for rc in .zshenv .zprofile .zshrc .zlogin; do
|
||||||
|
>$tmp/$rc <<<'{
|
||||||
|
ZDOTDIR="$_zshi_zdotdir"
|
||||||
|
if [[ -f "$ZDOTDIR/'$rc'" && -r "$ZDOTDIR/'$rc'" ]]; then
|
||||||
|
"builtin" "source" "--" "$ZDOTDIR/'$rc'"
|
||||||
|
fi
|
||||||
|
} always {
|
||||||
|
if [[ -o "no_rcs" ||
|
||||||
|
-o "login" && "'$rc'" == ".zlogin" ||
|
||||||
|
-o "no_login" && "'$rc'" == ".zshrc" ||
|
||||||
|
-o "no_login" && -o "no_interactive" && "'$rc'" == ".zshenv" ]]; then
|
||||||
|
"builtin" "unset" "_zshi_rcs" "_zshi_zdotdir"
|
||||||
|
"builtin" "command" "rm" "-rf" "--" '${(q)tmp}'
|
||||||
|
"builtin" "eval" '${(q)init}'
|
||||||
|
else
|
||||||
|
_zshi_zdotdir=${ZDOTDIR:-~}
|
||||||
|
ZDOTDIR='${(q)tmp}'
|
||||||
|
fi
|
||||||
|
}' || return
|
||||||
|
done
|
||||||
|
_zshi_zdotdir=${ZDOTDIR:-~} ZDOTDIR=$tmp zsh "$@"
|
||||||
|
} always {
|
||||||
|
[[ -e $tmp ]] && rm -rf -- $tmp
|
||||||
|
}
|
||||||
|
} "$@"
|
||||||
|
""";
|
||||||
|
|
||||||
public static String constructOpenWithInitScriptCommand(ShellProcessControl processControl, List<String> init, String toExecuteInShell) {
|
public static String constructOpenWithInitScriptCommand(ShellProcessControl processControl, List<String> init, String toExecuteInShell) {
|
||||||
ShellType t = processControl.getShellType();
|
ShellType t = processControl.getShellType();
|
||||||
if (init.size() == 0 && toExecuteInShell == null) {
|
if (init.size() == 0 && toExecuteInShell == null) {
|
||||||
|
@ -48,22 +97,29 @@ public class ScriptHelper {
|
||||||
content += t.getExitCommand() + nl;
|
content += t.getExitCommand() + nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
var initFile = createExecScript(processControl, content, true);
|
var initFile = createExecScript(processControl, content);
|
||||||
|
|
||||||
|
if (t.equals(ShellTypes.ZSH)) {
|
||||||
|
var zshiFile = createExecScript(processControl, ZSHI);
|
||||||
|
return t.getNormalOpenCommand() + " " + zshiFile + " " + initFile;
|
||||||
|
}
|
||||||
|
|
||||||
return t.getInitFileOpenCommand(initFile);
|
return t.getInitFileOpenCommand(initFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static String createExecScript(ShellProcessControl processControl, String content, boolean restart) {
|
public static String createExecScript(ShellProcessControl processControl, String content) {
|
||||||
var fileName = "exec-" + getScriptId();
|
var fileName = "exec-" + getScriptId();
|
||||||
ShellType type = processControl.getShellType();
|
ShellType type = processControl.getShellType();
|
||||||
var temp = processControl.getTemporaryDirectory();
|
var temp = processControl.getTemporaryDirectory();
|
||||||
var file = FileNames.join(temp, fileName + "." + type.getScriptFileEnding());
|
var file = FileNames.join(temp, fileName + "." + type.getScriptFileEnding());
|
||||||
return createExecScript(processControl, file, content, restart);
|
return createExecScript(processControl, file, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
private static String createExecScript(
|
private static String createExecScript(
|
||||||
ShellProcessControl processControl, String file, String content, boolean restart) {
|
ShellProcessControl processControl, String file, String content
|
||||||
|
) {
|
||||||
ShellType type = processControl.getShellType();
|
ShellType type = processControl.getShellType();
|
||||||
content = type.prepareScriptContent(content);
|
content = type.prepareScriptContent(content);
|
||||||
|
|
||||||
|
@ -81,10 +137,11 @@ public class ScriptHelper {
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static String createAskPassScript(
|
public static String createAskPassScript(
|
||||||
SecretValue pass, ShellProcessControl parent, ShellType type, boolean restart) {
|
SecretValue pass, ShellProcessControl parent, ShellType type
|
||||||
|
) {
|
||||||
var content = type.getScriptEchoCommand(pass.getSecretValue());
|
var content = type.getScriptEchoCommand(pass.getSecretValue());
|
||||||
var temp = parent.getTemporaryDirectory();
|
var temp = parent.getTemporaryDirectory();
|
||||||
var file = FileNames.join(temp, "askpass-" + getScriptId() + "." + type.getScriptFileEnding());
|
var file = FileNames.join(temp, "askpass-" + getScriptId() + "." + type.getScriptFileEnding());
|
||||||
return createExecScript(parent, file, content, restart);
|
return createExecScript(parent, file, content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue