Skip to content

Commit

Permalink
dispatch js event to all of browsers and frames
Browse files Browse the repository at this point in the history
  • Loading branch information
hibiyasleep committed Dec 3, 2016
1 parent 6efaa7f commit aca5b59
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
12 changes: 12 additions & 0 deletions HtmlRenderer/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,18 @@ public static void Shutdown()
CefRuntime.Shutdown();
}
}

public void ExecuteScript(string script)
{
this.Browsers.ForEach((b) =>
{
foreach (var frameId in b.GetFrameIdentifiers())
{
var frame = b.GetFrame(frameId);
frame.ExecuteJavaScript(script, null, 0);
}
});
}
}

public class BrowserErrorEventArgs : EventArgs
Expand Down
8 changes: 2 additions & 6 deletions OverlayPlugin.Core/OverlayBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ private void NotifyOverlayState()
this.Overlay.Renderer != null &&
this.Overlay.Renderer.Browser != null)
{
this.Overlay.Renderer.Browser.GetMainFrame().ExecuteJavaScript(updateScript, null, 0);
this.Overlay.Renderer.ExecuteScript(updateScript);
}
}

Expand All @@ -376,11 +376,7 @@ public void SendMessage(string message)
this.Overlay.Renderer != null &&
this.Overlay.Renderer.Browser != null)
{
foreach (var frameId in this.Overlay.Renderer.Browser.GetFrameIdentifiers())
{
var frame = this.Overlay.Renderer.Browser.GetFrame(frameId);
frame.ExecuteJavaScript(script, null, 0);
}
this.Overlay.Renderer.ExecuteScript(script);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion OverlayPlugin.Core/Overlays/LabelOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private void UpdateOverlayText()
this.Overlay.Renderer != null &&
this.Overlay.Renderer.Browser != null)
{
this.Overlay.Renderer.Browser.GetMainFrame().ExecuteJavaScript(updateScript, null, 0);
this.Overlay.Renderer.ExecuteScript(updateScript);
}
else
{
Expand Down
5 changes: 3 additions & 2 deletions OverlayPlugin.Core/Overlays/MiniParseOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ protected override void Update()
this.Overlay.Renderer != null &&
this.Overlay.Renderer.Browser != null)
{
this.Overlay.Renderer.Browser.GetMainFrame().ExecuteJavaScript(updateScript, null, 0);
this.Overlay.Renderer.ExecuteScript(updateScript);
}
}
}

private string CreateEventDispatcherScript()
{
// why?
return "var ActXiv = " + this.CreateJsonData() + ";\n" +
"document.dispatchEvent(new CustomEvent('onOverlayDataUpdate', { detail: ActXiv }));";
}
Expand All @@ -75,7 +76,7 @@ internal string CreateJsonData()

if (!CheckIsActReady())
{
return "";
return "{}";
}

#if DEBUG
Expand Down
2 changes: 1 addition & 1 deletion OverlayPlugin.Core/Overlays/SpellTimerOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected override void Update()
this.Overlay.Renderer != null &&
this.Overlay.Renderer.Browser != null)
{
this.Overlay.Renderer.Browser.GetMainFrame().ExecuteJavaScript(updateScript, null, 0);
this.Overlay.Renderer.ExecuteScript(updateScript);
}

}
Expand Down

0 comments on commit aca5b59

Please sign in to comment.