Skip to content

Commit

Permalink
Fix "Open In External Browser" duplicating tabs within the internal b…
Browse files Browse the repository at this point in the history
…rowser.
  • Loading branch information
Blobanium committed Nov 4, 2024
1 parent 788460a commit 218f20c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 218f20c

Please sign in to comment.