mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-15 08:48:04 +12:00
os specific browser fixes
This commit is contained in:
parent
0f8a8a3d02
commit
62cf8b4f1b
3 changed files with 64 additions and 41 deletions
|
@ -37,6 +37,15 @@ public interface ShellControl extends ProcessControl {
|
|||
|
||||
public void checkRunning() throws Exception;
|
||||
|
||||
default CommandControl osaScript(String script) {
|
||||
return command(String.format(
|
||||
"""
|
||||
osascript - "$@" <<EOF
|
||||
%s
|
||||
EOF
|
||||
""", script));
|
||||
}
|
||||
|
||||
default String executeSimpleStringCommand(String command) throws Exception {
|
||||
try (CommandControl c = command(command).start()) {
|
||||
return c.readOrThrow();
|
||||
|
@ -87,16 +96,17 @@ public interface ShellControl extends ProcessControl {
|
|||
|
||||
default ShellControl subShell(@NonNull ShellDialect type) {
|
||||
return subShell(p -> type.getOpenCommand(), new TerminalOpenFunction() {
|
||||
@Override
|
||||
public boolean changesEnvironment() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean changesEnvironment() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prepare(ShellControl sc, String command) throws Exception {
|
||||
return command;
|
||||
}
|
||||
}).elevationPassword(getElevationPassword());
|
||||
@Override
|
||||
public String prepare(ShellControl sc, String command) throws Exception {
|
||||
return command;
|
||||
}
|
||||
})
|
||||
.elevationPassword(getElevationPassword());
|
||||
}
|
||||
|
||||
interface TerminalOpenFunction {
|
||||
|
@ -108,16 +118,16 @@ public interface ShellControl extends ProcessControl {
|
|||
|
||||
default ShellControl identicalSubShell() {
|
||||
return subShell(p -> p.getShellDialect().getOpenCommand(), new TerminalOpenFunction() {
|
||||
@Override
|
||||
public boolean changesEnvironment() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean changesEnvironment() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prepare(ShellControl sc, String command) throws Exception {
|
||||
return command;
|
||||
}
|
||||
})
|
||||
@Override
|
||||
public String prepare(ShellControl sc, String command) throws Exception {
|
||||
return command;
|
||||
}
|
||||
})
|
||||
.elevationPassword(getElevationPassword());
|
||||
}
|
||||
|
||||
|
@ -137,7 +147,7 @@ public interface ShellControl extends ProcessControl {
|
|||
|
||||
default ShellControl enforcedDialect(ShellDialect type) throws Exception {
|
||||
start();
|
||||
if (getShellDialect().equals(type)) {
|
||||
if (getShellDialect().equals(type)) {
|
||||
return this;
|
||||
} else {
|
||||
return subShell(type).start();
|
||||
|
@ -145,7 +155,7 @@ public interface ShellControl extends ProcessControl {
|
|||
}
|
||||
|
||||
default <T> T enforceDialect(@NonNull ShellDialect type, Function<ShellControl, T> sc) throws Exception {
|
||||
if (isRunning() && getShellDialect().equals(type)) {
|
||||
if (isRunning() && getShellDialect().equals(type)) {
|
||||
return sc.apply(this);
|
||||
} else {
|
||||
try (var sub = subShell(type).start()) {
|
||||
|
@ -155,8 +165,7 @@ public interface ShellControl extends ProcessControl {
|
|||
}
|
||||
|
||||
ShellControl subShell(
|
||||
FailableFunction<ShellControl, String, Exception> command,
|
||||
TerminalOpenFunction terminalCommand);
|
||||
FailableFunction<ShellControl, String, Exception> command, TerminalOpenFunction terminalCommand);
|
||||
|
||||
void executeLine(String command) throws Exception;
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ import io.xpipe.app.browser.FileBrowserEntry;
|
|||
import io.xpipe.app.browser.OpenFileSystemModel;
|
||||
import io.xpipe.app.browser.action.LeafAction;
|
||||
import io.xpipe.core.process.OsType;
|
||||
import io.xpipe.core.process.ShellControl;
|
||||
import io.xpipe.core.process.ShellDialect;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -11,22 +13,26 @@ public class OpenInNativeManagerAction implements LeafAction {
|
|||
|
||||
@Override
|
||||
public void execute(OpenFileSystemModel model, List<FileBrowserEntry> entries) throws Exception {
|
||||
ShellControl sc = model.getFileSystem().getShell().get();
|
||||
ShellDialect d = sc.getShellDialect();
|
||||
for (FileBrowserEntry entry : entries) {
|
||||
var e = entry.getRawFileEntry().getPath();
|
||||
switch (OsType.getLocal()) {
|
||||
case OsType.Windows windows -> {
|
||||
model.getFileSystem()
|
||||
.getShell()
|
||||
.get()
|
||||
.executeSimpleCommand("explorer "
|
||||
+ model.getFileSystem()
|
||||
.getShell()
|
||||
.get()
|
||||
.getShellDialect()
|
||||
.fileArgument(e));
|
||||
sc.executeSimpleCommand("explorer " + d.fileArgument(e));
|
||||
}
|
||||
case OsType.Linux linux -> {
|
||||
var dbus = String.format("""
|
||||
dbus-send --session --print-reply --dest=org.freedesktop.FileManager1 --type=method_call /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:"%s" string:""
|
||||
""", entry.getRawFileEntry().getPath());
|
||||
// sc.executeSimpleCommand(
|
||||
// "xdg-open " + d.fileArgument(entry.getRawFileEntry().getPath()));
|
||||
sc.executeSimpleCommand(dbus);
|
||||
}
|
||||
case OsType.MacOs macOs -> {
|
||||
sc.executeSimpleCommand("open " + (entry.getRawFileEntry().isDirectory() ? "" : "-R ")
|
||||
+ d.fileArgument(entry.getRawFileEntry().getPath()));
|
||||
}
|
||||
case OsType.Linux linux -> {}
|
||||
case OsType.MacOs macOs -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,15 +49,15 @@ public class OpenInNativeManagerAction implements LeafAction {
|
|||
|
||||
@Override
|
||||
public boolean isApplicable(OpenFileSystemModel model, List<FileBrowserEntry> entries) {
|
||||
return entries.stream().allMatch(entry -> entry.getRawFileEntry().isDirectory());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(OpenFileSystemModel model, List<FileBrowserEntry> entries) {
|
||||
return switch (OsType.getLocal()) {
|
||||
case OsType.Windows windows -> "Open in Windows Explorer";
|
||||
case OsType.Linux linux -> "Open in Windows Explorer";
|
||||
case OsType.MacOs macOs -> "Open in Windows Explorer";
|
||||
case OsType.Windows windows -> "Browse in Windows Explorer";
|
||||
case OsType.Linux linux -> "Browse in default file manager";
|
||||
case OsType.MacOs macOs -> "Browse in Finder";
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import io.xpipe.app.browser.OpenFileSystemModel;
|
|||
import io.xpipe.app.browser.action.LeafAction;
|
||||
import io.xpipe.core.impl.FileNames;
|
||||
import io.xpipe.core.process.OsType;
|
||||
import io.xpipe.core.process.ShellControl;
|
||||
import io.xpipe.core.process.ShellDialects;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -13,6 +14,7 @@ public class OpenNativeFileDetailsAction implements LeafAction {
|
|||
|
||||
@Override
|
||||
public void execute(OpenFileSystemModel model, List<FileBrowserEntry> entries) throws Exception {
|
||||
ShellControl sc = model.getFileSystem().getShell().get();
|
||||
for (FileBrowserEntry entry : entries) {
|
||||
var e = entry.getRawFileEntry().getPath();
|
||||
switch (OsType.getLocal()) {
|
||||
|
@ -21,14 +23,20 @@ public class OpenNativeFileDetailsAction implements LeafAction {
|
|||
"""
|
||||
$shell = New-Object -ComObject Shell.Application; $shell.NameSpace('%s').ParseName('%s').InvokeVerb('Properties')
|
||||
""",
|
||||
FileNames.getParent(e),
|
||||
FileNames.getFileName(e));
|
||||
try (var sub = model.getFileSystem().getShell().get().enforcedDialect(ShellDialects.POWERSHELL).start()) {
|
||||
FileNames.getParent(e), FileNames.getFileName(e));
|
||||
try (var sub = sc.enforcedDialect(ShellDialects.POWERSHELL).start()) {
|
||||
sub.command(content).notComplex().execute();
|
||||
}
|
||||
}
|
||||
case OsType.Linux linux -> {}
|
||||
case OsType.MacOs macOs -> {}
|
||||
case OsType.MacOs macOs -> {
|
||||
sc.osaScript(String.format(
|
||||
"""
|
||||
set fileEntry to (POSIX file "%s") as text
|
||||
tell application "Finder" to open information window of file fileEntry
|
||||
""",
|
||||
entry.getRawFileEntry().getPath()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue