1
0
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:
chylex 2018-01-22 14:53:38 +01:00
parent 22f491d98a
commit f3f5b88550
3 changed files with 11 additions and 13 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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";