From 218f20c4b6345f07989e9fbd22428508af30dbc9 Mon Sep 17 00:00:00 2001 From: Blobanium <45613796+Blobanium@users.noreply.github.com> Date: Mon, 4 Nov 2024 15:58:45 -0800 Subject: [PATCH] Fix "Open In External Browser" duplicating tabs within the internal browser. --- .../blobanium/mcbrowser/mixin/UtilOperatingSystemMixin.java | 4 +++- .../java/io/github/blobanium/mcbrowser/util/BrowserUtil.java | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/blobanium/mcbrowser/mixin/UtilOperatingSystemMixin.java b/src/main/java/io/github/blobanium/mcbrowser/mixin/UtilOperatingSystemMixin.java index 1bff84c..841ece0 100644 --- a/src/main/java/io/github/blobanium/mcbrowser/mixin/UtilOperatingSystemMixin.java +++ b/src/main/java/io/github/blobanium/mcbrowser/mixin/UtilOperatingSystemMixin.java @@ -1,6 +1,7 @@ package io.github.blobanium.mcbrowser.mixin; import io.github.blobanium.mcbrowser.MCBrowser; +import io.github.blobanium.mcbrowser.util.BrowserUtil; import io.github.blobanium.mcbrowser.util.TabManager; import net.minecraft.util.Util; import org.spongepowered.asm.mixin.Mixin; @@ -16,10 +17,11 @@ public class UtilOperatingSystemMixin { @Inject(method = "open(Ljava/net/URI;)V", at = @At("HEAD"), cancellable = true) private void open(URI uri, CallbackInfo ci){ try { - if (MCBrowser.getConfig().openLinkInBrowser && (uri.getScheme().equals("http") || uri.getScheme().equals("https"))) { + if (MCBrowser.getConfig().openLinkInBrowser && (uri.getScheme().equals("http") || uri.getScheme().equals("https")) && !BrowserUtil.openInExternalBrowser) { TabManager.openNewTab(uri.toURL().toString()); ci.cancel(); } + BrowserUtil.openInExternalBrowser = false; } catch (MalformedURLException e) { MCBrowser.LOGGER.error("Opening in browser. Failed to convert to URL", e); } diff --git a/src/main/java/io/github/blobanium/mcbrowser/util/BrowserUtil.java b/src/main/java/io/github/blobanium/mcbrowser/util/BrowserUtil.java index c1dc76a..779f8ba 100644 --- a/src/main/java/io/github/blobanium/mcbrowser/util/BrowserUtil.java +++ b/src/main/java/io/github/blobanium/mcbrowser/util/BrowserUtil.java @@ -26,6 +26,8 @@ public class BrowserUtil { public static String tooltipText; + public static boolean openInExternalBrowser = false; + //Navigation initialization methods public static ButtonWidget initButton(Text message, ButtonWidget.PressAction onPress, int positionX, int buttonLevel) { return ButtonWidget.builder(message, onPress) @@ -110,6 +112,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { //Button related Methods public static void openInBrowser(){ try { + openInExternalBrowser = true; Util.getOperatingSystem().open(new URI(TabManager.getCurrentUrl())); } catch (URISyntaxException e) { MCBrowser.LOGGER.fatal("Unable to open Browser", e);