mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-21 23:20:23 +00:00
More cleanup
This commit is contained in:
parent
d58abf83b9
commit
d5c99ba49f
21 changed files with 97 additions and 153 deletions
|
@ -9,7 +9,7 @@ import io.xpipe.extension.I18n;
|
|||
import io.xpipe.extension.event.ErrorEvent;
|
||||
import io.xpipe.extension.fxcomps.SimpleComp;
|
||||
import io.xpipe.extension.util.DynamicOptionsBuilder;
|
||||
import io.xpipe.extension.util.OsHelper;
|
||||
import io.xpipe.extension.util.DesktopHelper;
|
||||
import javafx.scene.layout.Region;
|
||||
|
||||
public class BrowseDirectoryComp extends SimpleComp {
|
||||
|
@ -36,13 +36,13 @@ public class BrowseDirectoryComp extends SimpleComp {
|
|||
.addComp(
|
||||
"logFiles",
|
||||
new ButtonComp(I18n.observable("openLogsDirectory"), () -> {
|
||||
OsHelper.browsePath(AppLogs.get().getSessionLogsDirectory());
|
||||
DesktopHelper.browsePath(AppLogs.get().getSessionLogsDirectory());
|
||||
}),
|
||||
null)
|
||||
.addComp(
|
||||
"installationFiles",
|
||||
new ButtonComp(I18n.observable("openInstallationDirectory"), () -> {
|
||||
OsHelper.browsePath(XPipeInstallation.getLocalInstallationBasePath());
|
||||
DesktopHelper.browsePath(XPipeInstallation.getLocalInstallationBasePath());
|
||||
}),
|
||||
null)
|
||||
.build();
|
||||
|
|
|
@ -5,7 +5,7 @@ import io.xpipe.app.prefs.AppPrefs;
|
|||
import io.xpipe.extension.I18n;
|
||||
import io.xpipe.extension.fxcomps.CompStructure;
|
||||
import io.xpipe.extension.fxcomps.augment.PopupMenuAugment;
|
||||
import io.xpipe.extension.util.OsHelper;
|
||||
import io.xpipe.extension.util.DesktopHelper;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.ContextMenu;
|
||||
import javafx.scene.control.MenuItem;
|
||||
|
@ -88,7 +88,7 @@ public class SourceCollectionContextMenu<S extends CompStructure<?>> extends Pop
|
|||
if (AppPrefs.get().developerMode().getValue()) {
|
||||
var openDir = new MenuItem(I18n.get("openDir"), new FontIcon("mdal-edit"));
|
||||
openDir.setOnAction(e -> {
|
||||
OsHelper.browseFileInDirectory(group.getCollection().getDirectory());
|
||||
DesktopHelper.browseFileInDirectory(group.getCollection().getDirectory());
|
||||
});
|
||||
cm.getItems().add(openDir);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import io.xpipe.extension.I18n;
|
|||
import io.xpipe.extension.event.ErrorEvent;
|
||||
import io.xpipe.extension.fxcomps.CompStructure;
|
||||
import io.xpipe.extension.fxcomps.augment.PopupMenuAugment;
|
||||
import io.xpipe.extension.util.OsHelper;
|
||||
import io.xpipe.extension.util.DesktopHelper;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.scene.control.ContextMenu;
|
||||
import javafx.scene.control.MenuItem;
|
||||
|
@ -89,7 +89,7 @@ public class SourceEntryContextMenu<S extends CompStructure<?>> extends PopupMen
|
|||
|
||||
var openDir = new MenuItem(I18n.get("browseInternal"), new FontIcon("mdi2f-folder-open-outline"));
|
||||
openDir.setOnAction(e -> {
|
||||
OsHelper.browsePath(entry.getEntry().getDirectory());
|
||||
DesktopHelper.browsePath(entry.getEntry().getDirectory());
|
||||
});
|
||||
cm.getItems().add(openDir);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import io.xpipe.extension.fxcomps.impl.IconButtonComp;
|
|||
import io.xpipe.extension.fxcomps.impl.PrettyImageComp;
|
||||
import io.xpipe.extension.fxcomps.util.PlatformThread;
|
||||
import io.xpipe.extension.fxcomps.util.SimpleChangeListener;
|
||||
import io.xpipe.extension.util.OsHelper;
|
||||
import io.xpipe.extension.util.DesktopHelper;
|
||||
import io.xpipe.extension.util.ThreadHelper;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
|
@ -245,7 +245,7 @@ public class StoreEntryComp extends SimpleComp {
|
|||
|
||||
if (AppPrefs.get().developerMode().getValue()) {
|
||||
var browse = new MenuItem(I18n.get("browse"), new FontIcon("mdi2f-folder-open-outline"));
|
||||
browse.setOnAction(event -> OsHelper.browsePath(entry.getEntry().getDirectory()));
|
||||
browse.setOnAction(event -> DesktopHelper.browsePath(entry.getEntry().getDirectory()));
|
||||
contextMenu.getItems().add(browse);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public class App extends Application {
|
|||
AppActionLinkDetector.detectOnFocus();
|
||||
});
|
||||
});
|
||||
var title = String.format("X-Pipe Desktop (%s)", AppProperties.get().getVersion());
|
||||
var title = String.format("X-Pipe Desktop (Alpha %s)", AppProperties.get().getVersion());
|
||||
var appWindow = new AppMainWindow(stage);
|
||||
appWindow.initialize();
|
||||
appWindow.setContent(title, content);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package io.xpipe.app.core;
|
||||
|
||||
import io.xpipe.app.exchange.MessageExchangeImpls;
|
||||
import io.xpipe.app.util.ModuleHelper;
|
||||
import io.xpipe.core.util.ModuleHelper;
|
||||
import io.xpipe.core.util.XPipeInstallation;
|
||||
import io.xpipe.extension.ModuleInstall;
|
||||
import io.xpipe.extension.XPipeServiceProviders;
|
||||
|
|
|
@ -2,7 +2,7 @@ package io.xpipe.app.core;
|
|||
|
||||
import io.xpipe.app.prefs.AppPrefs;
|
||||
import io.xpipe.app.prefs.SupportedLocale;
|
||||
import io.xpipe.app.util.ModuleHelper;
|
||||
import io.xpipe.core.util.ModuleHelper;
|
||||
import io.xpipe.extension.I18n;
|
||||
import io.xpipe.extension.Translatable;
|
||||
import io.xpipe.extension.event.ErrorEvent;
|
||||
|
@ -25,7 +25,10 @@ import java.nio.file.SimpleFileVisitor;
|
|||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.UnaryOperator;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -94,11 +97,20 @@ public class AppI18n implements I18n {
|
|||
prettyTime = null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
public static class CallingClass extends SecurityManager {
|
||||
public static final CallingClass INSTANCE = new CallingClass();
|
||||
|
||||
public Class<?>[] getCallingClasses() {
|
||||
return getClassContext();
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private static String getCallerModuleName() {
|
||||
var callers = ModuleHelper.CallingClass.INSTANCE.getCallingClasses();
|
||||
var callers = CallingClass.INSTANCE.getCallingClasses();
|
||||
for (Class<?> caller : callers) {
|
||||
if (caller.equals(ModuleHelper.CallingClass.class)
|
||||
if (caller.equals(CallingClass.class)
|
||||
|| caller.equals(ModuleHelper.class)
|
||||
|| caller.equals(AppI18n.class)
|
||||
|| caller.equals(I18n.class)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package io.xpipe.app.core;
|
||||
|
||||
import io.xpipe.app.prefs.AppPrefs;
|
||||
import io.xpipe.app.util.ModuleHelper;
|
||||
import io.xpipe.core.util.ModuleHelper;
|
||||
import io.xpipe.extension.event.ErrorEvent;
|
||||
import io.xpipe.extension.event.TrackEvent;
|
||||
import lombok.Value;
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
package io.xpipe.app.util;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ModuleHelper {
|
||||
|
||||
public static boolean isImage() {
|
||||
return ModuleHelper.class
|
||||
.getProtectionDomain()
|
||||
.getCodeSource()
|
||||
.getLocation()
|
||||
.getProtocol()
|
||||
.equals("jrt");
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static Module getEveryoneModule() {
|
||||
Method getDeclaredFields0 = Class.class.getDeclaredMethod("getDeclaredFields0", boolean.class);
|
||||
getDeclaredFields0.setAccessible(true);
|
||||
Field[] fields = (Field[]) getDeclaredFields0.invoke(Module.class, false);
|
||||
Field modifiers = null;
|
||||
for (Field each : fields) {
|
||||
if ("EVERYONE_MODULE".equals(each.getName())) {
|
||||
modifiers = each;
|
||||
break;
|
||||
}
|
||||
}
|
||||
modifiers.setAccessible(true);
|
||||
return (Module) modifiers.get(null);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static void exportAndOpen(String pkg, Module mod) {
|
||||
if (mod.isExported(pkg) && mod.isOpen(pkg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Method getDeclaredFields0 = Class.class.getDeclaredMethod("getDeclaredMethods0", boolean.class);
|
||||
getDeclaredFields0.setAccessible(true);
|
||||
Method[] fields = (Method[]) getDeclaredFields0.invoke(Module.class, false);
|
||||
Method modifiers = null;
|
||||
for (Method each : fields) {
|
||||
if ("implAddExportsOrOpens".equals(each.getName())) {
|
||||
modifiers = each;
|
||||
break;
|
||||
}
|
||||
}
|
||||
modifiers.setAccessible(true);
|
||||
|
||||
var e = getEveryoneModule();
|
||||
modifiers.invoke(mod, pkg, e, false, true);
|
||||
modifiers.invoke(mod, pkg, e, true, true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
public static class CallingClass extends SecurityManager {
|
||||
public static final CallingClass INSTANCE = new CallingClass();
|
||||
|
||||
public Class<?>[] getCallingClasses() {
|
||||
return getClassContext();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,11 +2,12 @@ package io.xpipe.app.util;
|
|||
|
||||
import io.xpipe.app.core.AppProperties;
|
||||
import io.xpipe.app.core.AppWindowHelper;
|
||||
import io.xpipe.app.prefs.AppPrefs;
|
||||
import io.xpipe.app.update.AppDownloads;
|
||||
import io.xpipe.app.update.AppInstaller;
|
||||
import io.xpipe.app.prefs.AppPrefs;
|
||||
import io.xpipe.core.impl.FileNames;
|
||||
import io.xpipe.core.process.ShellProcessControl;
|
||||
import io.xpipe.core.util.ModuleHelper;
|
||||
import io.xpipe.core.util.ProxyManagerProvider;
|
||||
import io.xpipe.core.util.XPipeInstallation;
|
||||
import io.xpipe.extension.I18n;
|
||||
|
|
|
@ -3,6 +3,7 @@ package io.xpipe.core.util;
|
|||
import io.xpipe.core.charsetter.NewLine;
|
||||
import io.xpipe.core.process.OsType;
|
||||
import io.xpipe.core.process.ShellTypes;
|
||||
import io.xpipe.core.store.ShellStore;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
@ -105,6 +106,6 @@ public class Deobfuscator {
|
|||
}
|
||||
|
||||
var t = ShellTypes.getPlatformDefault();
|
||||
return LocalProcess.executeSimpleBooleanCommand(t.getWhichCommand("retrace." + t.getScriptFileEnding()));
|
||||
return ShellStore.local().create().executeBooleanSimpleCommand(t.getWhichCommand("retrace." + t.getScriptFileEnding()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
package io.xpipe.core.util;
|
||||
|
||||
import io.xpipe.core.process.ShellTypes;
|
||||
|
||||
public class LocalProcess {
|
||||
|
||||
public static boolean executeSimpleBooleanCommand(String cmd) throws Exception {
|
||||
var proc = new ProcessBuilder(ShellTypes.getPlatformDefault().executeCommandListWithShell(cmd)).redirectErrorStream(true).redirectOutput(
|
||||
ProcessBuilder.Redirect.DISCARD).start();
|
||||
return proc.waitFor() == 0;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,10 @@
|
|||
package io.xpipe.core.util;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ModuleHelper {
|
||||
|
||||
public static boolean isImage() {
|
||||
|
@ -10,4 +15,43 @@ public class ModuleHelper {
|
|||
.getProtocol()
|
||||
.equals("jrt");
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static Module getEveryoneModule() {
|
||||
Method getDeclaredFields0 = Class.class.getDeclaredMethod("getDeclaredFields0", boolean.class);
|
||||
getDeclaredFields0.setAccessible(true);
|
||||
Field[] fields = (Field[]) getDeclaredFields0.invoke(Module.class, false);
|
||||
Field modifiers = null;
|
||||
for (Field each : fields) {
|
||||
if ("EVERYONE_MODULE".equals(each.getName())) {
|
||||
modifiers = each;
|
||||
break;
|
||||
}
|
||||
}
|
||||
modifiers.setAccessible(true);
|
||||
return (Module) modifiers.get(null);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static void exportAndOpen(String pkg, Module mod) {
|
||||
if (mod.isExported(pkg) && mod.isOpen(pkg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Method getDeclaredFields0 = Class.class.getDeclaredMethod("getDeclaredMethods0", boolean.class);
|
||||
getDeclaredFields0.setAccessible(true);
|
||||
Method[] fields = (Method[]) getDeclaredFields0.invoke(Module.class, false);
|
||||
Method modifiers = null;
|
||||
for (Method each : fields) {
|
||||
if ("implAddExportsOrOpens".equals(each.getName())) {
|
||||
modifiers = each;
|
||||
break;
|
||||
}
|
||||
}
|
||||
modifiers.setAccessible(true);
|
||||
|
||||
var e = getEveryoneModule();
|
||||
modifiers.invoke(mod, pkg, e, false, true);
|
||||
modifiers.invoke(mod, pkg, e, true, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import io.xpipe.core.impl.FileStore;
|
|||
import io.xpipe.core.impl.LocalStore;
|
||||
import io.xpipe.extension.DataStoreActionProvider;
|
||||
import io.xpipe.extension.I18n;
|
||||
import io.xpipe.extension.util.OsHelper;
|
||||
import io.xpipe.extension.util.DesktopHelper;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
|
||||
import java.nio.file.Files;
|
||||
|
@ -34,6 +34,6 @@ public class FileBrowseAction implements DataStoreActionProvider<FileStore> {
|
|||
|
||||
@Override
|
||||
public void execute(FileStore store) throws Exception {
|
||||
OsHelper.browseFileInDirectory(Path.of(store.getFile()));
|
||||
DesktopHelper.browseFileInDirectory(Path.of(store.getFile()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import io.xpipe.core.store.StreamDataStore;
|
|||
import io.xpipe.extension.DataStoreActionProvider;
|
||||
import io.xpipe.extension.I18n;
|
||||
import io.xpipe.extension.event.ErrorEvent;
|
||||
import io.xpipe.extension.util.OsHelper;
|
||||
import io.xpipe.extension.util.DesktopHelper;
|
||||
import io.xpipe.extension.util.ThreadHelper;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.stage.FileChooser;
|
||||
|
@ -49,7 +49,7 @@ public class StreamExportAction implements DataStoreActionProvider<StreamDataSto
|
|||
try (OutputStream outputStream = Files.newOutputStream(outputFile.toPath())) {
|
||||
inputStream.transferTo(outputStream);
|
||||
}
|
||||
OsHelper.browseFileInDirectory(outputFile.toPath());
|
||||
DesktopHelper.browseFileInDirectory(outputFile.toPath());
|
||||
} catch (Exception e) {
|
||||
ErrorEvent.fromThrowable(e).handle();
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package io.xpipe.extension.fxcomps.util;
|
|||
import io.xpipe.extension.util.ThreadHelper;
|
||||
import javafx.beans.binding.Binding;
|
||||
import javafx.beans.binding.ListBinding;
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
|
@ -20,6 +21,17 @@ public class BindingsHelper {
|
|||
|
||||
private static final Set<ReferenceEntry> REFERENCES = Collections.newSetFromMap(new ConcurrentHashMap<ReferenceEntry, Boolean>());
|
||||
|
||||
public static <T, V> void bindExclusive(
|
||||
Property<V> selected, Map<V, ? extends Property<T>> map, Property<T> toBind
|
||||
) {
|
||||
selected.addListener((c, o, n) -> {
|
||||
toBind.unbind();
|
||||
toBind.bind(map.get(n));
|
||||
});
|
||||
|
||||
toBind.bind(map.get(selected.getValue()));
|
||||
}
|
||||
|
||||
@Value
|
||||
private static class ReferenceEntry {
|
||||
|
||||
|
|
|
@ -1,25 +1,11 @@
|
|||
package io.xpipe.extension.util;
|
||||
|
||||
import io.xpipe.extension.event.ErrorEvent;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
|
||||
import java.awt.*;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class OsHelper {
|
||||
|
||||
public static String getFileSystemCompatibleName(String name) {
|
||||
return name.replaceAll("[\\\\/:*?\"<>|]", "_");
|
||||
}
|
||||
|
||||
public static Path getUserDocumentsPath() {
|
||||
if (SystemUtils.IS_OS_WINDOWS) {
|
||||
return Paths.get(System.getProperty("user.home"));
|
||||
} else {
|
||||
return Paths.get(System.getProperty("user.home"), ".local", "share");
|
||||
}
|
||||
}
|
||||
public class DesktopHelper {
|
||||
|
||||
public static void browsePath(Path file) {
|
||||
if (!Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
|
|
@ -1,19 +0,0 @@
|
|||
package io.xpipe.extension.util;
|
||||
|
||||
import javafx.beans.property.Property;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class PropertiesHelper {
|
||||
|
||||
public static <T, V> void bindExclusive(
|
||||
Property<V> selected, Map<V, ? extends Property<T>> map, Property<T> toBind
|
||||
) {
|
||||
selected.addListener((c, o, n) -> {
|
||||
toBind.unbind();
|
||||
toBind.bind(map.get(n));
|
||||
});
|
||||
|
||||
toBind.bind(map.get(selected.getValue()));
|
||||
}
|
||||
}
|
|
@ -5,13 +5,6 @@ import org.apache.commons.lang3.function.FailableRunnable;
|
|||
|
||||
public class ThreadHelper {
|
||||
|
||||
public static void await(FailableRunnable<InterruptedException> r) {
|
||||
try {
|
||||
r.run();
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static Thread runAsync(Runnable r) {
|
||||
var t = new Thread(r);
|
||||
t.setDaemon(true);
|
||||
|
|
Binary file not shown.
|
@ -1,14 +1,6 @@
|
|||
repositories {
|
||||
mavenCentral()
|
||||
flatDir {
|
||||
dirs file(buildscript.sourceFile).parent
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// A forked version of Lombok because the official one doesn't support Java 19 yet
|
||||
compileOnly name: 'lombok-jdk19-20221010'
|
||||
annotationProcessor name: 'lombok-jdk19-20221010'
|
||||
testCompileOnly name: 'lombok-jdk19-20221010'
|
||||
testAnnotationProcessor name: 'lombok-jdk19-20221010'
|
||||
compileOnly 'org.projectlombok:lombok:1.18.26'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.26'
|
||||
testCompileOnly 'org.projectlombok:lombok:1.18.26'
|
||||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.26'
|
||||
}
|
Loading…
Reference in a new issue