From 940480918e1c5351be129f1d3f99b9648d70b4c0 Mon Sep 17 00:00:00 2001 From: crschnick Date: Wed, 17 Jul 2024 10:00:29 +0000 Subject: [PATCH] Native lib fixes --- .../xpipe/app/core/window/ModifiedStage.java | 6 +++--- .../core/window/NativeMacOsWindowControl.java | 12 +++++++++--- .../java/io/xpipe/app/util/NativeBridge.java | 18 +++++++++--------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/core/window/ModifiedStage.java b/app/src/main/java/io/xpipe/app/core/window/ModifiedStage.java index 4352ab6c6..18bc28f82 100644 --- a/app/src/main/java/io/xpipe/app/core/window/ModifiedStage.java +++ b/app/src/main/java/io/xpipe/app/core/window/ModifiedStage.java @@ -67,9 +67,9 @@ public class ModifiedStage extends Stage { case OsType.MacOs macOs -> { var ctrl = new NativeMacOsWindowControl(stage); var seamlessFrame = !AppPrefs.get().performanceMode().get() && mergeFrame(); - ctrl.setAppearance(seamlessFrame, AppPrefs.get().theme.getValue().isDark()); - stage.getScene().getRoot().pseudoClassStateChanged(PseudoClass.getPseudoClass("seamless-frame"), seamlessFrame); - stage.getScene().getRoot().pseudoClassStateChanged(PseudoClass.getPseudoClass("separate-frame"), !seamlessFrame); + var seamlessFrameApplied = ctrl.setAppearance(seamlessFrame, AppPrefs.get().theme.getValue().isDark()) && seamlessFrame; + stage.getScene().getRoot().pseudoClassStateChanged(PseudoClass.getPseudoClass("seamless-frame"), seamlessFrameApplied); + stage.getScene().getRoot().pseudoClassStateChanged(PseudoClass.getPseudoClass("separate-frame"), !seamlessFrameApplied); } case OsType.Windows windows -> { var ctrl = new NativeWinWindowControl(stage); diff --git a/app/src/main/java/io/xpipe/app/core/window/NativeMacOsWindowControl.java b/app/src/main/java/io/xpipe/app/core/window/NativeMacOsWindowControl.java index 8ad5d189c..817d8c57a 100644 --- a/app/src/main/java/io/xpipe/app/core/window/NativeMacOsWindowControl.java +++ b/app/src/main/java/io/xpipe/app/core/window/NativeMacOsWindowControl.java @@ -28,11 +28,17 @@ public class NativeMacOsWindowControl { this.nsWindow = (long) nativeHandle; } - public void setAppearance(boolean seamlessFrame, boolean darkMode) { + public boolean setAppearance(boolean seamlessFrame, boolean darkMode) { if (!ModuleHelper.isImage()) { - return; + return false; } - NativeBridge.getMacOsLibrary().setAppearance(new NativeLong(nsWindow), seamlessFrame, darkMode); + var lib = NativeBridge.getMacOsLibrary(); + if (lib.isEmpty()) { + return false; + } + + lib.get().setAppearance(new NativeLong(nsWindow), seamlessFrame, darkMode); + return true; } } diff --git a/app/src/main/java/io/xpipe/app/util/NativeBridge.java b/app/src/main/java/io/xpipe/app/util/NativeBridge.java index 81b5283c6..de42ab897 100644 --- a/app/src/main/java/io/xpipe/app/util/NativeBridge.java +++ b/app/src/main/java/io/xpipe/app/util/NativeBridge.java @@ -4,29 +4,29 @@ import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.NativeLong; import io.xpipe.app.issue.ErrorEvent; +import io.xpipe.core.util.XPipeInstallation; import java.util.Map; +import java.util.Optional; public class NativeBridge { private static MacOsLibrary macOsLibrary; + private static boolean loadingFailed; - public static MacOsLibrary getMacOsLibrary() { - if (macOsLibrary == null) { + public static Optional getMacOsLibrary() { + if (macOsLibrary == null && !loadingFailed) { try { + System.setProperty("jna.library.path", XPipeInstallation.getCurrentInstallationBasePath() + .resolve("Contents").resolve("runtime").resolve("Home").resolve("lib").toString()); var l = Native.load("xpipe_bridge", MacOsLibrary.class, Map.of()); macOsLibrary = l; } catch (Throwable t) { ErrorEvent.fromThrowable(t).handle(); - macOsLibrary = new MacOsLibrary() { - @Override - public void setAppearance(NativeLong window, boolean seamlessFrame, boolean dark) { - - } - }; + loadingFailed = true; } } - return macOsLibrary; + return Optional.ofNullable(macOsLibrary); } public static interface MacOsLibrary extends Library {