From 7946c8ec379862f44ffab65f46c69959b5a51e0e Mon Sep 17 00:00:00 2001 From: Martin Barker Date: Sat, 28 Jan 2023 15:24:45 +0000 Subject: [PATCH] Added some Checks to make sure we're not contantly downloading profile images if we have it cached already, and clean up thumbnails when the toast is finished. --- TwitchDesktopNotifications/Core/Notification.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/TwitchDesktopNotifications/Core/Notification.cs b/TwitchDesktopNotifications/Core/Notification.cs index 70935c0..d2141da 100644 --- a/TwitchDesktopNotifications/Core/Notification.cs +++ b/TwitchDesktopNotifications/Core/Notification.cs @@ -9,6 +9,7 @@ using System.IO; using Windows.Foundation.Collections; using System.Diagnostics; using System.ComponentModel; +using Windows.UI.Notifications; namespace TwitchDesktopNotifications.Core { @@ -57,7 +58,10 @@ namespace TwitchDesktopNotifications.Core // download there profile picture string fileNameProfilePic = profilePic.Split("/").Last(); - (new WebClient()).DownloadFile(new Uri(profilePic), FilePath+"/"+ fileNameProfilePic); + if (!File.Exists(FilePath + "/" + fileNameProfilePic)) + { + (new WebClient()).DownloadFile(new Uri(profilePic), FilePath + "/" + fileNameProfilePic); + } // download there profile picture string fileNameThumbnailPic = streamThumbnail.Split("/").Last(); @@ -67,6 +71,7 @@ namespace TwitchDesktopNotifications.Core var builder = new ToastContentBuilder() .AddArgument("streamerUrl", streamerUrl) + .AddArgument("thumbnail_path", FilePath + "/" + fileNameThumbnailPic) .AddText(streamerName + " is now live on Twitch") .AddHeroImage(new Uri("file://" + (FilePath + "/" + fileNameThumbnailPic).Replace("\\", "/"))) .AddAppLogoOverride(new Uri("file://" + (FilePath + "/" + fileNameProfilePic).Replace("\\", "/")), ToastGenericAppLogoCrop.Circle) @@ -85,9 +90,14 @@ namespace TwitchDesktopNotifications.Core builder.Show(toast => { toast.ExpirationTime = DateTime.Now.AddSeconds(15); + toast.Dismissed += (ToastNotification sender, ToastDismissedEventArgs args) => + { + try + { + File.Delete(FilePath + "/" + fileNameThumbnailPic); + }catch(Exception) { } + }; }); } - - } }