1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-10-08 22:27:02 +02:00

Fix runtime errors & minor tweaks after updating CefSharp

This commit is contained in:
2020-05-16 17:10:23 +02:00
parent 1e3de31fc3
commit ad28d2279f
11 changed files with 25 additions and 22 deletions

@@ -33,7 +33,7 @@ namespace TweetDuck.Browser.Handling{
}
bool IKeyboardHandler.OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut){
if (type == KeyType.RawKeyDown && !browser.FocusedFrame.Url.StartsWith("chrome-devtools://")){
if (type == KeyType.RawKeyDown && !browser.FocusedFrame.Url.StartsWith("devtools://")){
return HandleRawKey(browserControl, browser, (Keys)windowsKeyCode, modifiers);
}

@@ -23,8 +23,13 @@ namespace TweetDuck.Browser.Handling{
}
bool IResourceHandler.Open(IRequest request, out bool handleRequest, ICallback callback){
callback.Dispose();
handleRequest = true;
callback.Continue();
if (dataIn != null){
dataIn.Position = 0;
}
return true;
}
@@ -48,11 +53,11 @@ namespace TweetDuck.Browser.Handling{
dataIn.Read(buffer, 0, length);
dataOut.Write(buffer, 0, length);
bytesRead = length;
return true;
}catch{ // catch IOException, possibly NullReferenceException if dataIn is null
bytesRead = 0;
return false;
}
return bytesRead > 0;
}
bool IResourceHandler.Skip(long bytesToSkip, out long bytesSkipped, IResourceSkipCallback callback){

@@ -1,5 +1,4 @@
using System.Collections.Specialized;
using CefSharp;
using CefSharp;
using TweetDuck.Browser.Handling.Filters;
using TweetDuck.Utils;
using TweetLib.Core.Features.Twitter;
@@ -28,9 +27,7 @@ namespace TweetDuck.Browser.Handling{
return CefReturnValue.Cancel;
}
else if (url.Contains(UrlVendorResource)){
NameValueCollection headers = request.Headers;
headers["Accept-Encoding"] = "identity";
request.Headers = headers;
request.SetHeaderByName("Accept-Encoding", "identity", overwrite: true);
}
}

@@ -73,7 +73,7 @@ namespace TweetDuck.Browser.Notification{
this.timerBarHeight = BrowserUtils.Scale(4, DpiScale);
browser.KeyboardHandler = new KeyboardHandlerNotification(this);
browser.RegisterAsyncJsObject("$TD", new TweetDeckBridge.Notification(owner, this));
browser.RegisterJsBridge("$TD", new TweetDeckBridge.Notification(owner, this));
browser.LoadingStateChanged += Browser_LoadingStateChanged;
browser.FrameLoadEnd += Browser_FrameLoadEnd;

@@ -23,7 +23,7 @@ namespace TweetDuck.Browser.Notification.Screenshot{
int realWidth = BrowserUtils.Scale(width, DpiScale);
browser.RegisterAsyncJsObject("$TD_NotificationScreenshot", new ScreenshotBridge(this, SetScreenshotHeight, callback));
browser.RegisterJsBridge("$TD_NotificationScreenshot", new ScreenshotBridge(this, SetScreenshotHeight, callback));
browser.LoadingStateChanged += (sender, args) => {
if (args.IsLoading){

@@ -74,8 +74,8 @@ namespace TweetDuck.Browser{
this.browser.FrameLoadEnd += browser_FrameLoadEnd;
this.browser.LoadError += browser_LoadError;
this.browser.RegisterAsyncJsObject("$TD", tdBridge);
this.browser.RegisterAsyncJsObject("$TDU", updateBridge);
this.browser.RegisterJsBridge("$TD", tdBridge);
this.browser.RegisterJsBridge("$TDU", updateBridge);
this.browser.BrowserSettings.BackgroundColor = (uint)TwitterUtils.BackgroundColor.ToArgb();
this.browser.Dock = DockStyle.None;

@@ -23,7 +23,6 @@ namespace TweetDuck.Dialogs.Settings{
});
};
this.notification.Activated += notification_Activated;
this.notification.Show();
Disposed += (sender, args) => this.notification.Dispose();
@@ -139,11 +138,6 @@ namespace TweetDuck.Dialogs.Settings{
}
}
private void notification_Activated(object sender, EventArgs e){
notification.Hide();
notification.Activated -= notification_Activated;
}
private void notification_Move(object sender, EventArgs e){
if (radioLocCustom.Checked && notification.Location != ControlExtensions.InvisibleLocation){
Config.CustomNotificationPosition = notification.Location;

@@ -1,6 +1,7 @@
using System;
using CefSharp;
using TweetDuck.Browser.Adapters;
using TweetDuck.Utils;
using TweetLib.Core.Browser;
using TweetLib.Core.Features.Plugins;
using TweetLib.Core.Features.Plugins.Events;
@@ -22,7 +23,7 @@ namespace TweetDuck.Plugins{
}
void IPluginDispatcher.AttachBridge(string name, object bridge){
browser.RegisterAsyncJsObject(name, bridge);
browser.RegisterJsBridge(name, bridge);
}
private void browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){

@@ -27,7 +27,7 @@ namespace TweetDuck.Plugins{
return Status(HttpStatusCode.NoContent, "File is empty."); // FromByteArray crashes CEF internals with no contents
}
else{
return ResourceHandler.FromByteArray(bytes, ResourceHandler.GetMimeType(extension));
return ResourceHandler.FromByteArray(bytes, Cef.GetMimeType(extension));
}
}
}

@@ -144,6 +144,7 @@ namespace TweetDuck{
if (Arguments.HasFlag(Arguments.ArgUpdated)){
WindowsUtils.TryDeleteFolderWhenAble(InstallerPath, 8000);
WindowsUtils.TryDeleteFolderWhenAble(Path.Combine(StoragePath, "Service Worker"), 4000);
BrowserCache.TryClearNow();
}
@@ -161,7 +162,7 @@ namespace TweetDuck{
CefSettings settings = new CefSettings{
UserAgent = BrowserUtils.UserAgentChrome,
BrowserSubprocessPath = BrandName + ".Browser.exe",
BrowserSubprocessPath = Path.Combine(ProgramPath, BrandName + ".Browser.exe"),
CachePath = StoragePath,
UserDataPath = CefDataPath,
LogFile = ConsoleLogFilePath,

@@ -81,6 +81,11 @@ namespace TweetDuck.Utils{
};
}
public static void RegisterJsBridge(this IWebBrowser browserControl, string name, object bridge){
CefSharpSettings.LegacyJavascriptBindingEnabled = true;
browserControl.JavascriptObjectRepository.Register(name, bridge, isAsync: true, BindingOptions.DefaultBinder);
}
public static void OpenDevToolsCustom(this IWebBrowser browser){
var info = new WindowInfo();
info.SetAsPopup(IntPtr.Zero, "Dev Tools");