mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-25 00:15:48 +02:00
Refactor resource handler related extension methods
This commit is contained in:
parent
22f491d98a
commit
f3f5b88550
Core
@ -139,7 +139,7 @@ protected FormNotificationBase(FormBrowser owner, bool enableContextMenu){
|
||||
|
||||
DpiScale = this.GetDPIScale();
|
||||
|
||||
browser.GetHandlerFactory().RegisterHandler(TwitterUtils.TweetDeckURL, this.resourceHandler);
|
||||
browser.SetupResourceHandler(TwitterUtils.TweetDeckURL, this.resourceHandler);
|
||||
|
||||
Controls.Add(browser);
|
||||
|
||||
|
@ -178,16 +178,7 @@ private void UserConfig_SoundNotificationInfoChanged(object sender, EventArgs e)
|
||||
bool hasCustomSound = Program.UserConfig.IsCustomSoundNotificationSet;
|
||||
|
||||
if (prevSoundNotificationPath != Program.UserConfig.NotificationSoundPath){
|
||||
DefaultResourceHandlerFactory handlerFactory = browser.GetHandlerFactory();
|
||||
IResourceHandler resourceHandler = hasCustomSound ? SoundNotification.CreateFileHandler(Program.UserConfig.NotificationSoundPath) : null;
|
||||
|
||||
if (resourceHandler != null){
|
||||
handlerFactory.RegisterHandler(soundUrl, resourceHandler);
|
||||
}
|
||||
else{
|
||||
handlerFactory.UnregisterHandler(soundUrl);
|
||||
}
|
||||
|
||||
browser.SetupResourceHandler(soundUrl, hasCustomSound ? SoundNotification.CreateFileHandler(Program.UserConfig.NotificationSoundPath) : null);
|
||||
prevSoundNotificationPath = Program.UserConfig.NotificationSoundPath;
|
||||
}
|
||||
|
||||
|
@ -38,8 +38,15 @@ public static ChromiumWebBrowser AsControl(this IWebBrowser browserControl){
|
||||
return (ChromiumWebBrowser)browserControl;
|
||||
}
|
||||
|
||||
public static DefaultResourceHandlerFactory GetHandlerFactory(this ChromiumWebBrowser browser){
|
||||
return (DefaultResourceHandlerFactory)browser.ResourceHandlerFactory;
|
||||
public static void SetupResourceHandler(this ChromiumWebBrowser browser, string url, IResourceHandler handler){
|
||||
DefaultResourceHandlerFactory factory = (DefaultResourceHandlerFactory)browser.ResourceHandlerFactory;
|
||||
|
||||
if (handler == null){
|
||||
factory.UnregisterHandler(url);
|
||||
}
|
||||
else{
|
||||
factory.RegisterHandler(url, handler);
|
||||
}
|
||||
}
|
||||
|
||||
private const string TwitterTrackingUrl = "t.co";
|
||||
|
Loading…
Reference in New Issue
Block a user