Skip to content

Commit f8baff1

Browse files
committed
Allow Hyperlink components to open URLs with any scheme, not just http(s)
Adds a fix for Yellow-Dog-Man/Resonite-Issues#1018
1 parent d9fd996 commit f8baff1

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Elements.Core;
2+
using FrooxEngine;
3+
using HarmonyLib;
4+
using MonkeyLoader.Resonite;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Diagnostics;
8+
using System.Text;
9+
10+
namespace CommunityBugFixCollection
11+
{
12+
[HarmonyPatch]
13+
[HarmonyPatchCategory(nameof(AnyProtocolHyperlinks))]
14+
internal sealed class AnyProtocolHyperlinks : ResoniteMonkey<AnyProtocolHyperlinks>
15+
{
16+
public override IEnumerable<string> Authors => Contributors.Banane9;
17+
18+
public override bool CanBeDisabled => true;
19+
20+
[HarmonyPrefix]
21+
[HarmonyPatch(typeof(HyperlinkOpenDialog), nameof(HyperlinkOpenDialog.Open))]
22+
private static bool HyperlinkOpenDialogOpenPrefix(HyperlinkOpenDialog __instance)
23+
{
24+
if (!Enabled)
25+
return true;
26+
27+
if (__instance.World != Userspace.UserspaceWorld || __instance.URL.Value is null)
28+
return false;
29+
30+
Logger.Debug(() => $"Opening Hyperlink: {__instance.URL.Value}");
31+
__instance.RunInBackground(() => Process.Start(__instance.URL.Value.ToString()));
32+
33+
__instance.Slot.Destroy();
34+
35+
return false;
36+
}
37+
38+
[HarmonyPostfix]
39+
[HarmonyPatch(typeof(Hyperlink), nameof(Hyperlink.Open))]
40+
private static bool HyperlinkOpenPostfix(bool __result, Hyperlink __instance)
41+
{
42+
if (!Enabled)
43+
return __result;
44+
45+
if (__result)
46+
return true;
47+
48+
var url = __instance.URL.Value;
49+
if (url is null || (__instance.OpenOnce.Value && url == __instance._lastOpened))
50+
return false;
51+
52+
__instance._lastOpened = url;
53+
54+
Userspace.UserspaceWorld.RunSynchronously(delegate
55+
{
56+
Slot slot = Userspace.UserspaceWorld.AddSlot("Hyperlink");
57+
slot.PositionInFrontOfUser(float3.Backward);
58+
slot.AttachComponent<HyperlinkOpenDialog>().Setup(url, __instance.Reason.Value);
59+
});
60+
61+
__instance.RunInSeconds(5f, () => __instance._lastOpened = null!);
62+
63+
return true;
64+
}
65+
}
66+
}

CommunityBugFixCollection/Locale/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
"CommunityBugFixCollection.CopyToClipboard": "In Zwischenablage kopieren",
99

10+
"CommunityBugFixCollection.AnyProtocolHyperlinks.Description": "Erlaubt es Hyperlink-Komponenten URLs mit beliebigen Schemata zu öffnen, statt nur http(s).",
1011
"CommunityBugFixCollection.BetterGridWorldPreset.Description": "Verbessert das Grid Welt Preset indem das zittern des Bodens verhindert und das Grid zentriert wird.",
1112
"CommunityBugFixCollection.BreakDragAndDropCopiedComponentDrives.Description": "Sorgt dafür, dass Drives beim Kopieren von Komponenten mittels Drag-und-Drop nicht kaputt gehen.",
1213
"CommunityBugFixCollection.CaseInsensitiveCustomGenerics.Description": "Macht das Auswählen von eigenen generischen Typparametern unabhängig von Groß- und Kleinschreibung.",

CommunityBugFixCollection/Locale/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
"CommunityBugFixCollection.CopyToClipboard": "Copy to Clipboard",
99

10+
"CommunityBugFixCollection.AnyProtocolHyperlinks.Description": "Allows Hyperlink components to open URLs with any scheme, not just http(s).",
1011
"CommunityBugFixCollection.BetterGridWorldPreset.Description": "Improves the Grid World Preset by preventing the shaking ground and centering the grid.",
1112
"CommunityBugFixCollection.BreakDragAndDropCopiedComponentDrives.Description": "Fixes copying components using drag-and-drop breaking drives.",
1213
"CommunityBugFixCollection.CaseInsensitiveCustomGenerics.Description": "Makes picking custom generic type parameters case-insensitive.",

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ just disable them in the settings in the meantime.
4343
* URLs to text files or Resonite Packages failing to import instead of appearing as a hyperlink (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/785)
4444
* References in multiple duplicated or transferred-between-worlds items breaking (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/984)
4545
* Context Menu changing size and becoming unusable with extreme FOVs (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/991)
46+
* Hyperlink components only opening http(s) links (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/1018)
4647
* ColorX From HexCode (ProtoFlux node) defaults to Linear profile (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/1404)
4748
* UserInspectors not listing existing users in the session for non-host users (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/1964)
4849
* ProtoFlux value casts from byte to other values converting incorrectly (mono / graphical client only) (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/2257)

0 commit comments

Comments
 (0)