diff --git a/Core/Notification/FormNotificationBase.cs b/Core/Notification/FormNotificationBase.cs index 67e119a7..a4ae66d3 100644 --- a/Core/Notification/FormNotificationBase.cs +++ b/Core/Notification/FormNotificationBase.cs @@ -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); diff --git a/Core/TweetDeckBrowser.cs b/Core/TweetDeckBrowser.cs index 47fb7ab6..3680b39b 100644 --- a/Core/TweetDeckBrowser.cs +++ b/Core/TweetDeckBrowser.cs @@ -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; } diff --git a/Core/Utils/BrowserUtils.cs b/Core/Utils/BrowserUtils.cs index 9d33167c..44c3ca44 100644 --- a/Core/Utils/BrowserUtils.cs +++ b/Core/Utils/BrowserUtils.cs @@ -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";