Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/UniGetUI.Core.Data.Tests/CoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ public void CheckOtherAttributes()
Assert.NotEqual(0, CoreData.VersionNumber);
Assert.True(File.Exists(CoreData.IgnoredUpdatesDatabaseFile), "The Ignored Updates database file does not exist, but it should have been created automatically.");

int notif_1 = CoreData.VolatileNotificationIdCounter;
int notif_2 = CoreData.VolatileNotificationIdCounter;
Assert.NotEqual(notif_1, notif_2);

int notif_3 = CoreData.UpdatesAvailableNotificationId;
int notif_4 = CoreData.UpdatesAvailableNotificationId;
int notif_3 = CoreData.UpdatesAvailableNotificationTag;
int notif_4 = CoreData.UpdatesAvailableNotificationTag;
Assert.True(notif_3 == notif_4, "The UpdatesAvailableNotificationId must be always the same");
Assert.NotEqual(0, CoreData.UpdatesAvailableNotificationId);
Assert.NotEqual(0, CoreData.UpdatesAvailableNotificationTag);

Assert.True(Directory.Exists(CoreData.UniGetUIExecutableDirectory), "Directory where the executable is located does not exist");
Assert.True(File.Exists(CoreData.UniGetUIExecutableFile), "The executable file does not exist");
Expand Down
18 changes: 2 additions & 16 deletions src/UniGetUI.Core.Data/CoreData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,25 +164,11 @@ public static string IgnoredUpdatesDatabaseFile

public static bool IsDaemon;

public static string ManagerLogs = "";

private static int __volatile_notification_id_counter = 1235;

/// <summary>
/// A self-incremented value to generate random notification IDs
/// </summary>
public static int VolatileNotificationIdCounter
{
get => __volatile_notification_id_counter++;
}

/// <summary>
/// The ID of the notification that is used to inform the user that updates are available
/// </summary>
public static int UpdatesAvailableNotificationId
{
get => 1234;
}
public const int UpdatesAvailableNotificationTag = 1234;


/// <summary>
/// A path pointing to the location where the app is installed
Expand Down
20 changes: 20 additions & 0 deletions src/UniGetUI.Core.Settings/SettingsEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ public static bool AreNotificationsDisabled()
return Get("DisableSystemTray") || Get("DisableNotifications");
}

public static bool AreUpdatesNotificationsDisabled()
{
return AreNotificationsDisabled() || Get("DisableUpdatesNotifications");
}

public static bool AreErrorNotificationsDisabled()
{
return AreNotificationsDisabled() || Get("DisableErrorNotifications");
}

public static bool AreSuccessNotificationsDisabled()
{
return AreNotificationsDisabled() || Get("DisableSuccessNotifications");
}

public static bool AreProgressNotificationsDisabled()
{
return AreNotificationsDisabled() || Get("DisableProgressNotifications");
}

public static bool Get(string setting, bool invert = false)
{
return File.Exists(Path.Join(CoreData.UniGetUIDataDirectory, setting)) ^ invert;
Expand Down
7 changes: 7 additions & 0 deletions src/UniGetUI.Interface.Enums/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,11 @@ public enum IconType
Warning_Round = '\uE93F',
WinGet = '\uE940',
}

