Restructure proc module

This commit is contained in:
crschnick
2023-02-08 21:34:19 +00:00
parent d5c99ba49f
commit 51bbf8ad67
26 changed files with 159 additions and 159 deletions

View File

@@ -2,6 +2,7 @@ package io.xpipe.app.core;
import io.xpipe.app.Main;
import io.xpipe.app.comp.AppLayoutComp;
import io.xpipe.core.process.OsType;
import io.xpipe.extension.event.ErrorEvent;
import io.xpipe.extension.event.TrackEvent;
import io.xpipe.extension.fxcomps.util.PlatformThread;
@@ -10,7 +11,6 @@ import javafx.application.Platform;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import org.apache.commons.lang3.SystemUtils;
import javax.imageio.ImageIO;
import java.awt.*;
@@ -38,7 +38,7 @@ public class App extends Application {
// Set dock icon explicitly on mac
// This is necessary in case X-Pipe was started through a script as it will have no icon otherwise
if (SystemUtils.IS_OS_MAC) {
if (OsType.getLocal().equals(OsType.MACOS)) {
try {
var iconUrl = Main.class.getResourceAsStream("resources/img/logo.png");
if (iconUrl != null) {

View File

@@ -77,7 +77,7 @@ public class LauncherCommand implements Callable<Integer> {
OpenExchange.Request.builder().arguments(inputs).build());
}
if (OsType.getLocal().equals(OsType.MAC)) {
if (OsType.getLocal().equals(OsType.MACOS)) {
Desktop.getDesktop().setOpenURIHandler(e -> {
con.performSimpleExchange(
OpenExchange.Request.builder().arguments(List.of(e.getURI().toString())).build());
@@ -120,7 +120,7 @@ public class LauncherCommand implements Callable<Integer> {
LauncherInput.handle(inputs);
// URL open operations have to be handled in a special way on macOS!
if (OsType.getLocal().equals(OsType.MAC)) {
if (OsType.getLocal().equals(OsType.MACOS)) {
Desktop.getDesktop().setOpenURIHandler(e -> {
LauncherInput.handle(List.of(e.getURI().toString()));
});

View File

@@ -57,7 +57,7 @@ public abstract class ExternalApplicationType implements PrefsChoiceValue {
@Override
public boolean isSelectable() {
return OsType.getLocal().equals(OsType.MAC);
return OsType.getLocal().equals(OsType.MACOS);
}
@Override

View File

@@ -5,7 +5,6 @@ import io.xpipe.core.process.ShellTypes;
import io.xpipe.extension.prefs.PrefsChoiceValue;
import io.xpipe.extension.util.ApplicationHelper;
import io.xpipe.extension.util.WindowsRegistry;
import org.apache.commons.lang3.SystemUtils;
import java.io.IOException;
import java.nio.file.Path;
@@ -38,13 +37,9 @@ public interface ExternalEditorType extends PrefsChoiceValue {
@Override
protected Optional<Path> determinePath() {
Optional<String> launcherDir = Optional.empty();
if (SystemUtils.IS_OS_WINDOWS) {
launcherDir = WindowsRegistry.readString(
WindowsRegistry.HKEY_LOCAL_MACHINE, "SOFTWARE\\Notepad++", null)
.map(p -> p + "\\notepad++.exe");
}
Optional<String> launcherDir;
launcherDir = WindowsRegistry.readString(WindowsRegistry.HKEY_LOCAL_MACHINE, "SOFTWARE\\Notepad++", null)
.map(p -> p + "\\notepad++.exe");
return launcherDir.map(Path::of);
}
};
@@ -71,7 +66,8 @@ public interface ExternalEditorType extends PrefsChoiceValue {
@Override
public void launch(Path file) throws Exception {
ApplicationHelper.executeLocalApplication(List.of("open", "-a", getApplicationPath().orElseThrow().toString(), file.toString()));
ApplicationHelper.executeLocalApplication(
List.of("open", "-a", getApplicationPath().orElseThrow().toString(), file.toString()));
}
}
@@ -92,7 +88,7 @@ public interface ExternalEditorType extends PrefsChoiceValue {
var format = customCommand.contains("$file") ? customCommand : customCommand + " $file";
var fileString = file.toString().contains(" ") ? "\"" + file + "\"" : file.toString();
ApplicationHelper.executeLocalApplication(format.replace("$file",fileString));
ApplicationHelper.executeLocalApplication(format.replace("$file", fileString));
}
@Override
@@ -108,7 +104,6 @@ public interface ExternalEditorType extends PrefsChoiceValue {
public void launch(Path file) throws Exception;
public static class LinuxPathType extends ExternalApplicationType.PathApplication implements ExternalEditorType {
public LinuxPathType(String id, String command) {
@@ -127,7 +122,8 @@ public interface ExternalEditorType extends PrefsChoiceValue {
}
}
public abstract static class WindowsFullPathType extends ExternalApplicationType.WindowsFullPathType implements ExternalEditorType {
public abstract static class WindowsFullPathType extends ExternalApplicationType.WindowsFullPathType
implements ExternalEditorType {
public WindowsFullPathType(String id) {
super(id);
@@ -147,23 +143,23 @@ public interface ExternalEditorType extends PrefsChoiceValue {
public static final List<ExternalEditorType> WINDOWS_EDITORS = List.of(VSCODE, NOTEPADPLUSPLUS_WINDOWS, NOTEPAD);
public static final List<LinuxPathType> LINUX_EDITORS =
List.of(VSCODE_LINUX, NOTEPADPLUSPLUS_LINUX, KATE, GEDIT, PLUMA, LEAFPAD, MOUSEPAD);
public static final List<ExternalEditorType> MACOS_EDITORS =
List.of(VSCODE_MACOS, SUBLIME_MACOS, TEXT_EDIT);
public static final List<ExternalEditorType> MACOS_EDITORS = List.of(VSCODE_MACOS, SUBLIME_MACOS, TEXT_EDIT);
public static final List<ExternalEditorType> ALL = ((Supplier<List<ExternalEditorType>>) () -> {
var all = new ArrayList<ExternalEditorType>();
if (OsType.getLocal().equals(OsType.WINDOWS)) {
all.addAll(WINDOWS_EDITORS);
}
if (OsType.getLocal().equals(OsType.LINUX)) {
all.addAll(LINUX_EDITORS);
}
if (OsType.getLocal().equals(OsType.MAC)) {
all.addAll(MACOS_EDITORS);
}
all.add(CUSTOM);
return all;
}).get();
var all = new ArrayList<ExternalEditorType>();
if (OsType.getLocal().equals(OsType.WINDOWS)) {
all.addAll(WINDOWS_EDITORS);
}
if (OsType.getLocal().equals(OsType.LINUX)) {
all.addAll(LINUX_EDITORS);
}
if (OsType.getLocal().equals(OsType.MACOS)) {
all.addAll(MACOS_EDITORS);
}
all.add(CUSTOM);
return all;
})
.get();
public static void detectDefault() {
var typeProperty = AppPrefs.get().externalEditor;
@@ -190,13 +186,13 @@ public interface ExternalEditorType extends PrefsChoiceValue {
}
} else {
typeProperty.set(LINUX_EDITORS.stream()
.filter(externalEditorType -> externalEditorType.isAvailable())
.findFirst()
.orElse(null));
.filter(externalEditorType -> externalEditorType.isAvailable())
.findFirst()
.orElse(null));
}
}
if (OsType.getLocal().equals(OsType.MAC)) {
if (OsType.getLocal().equals(OsType.MACOS)) {
typeProperty.set(MACOS_EDITORS.stream()
.filter(externalEditorType -> externalEditorType.isAvailable())
.findFirst()

View File

@@ -121,6 +121,7 @@ public class DataStoreEntry extends StorageElement {
var information = Optional.ofNullable(json.get("information"))
.map(JsonNode::textValue)
.orElse(null);
var lastUsed = Instant.parse(json.required("lastUsed").textValue());
var lastModified = Instant.parse(json.required("lastModified").textValue());
var configuration = Optional.ofNullable(json.get("configuration"))

View File

@@ -1,16 +1,14 @@
package io.xpipe.app.storage;
import io.xpipe.core.util.XPipeTempDirectory;
import io.xpipe.core.util.XPipeSession;
import io.xpipe.extension.event.ErrorEvent;
import io.xpipe.extension.event.TrackEvent;
import lombok.NonNull;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.SystemUtils;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -22,44 +20,7 @@ public class StandardStorage extends DataStorage {
private DataSourceCollection recovery;
private boolean isNewSession() {
try {
if (SystemUtils.IS_OS_WINDOWS) {
var sessionFile = dir.resolve("session");
if (!Files.exists(sessionFile)) {
return true;
}
var lastSessionEndTime = Instant.parse(Files.readString(sessionFile));
var pf = Path.of("C:\\pagefile.sys");
var lastBootTime = Files.getLastModifiedTime(pf).toInstant();
return lastSessionEndTime.isBefore(lastBootTime);
} else {
var sessionFile = XPipeTempDirectory.getLocal().resolve("xpipe_session");
return !Files.exists(sessionFile);
}
} catch (Exception ex) {
ErrorEvent.fromThrowable(ex).omitted(true).build().handle();
return true;
}
}
private void writeSessionInfo() {
try {
if (SystemUtils.IS_OS_WINDOWS) {
var sessionFile = dir.resolve("session");
var now = Instant.now().toString();
Files.writeString(sessionFile, now);
} else {
var sessionFile = XPipeTempDirectory.getLocal().resolve("xpipe_session");
if (!Files.exists(sessionFile)) {
Files.createFile(sessionFile);
}
}
} catch (Exception ex) {
ErrorEvent.fromThrowable(ex).omitted(true).build().handle();
}
return XPipeSession.get().isNewSystemSession();
}
private void deleteLeftovers() {
@@ -322,8 +283,6 @@ public class StandardStorage extends DataStorage {
}
deleteLeftovers();
writeSessionInfo();
}
@Override

View File

@@ -63,7 +63,7 @@ public class AppInstaller {
return Files.exists(Path.of("/etc/debian_version")) ? new InstallerAssetType.Debian() : new InstallerAssetType.Rpm();
}
if (OsType.getLocal().equals(OsType.MAC)) {
if (OsType.getLocal().equals(OsType.MACOS)) {
return new InstallerAssetType.Pkg();
}
@@ -82,7 +82,7 @@ public class AppInstaller {
}
}
if (p.getOsType().equals(OsType.MAC)) {
if (p.getOsType().equals(OsType.MACOS)) {
return new InstallerAssetType.Pkg();
}

View File

@@ -6,7 +6,7 @@ import io.xpipe.app.core.AppExtensionManager;
import io.xpipe.app.core.AppProperties;
import io.xpipe.app.core.mode.OperationMode;
import io.xpipe.app.prefs.AppPrefs;
import io.xpipe.core.impl.ProcessControlProvider;
import io.xpipe.core.process.ProcessControlProvider;
import io.xpipe.core.util.XPipeSession;
import io.xpipe.extension.event.ErrorEvent;
import io.xpipe.extension.event.TrackEvent;