1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-08 02:34:06 +02:00

Fix JS script execution after updating CefSharp

This commit is contained in:
chylex 2021-12-19 08:14:05 +01:00
parent 587060f73c
commit 3e607ae0fe
Signed by: chylex
GPG Key ID: 4DE42C8F19A80548
5 changed files with 28 additions and 17 deletions

View File

@ -1,5 +1,6 @@
using System.IO;
using CefSharp;
using TweetDuck.Utils;
using TweetLib.Core.Browser;
namespace TweetDuck.Browser.Adapters {
@ -11,7 +12,7 @@ public CefScriptExecutor(IWebBrowser browser) {
}
public void RunFunction(string name, params object[] args) {
browser.ExecuteScriptAsync(name, args);
browser.ExecuteJsAsync(name, args);
}
public void RunScript(string identifier, string script) {

View File

@ -1,6 +1,7 @@
using System.Collections.Generic;
using CefSharp;
using CefSharp.Enums;
using TweetDuck.Utils;
namespace TweetDuck.Browser.Handling {
sealed class DragHandlerBrowser : IDragHandler {
@ -12,7 +13,7 @@ public DragHandlerBrowser(RequestHandlerBrowser requestHandler) {
public bool OnDragEnter(IWebBrowser browserControl, IBrowser browser, IDragData dragData, DragOperationsMask mask) {
void TriggerDragStart(string type, string data = null) {
browserControl.ExecuteScriptAsync("window.TDGF_onGlobalDragStart", type, data);
browserControl.ExecuteJsAsync("window.TDGF_onGlobalDragStart", type, data);
}
requestHandler.BlockNextUserNavUrl = dragData.LinkUrl; // empty if not a link

View File

@ -115,7 +115,7 @@ private IntPtr MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam) {
int delta = BrowserUtils.Scale(NativeMethods.GetMouseHookData(lParam), Config.NotificationScrollSpeed * 0.01);
if (Config.EnableSmoothScrolling) {
browser.ExecuteScriptAsync("window.TDGF_scrollSmoothly", (int) Math.Round(-delta / 0.6));
browser.ExecuteJsAsync("window.TDGF_scrollSmoothly", (int) Math.Round(-delta / 0.6));
}
else {
browser.SendMouseWheelEvent(0, 0, 0, delta, CefEventFlags.None);

View File

@ -220,7 +220,7 @@ private void Config_SoundNotificationInfoChanged(object sender, EventArgs e) {
}
}
browser.ExecuteScriptAsync("TDGF_setSoundNotificationData", hasCustomSound, Config.NotificationSoundVolume);
browser.ExecuteJsAsync("TDGF_setSoundNotificationData", hasCustomSound, Config.NotificationSoundVolume);
}
// external handling
@ -230,57 +230,57 @@ public void HideVideoOverlay(bool focus) {
browser.GetBrowser().GetHost().SendFocusEvent(true);
}
browser.ExecuteScriptAsync("$('#td-video-player-overlay').remove()");
browser.ExecuteJsAsync("$('#td-video-player-overlay').remove()");
}
// javascript calls
public void ReloadToTweetDeck() {
browser.ExecuteScriptAsync($"if(window.TDGF_reload)window.TDGF_reload();else window.location.href='{TwitterUrls.TweetDeck}'");
browser.ExecuteJsAsync($"if(window.TDGF_reload)window.TDGF_reload();else window.location.href='{TwitterUrls.TweetDeck}'");
}
public void UpdateProperties() {
browser.ExecuteScriptAsync(PropertyBridge.GenerateScript(PropertyBridge.Environment.Browser));
browser.ExecuteJsAsync(PropertyBridge.GenerateScript(PropertyBridge.Environment.Browser));
}
public void InjectBrowserCSS() {
browser.ExecuteScriptAsync("TDGF_injectBrowserCSS", Program.Resources.Load("styles/browser.css")?.TrimEnd() ?? string.Empty);
browser.ExecuteJsAsync("TDGF_injectBrowserCSS", Program.Resources.Load("styles/browser.css")?.TrimEnd() ?? string.Empty);
}
public void ReinjectCustomCSS(string css) {
browser.ExecuteScriptAsync("TDGF_reinjectCustomCSS", css?.Replace(Environment.NewLine, " ") ?? string.Empty);
browser.ExecuteJsAsync("TDGF_reinjectCustomCSS", css?.Replace(Environment.NewLine, " ") ?? string.Empty);
}
public void OnMouseClickExtra(IntPtr param) {
browser.ExecuteScriptAsync("TDGF_onMouseClickExtra", (param.ToInt32() >> 16) & 0xFFFF);
browser.ExecuteJsAsync("TDGF_onMouseClickExtra", (param.ToInt32() >> 16) & 0xFFFF);
}
public void ShowTweetDetail(string columnId, string chirpId, string fallbackUrl) {
browser.ExecuteScriptAsync("TDGF_showTweetDetail", columnId, chirpId, fallbackUrl);
browser.ExecuteJsAsync("TDGF_showTweetDetail", columnId, chirpId, fallbackUrl);
}
public void AddSearchColumn(string query) {
browser.ExecuteScriptAsync("TDGF_performSearch", query);
browser.ExecuteJsAsync("TDGF_performSearch", query);
}
public void TriggerTweetScreenshot() {
browser.ExecuteScriptAsync("TDGF_triggerScreenshot()");
browser.ExecuteJsAsync("TDGF_triggerScreenshot()");
}
public void ReloadColumns() {
browser.ExecuteScriptAsync("TDGF_reloadColumns()");
browser.ExecuteJsAsync("TDGF_reloadColumns()");
}
public void PlaySoundNotification() {
browser.ExecuteScriptAsync("TDGF_playSoundNotification()");
browser.ExecuteJsAsync("TDGF_playSoundNotification()");
}
public void ApplyROT13() {
browser.ExecuteScriptAsync("TDGF_applyROT13()");
browser.ExecuteJsAsync("TDGF_applyROT13()");
}
public void ShowUpdateNotification(string versionTag, string releaseNotes) {
browser.ExecuteScriptAsync("TDUF_displayNotification", versionTag, Convert.ToBase64String(Encoding.GetEncoding("iso-8859-1").GetBytes(releaseNotes)));
browser.ExecuteJsAsync("TDUF_displayNotification", versionTag, Convert.ToBase64String(Encoding.GetEncoding("iso-8859-1").GetBytes(releaseNotes)));
}
public void OpenDevTools() {

View File

@ -76,6 +76,15 @@ public static void RegisterJsBridge(this IWebBrowser browserControl, string name
browserControl.JavascriptObjectRepository.Register(name, bridge, isAsync: true, BindingOptions.DefaultBinder);
}
public static void ExecuteJsAsync(this IWebBrowser browserControl, string scriptOrMethodName, params object[] args) {
if (args.Length == 0) {
browserControl.BrowserCore.ExecuteScriptAsync(scriptOrMethodName);
}
else {
browserControl.BrowserCore.ExecuteScriptAsync(scriptOrMethodName, args);
}
}
public static void OpenDevToolsCustom(this IWebBrowser browser, Point? inspectPoint = null) {
var info = new WindowInfo();
info.SetAsPopup(IntPtr.Zero, "Dev Tools");