public class NotificationArguments
{
public const string Show = "openUniGetUI";
public const string ShowOnUpdatesTab = "openUniGetUIOnUpdatesTab";
public const string UpdateAllPackages = "updateAll";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract class AbstractPackageLoader
private int LoadOperationIdentifier;
protected IEnumerable<IPackageManager> Managers { get; private set; }

public AbstractPackageLoader(IEnumerable<IPackageManager> managers, string identifier, bool AllowMultiplePackageVersions = false, bool DisableReload = false)
public AbstractPackageLoader(IEnumerable<IPackageManager> managers, string identifier, bool AllowMultiplePackageVersions = false, bool DisableReload = false)
{
Managers = managers;
PackageReference = new Dictionary<long, IPackage>();
Expand All @@ -62,7 +62,7 @@ public void StopLoading(bool emitFinishSignal = true)
LoadOperationIdentifier = -1;
IsLoaded = false;
IsLoading = false;
InvokeFinishedLoadingEvent();
if(emitFinishSignal) InvokeFinishedLoadingEvent();
}

protected void InvokePackagesChangedEvent()
Expand Down
13 changes: 6 additions & 7 deletions src/UniGetUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using UniGetUI.PackageEngine.Classes.Manager.Classes;
using UniGetUI.PackageEngine.Operations;
using Windows.Foundation.Collections;
using Microsoft.Windows.AppNotifications;

namespace UniGetUI
{
Expand Down Expand Up @@ -70,7 +71,7 @@ public MainApp()
SetUpWebViewUserDataFolder();
InitializeMainWindow();
ClearNotificationHistory_Safe();
RegisterNotificationActivationEvent_Safe();
RegisterNotificationService();

LoadComponentsAsync().ConfigureAwait(false);
}
Expand Down Expand Up @@ -198,20 +199,18 @@ private static void ClearNotificationHistory_Safe()
/// <summary>
/// Register the notification activation event
/// </summary>
private void RegisterNotificationActivationEvent_Safe()
private void RegisterNotificationService()
{
try
{
ToastNotificationManagerCompat.OnActivated += toastArgs =>
AppNotificationManager.Default.NotificationInvoked += (_, args) =>
{
ToastArguments args = ToastArguments.Parse(toastArgs.Argument);
ValueSet userInput = toastArgs.UserInput;

MainWindow.DispatcherQueue.TryEnqueue(() =>
{
MainWindow.HandleNotificationActivation(args, userInput);
MainWindow.HandleNotificationActivation(args);
});
};
AppNotificationManager.Default.Register();
}
catch (Exception ex)
{
Expand Down
1 change: 1 addition & 0 deletions src/UniGetUI/EntryPoint.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CommunityToolkit.WinUI.Notifications;
using Microsoft.UI.Dispatching;
using Microsoft.Windows.AppLifecycle;
using Microsoft.Windows.AppNotifications;
using UniGetUI.Core.Data;
using UniGetUI.Core.Logging;
using UniGetUI.Core.Tools;
Expand Down
20 changes: 15 additions & 5 deletions src/UniGetUI/Interface/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
using UniGetUI.PackageEngine.Interfaces;
using Windows.ApplicationModel.DataTransfer;
using Windows.Foundation.Collections;
using Microsoft.Windows.AppNotifications;
using UniGetUI.Interface.Enums;

namespace UniGetUI.Interface
{
Expand Down Expand Up @@ -106,22 +108,30 @@ public MainWindow()
};
}
#pragma warning restore CS8618
public void HandleNotificationActivation(ToastArguments args, ValueSet input)
public void HandleNotificationActivation(AppNotificationActivatedEventArgs args)
{
if (args.Contains("action") && args["action"] == "updateAll")
args.Arguments.TryGetValue("action", out string? action);
if (action is null) action = "";

if (action == NotificationArguments.UpdateAllPackages)
{
NavigationPage.UpdatesPage.UpdateAll();
}
else if (args.Contains("action") && args["action"] == "openUniGetUIOnUpdatesTab")
else if (action == NotificationArguments.ShowOnUpdatesTab)
{
NavigationPage.UpdatesNavButton.ForceClick();
Activate();
}
else
else if(action == NotificationArguments.Show)
{
Activate();
}
Logger.Debug("Notification activated: " + args.ToString() + " " + input.ToString());
else
{
throw new ArgumentException(
"args.Argument was not set to a value present in Enums.NotificationArguments");
}
Logger.Debug("Notification activated: " + args.Arguments);
}

/// <summary>
Expand Down
8 changes: 6 additions & 2 deletions src/UniGetUI/Interface/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,17 @@
SettingName="DisableUpdatesNotifications"
/>
<widgets:CheckboxCard
Text="Show a notification when an installation fails"
Text="Show a notification when an operation fails"
SettingName="DisableErrorNotifications"
/>
<widgets:CheckboxCard
Text="Show a notification when an installation finishes successfully"
Text="Show a notification when an operation finishes successfully"
SettingName="DisableSuccessNotifications"
/>
<widgets:CheckboxCard
Text="Show a silent notification when an operation is running"
SettingName="DisableProgressNotifications"
/>
</Toolkit:SettingsExpander.Items>
</widgets:SettingsEntry>

Expand Down
Loading