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.

This commit is contained in:
Martin Barker
2023-01-28 15:24:45 +00:00
parent e9f291f6f7
commit 7946c8ec37

View File

@@ -9,6 +9,7 @@ using System.IO;
using Windows.Foundation.Collections; using Windows.Foundation.Collections;
using System.Diagnostics; using System.Diagnostics;
using System.ComponentModel; using System.ComponentModel;
using Windows.UI.Notifications;
namespace TwitchDesktopNotifications.Core namespace TwitchDesktopNotifications.Core
{ {
@@ -57,7 +58,10 @@ namespace TwitchDesktopNotifications.Core
// download there profile picture // download there profile picture
string fileNameProfilePic = profilePic.Split("/").Last(); 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 // download there profile picture
string fileNameThumbnailPic = streamThumbnail.Split("/").Last(); string fileNameThumbnailPic = streamThumbnail.Split("/").Last();
@@ -67,6 +71,7 @@ namespace TwitchDesktopNotifications.Core
var builder = new ToastContentBuilder() var builder = new ToastContentBuilder()
.AddArgument("streamerUrl", streamerUrl) .AddArgument("streamerUrl", streamerUrl)
.AddArgument("thumbnail_path", FilePath + "/" + fileNameThumbnailPic)
.AddText(streamerName + " is now live on Twitch") .AddText(streamerName + " is now live on Twitch")
.AddHeroImage(new Uri("file://" + (FilePath + "/" + fileNameThumbnailPic).Replace("\\", "/"))) .AddHeroImage(new Uri("file://" + (FilePath + "/" + fileNameThumbnailPic).Replace("\\", "/")))
.AddAppLogoOverride(new Uri("file://" + (FilePath + "/" + fileNameProfilePic).Replace("\\", "/")), ToastGenericAppLogoCrop.Circle) .AddAppLogoOverride(new Uri("file://" + (FilePath + "/" + fileNameProfilePic).Replace("\\", "/")), ToastGenericAppLogoCrop.Circle)
@@ -85,9 +90,14 @@ namespace TwitchDesktopNotifications.Core
builder.Show(toast => builder.Show(toast =>
{ {
toast.ExpirationTime = DateTime.Now.AddSeconds(15); toast.ExpirationTime = DateTime.Now.AddSeconds(15);
toast.Dismissed += (ToastNotification sender, ToastDismissedEventArgs args) =>
{
try
{
File.Delete(FilePath + "/" + fileNameThumbnailPic);
}catch(Exception) { }
};
}); });
} }
} }
} }