notifications fix

This commit is contained in:
2024-03-10 23:04:39 +01:00
Unverified
parent 1951db857a
commit c4387213a9
15 changed files with 166 additions and 53 deletions

View File

@@ -10,8 +10,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.240211001" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240227000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
</ItemGroup>
<ItemGroup>

View File

@@ -21,6 +21,19 @@ namespace VDownload.Core.Tasks
{
public partial class DownloadTask : ObservableObject
{
#region ENUMS
private enum TaskResult
{
Success,
Cancellation,
Error
}
#endregion
#region SERVICES
protected readonly IConfigurationService _configurationService;
@@ -156,6 +169,8 @@ namespace VDownload.Core.Tasks
$"{_stringResourcesService.NotificationsResources.Get("Author")}: {Video.Author}"
};
string errorMessage = null;
TaskResult? endingStatus = null;
try
{
IProgress<double> onProgressDownloading = new Progress<double>((value) =>
@@ -194,16 +209,12 @@ namespace VDownload.Core.Tasks
await Finalizing(outputFile);
UpdateStatusWithDispatcher(DownloadTaskStatus.EndedSuccessfully);
if (_settingsService.Data.Common.Notifications.OnSuccessful)
{
string title = _stringResourcesService.NotificationsResources.Get("OnSuccessfulTitle");
_notificationsService.SendNotification(title, content);
}
endingStatus = TaskResult.Success;
}
catch (OperationCanceledException)
{
UpdateStatusWithDispatcher(DownloadTaskStatus.EndedCancelled);
endingStatus = TaskResult.Cancellation;
}
catch (Exception ex)
{
@@ -226,18 +237,32 @@ namespace VDownload.Core.Tasks
message = ex.Message;
}
UpdateErrorWithDispatcher(message);
UpdateErrorWithDispatcher(message);
UpdateStatusWithDispatcher(DownloadTaskStatus.EndedUnsuccessfully);
if (_settingsService.Data.Common.Notifications.OnUnsuccessful)
{
string title = _stringResourcesService.NotificationsResources.Get("OnSuccessfulTitle");
content.Add($"{_stringResourcesService.NotificationsResources.Get("Message")}: {ex.Message}");
_notificationsService.SendNotification(title, content);
}
endingStatus = TaskResult.Error;
errorMessage = message;
}
finally
{
switch (endingStatus)
{
case TaskResult.Error:
if (_settingsService.Data.Common.Notifications.OnUnsuccessful)
{
string title = _stringResourcesService.NotificationsResources.Get("OnUnsuccessfulTitle");
content.Add($"{_stringResourcesService.NotificationsResources.Get("Message")}: {errorMessage}");
_notificationsService.SendNotification(title, content);
}
break;
case TaskResult.Success:
if (_settingsService.Data.Common.Notifications.OnSuccessful)
{
string title = _stringResourcesService.NotificationsResources.Get("OnSuccessfulTitle");
_notificationsService.SendNotification(title, content);
}
break;
}
if (Status != DownloadTaskStatus.EndedUnsuccessfully || _settingsService.Data.Common.Temp.DeleteOnError)
{
Directory.Delete(tempDirectory, true);

View File

@@ -11,8 +11,8 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.WinUI.Helpers" Version="8.0.240109" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.240211001" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240227000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="SimpleToolkit.MVVM" Version="1.7.4" />
<PackageReference Include="SimpleToolkit.UI.Models" Version="1.7.4" />

View File

@@ -20,8 +20,8 @@
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.WinUI.Extensions" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls" Version="7.1.2" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.240211001" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240227000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
<PackageReference Include="SimpleToolkit.UI.WinUI.Behaviors" Version="1.7.4" />
<PackageReference Include="SimpleToolkit.UI.WinUI.Controls" Version="1.7.4" />