Skip to content

Commit

Permalink
Remove usr:// custom scheme in BROWSER controls (OpenDreamProject#1760
Browse files Browse the repository at this point in the history
)
  • Loading branch information
wixoaGit authored Apr 23, 2024
1 parent 48a3b2f commit 45ec6d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions OpenDreamClient/Interface/Controls/ControlBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ public override void Output(string value, string? jsFunction) {
for (var i = 0; i < parts.Length; i++) {
parts[i] = "\""+HttpUtility.JavaScriptStringEncode(HttpUtility.UrlDecode(parts[i]))+"\""; //wrap in quotes and encode for JS
}

// Insert the values directly into JS and execute it (what could go wrong??)
_webView.ExecuteJavaScript($"{jsFunction}({string.Join(",", parts)})");
}

public void SetFileSource(ResPath filepath, bool userData) {
_webView.Url = (userData ? "usr://127.0.0.1/" : "res://127.0.0.1/") + filepath; // hostname must be the localhost IP for TGUI to work properly
public void SetFileSource(ResPath filepath) {
_webView.Url = "http://127.0.0.1/" + filepath; // hostname must be the localhost IP for TGUI to work properly
}

private void BeforeBrowseHandler(IBeforeBrowseContext context) {
Expand Down Expand Up @@ -108,7 +109,7 @@ private void BeforeBrowseHandler(IBeforeBrowseContext context) {
private void RequestHandler(IRequestHandlerContext context) {
Uri newUri = new Uri(context.Url);

if (newUri.Scheme == "usr") {
if (newUri is { Scheme: "http", Host: "127.0.0.1" }) {
Stream stream;
HttpStatusCode status;
var path = new ResPath(newUri.AbsolutePath);
Expand All @@ -119,7 +120,7 @@ private void RequestHandler(IRequestHandlerContext context) {
stream = Stream.Null;
status = HttpStatusCode.NotFound;
} catch (Exception e) {
_sawmill.Error($"Exception while loading file from usr://:\n{e}");
_sawmill.Error($"Exception while loading file from {newUri}:\n{e}");
stream = Stream.Null;
status = HttpStatusCode.InternalServerError;
}
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamClient/Interface/DreamInterfaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private void RxBrowse(MsgBrowse pBrowse) {
}

var cacheFile = _dreamResource.CreateCacheFile(htmlFileName + ".html", pBrowse.HtmlSource);
outputBrowser.SetFileSource(cacheFile, true);
outputBrowser.SetFileSource(cacheFile);

popup?.Open();
}
Expand Down

0 comments on commit 45ec6d2

Please sign in to comment.