Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Automatically Remove All Desktop Shortcuts' Option #3338

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
9 changes: 7 additions & 2 deletions src/UniGetUI.PackageEngine.Operations/AbstractOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,20 +290,20 @@ public async Task MainThread()
}
} while (result == OperationVeredict.AutoRetry);

OperationFinished?.Invoke(this, EventArgs.Empty);

while (OperationQueue.Remove(this));
// END OPERATION

if (result == OperationVeredict.Success)
{
Status = OperationStatus.Succeeded;
OperationFinished?.Invoke(this, EventArgs.Empty);
OperationSucceeded?.Invoke(this, EventArgs.Empty);
Line(Metadata.SuccessMessage, LineType.Information);
}
else if (result == OperationVeredict.Failure)
{
Status = OperationStatus.Failed;
OperationFinished?.Invoke(this, EventArgs.Empty);
OperationFailed?.Invoke(this, EventArgs.Empty);
Line(Metadata.FailureMessage, LineType.Error);
Line(Metadata.FailureMessage + " - " + CoreTools.Translate("Click here for more details"),
Expand All @@ -312,8 +312,13 @@ public async Task MainThread()
else if (result == OperationVeredict.Canceled)
{
Status = OperationStatus.Canceled;
OperationFinished?.Invoke(this, EventArgs.Empty);
Line(CoreTools.Translate("Operation canceled by user"), LineType.Error);
}
else
{
throw new Exception();
}
}
catch (Exception ex)
{
Expand Down
4 changes: 3 additions & 1 deletion src/UniGetUI.PackageEngine.Operations/PackageOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ protected override Task HandleSuccess()

if (Settings.Get("AskToDeleteNewDesktopShortcuts"))
{
DesktopShortcutsDatabase.TryRemoveNewShortcuts(DesktopShortcutsBeforeStart);
// If RemoveAllDesktopShortcuts is enabled, we don't care if the shortcuts were there before the oepration or not;
// we just want them all removed.
DesktopShortcutsDatabase.TryRemoveNewShortcuts(Settings.Get("RemoveAllDesktopShortcuts") ? [] : DesktopShortcutsBeforeStart);
}
return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,26 +152,34 @@ public static List<string> GetUnknownShortcuts()
/// <summary>
/// Will attempt to remove new desktop shortcuts, if applicable.
/// </summary>
/// <param name="PreviousShortCutList"></param>
/// <param name="PreviousShortCutList">The shortcuts that already existed</param>
public static void TryRemoveNewShortcuts(IReadOnlyList<string> PreviousShortCutList)
{
HashSet<string> ShortcutSet = PreviousShortCutList.ToHashSet();
List<string> CurrentShortcutList = DesktopShortcutsDatabase.GetShortcuts();
HashSet<string> ShortcutSet = [.. PreviousShortCutList];
List<string> CurrentShortcutList = GetShortcuts();
foreach (string shortcut in CurrentShortcutList)
{
if (ShortcutSet.Contains(shortcut)) continue;
switch (DesktopShortcutsDatabase.GetStatus(shortcut))
switch (GetStatus(shortcut))
{
case Status.Delete:
DesktopShortcutsDatabase.DeleteFromDisk(shortcut);
DeleteFromDisk(shortcut);
break;
case Status.Maintain:
Logger.Debug("Refraining from deleting new shortcut " + shortcut + ": user disabled its deletion");
break;
case Status.Unknown:
if (UnknownShortcuts.Contains(shortcut)) continue;
Logger.Info("Marking the shortcut " + shortcut + " to be asked to be deleted");
UnknownShortcuts.Add(shortcut);
if (Settings.Get("RemoveAllDesktopShortcuts"))
{
AddToDatabase(shortcut, true);
DeleteFromDisk(shortcut);
RemoveFromUnknownShortcuts(shortcut);
}
else if (!UnknownShortcuts.Contains(shortcut))
{
Logger.Info("Marking the shortcut " + shortcut + " to be asked to be deleted");
UnknownShortcuts.Add(shortcut);
}
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/UniGetUI/Controls/OperationWidgets/OperationControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
private async void OnOperationFinished(object? sender, EventArgs e)
{
// Remove progress notification (if any)
AppNotificationManager.Default.RemoveByTagAsync(Operation.Metadata.Identifier + "progress");

Check warning on line 125 in src/UniGetUI/Controls/OperationWidgets/OperationControl.cs

View workflow job for this annotation

GitHub Actions / test-codebase

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
MainApp.Tooltip.OperationsInProgress--;

// Generate process output
Expand Down Expand Up @@ -156,7 +156,7 @@
}

// Handle newly created shortcuts
if(Settings.Get("AskToDeleteNewDesktopShortcuts")
if (Settings.Get("AskToDeleteNewDesktopShortcuts")
&& !MainApp.Operations.AreThereRunningOperations()
&& DesktopShortcutsDatabase.GetUnknownShortcuts().Any())
{
Expand Down Expand Up @@ -403,7 +403,7 @@

try
{
AppNotificationManager.Default.RemoveByTagAsync(Operation.Metadata.Identifier + "progress");

Check warning on line 406 in src/UniGetUI/Controls/OperationWidgets/OperationControl.cs

View workflow job for this annotation

GitHub Actions / test-codebase

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
AppNotificationBuilder builder = new AppNotificationBuilder()
.SetScenario(AppNotificationScenario.Default)
.SetTag(Operation.Metadata.Identifier + "progress")
Expand Down Expand Up @@ -432,7 +432,7 @@

try
{
AppNotificationManager.Default.RemoveByTagAsync(Operation.Metadata.Identifier);

Check warning on line 435 in src/UniGetUI/Controls/OperationWidgets/OperationControl.cs

View workflow job for this annotation

GitHub Actions / test-codebase

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
AppNotificationBuilder builder = new AppNotificationBuilder()
.SetScenario(AppNotificationScenario.Default)
.SetTag(Operation.Metadata.Identifier)
Expand All @@ -457,7 +457,7 @@

try
{
AppNotificationManager.Default.RemoveByTagAsync(Operation.Metadata.Identifier);

Check warning on line 460 in src/UniGetUI/Controls/OperationWidgets/OperationControl.cs

View workflow job for this annotation

GitHub Actions / test-codebase

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
AppNotificationBuilder builder = new AppNotificationBuilder()
.SetScenario(AppNotificationScenario.Urgent)
.SetTag(Operation.Metadata.Identifier)
Expand Down
7 changes: 6 additions & 1 deletion src/UniGetUI/Pages/DialogPages/DesktopShortcuts.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</Grid.ColumnDefinitions>
<TextBlock
Grid.ColumnSpan="2"
Text="Existing shortcuts on your desktop will be scanned, and you will need to pick which ones to keep and which ones to remove."
Text="Existing shortcuts on your desktop will be scanned, and you will need to pick which ones to keep and which ones to remove. If 'Delete all desktop shortcuts after an install or upgrade' is enabled, they will be deleted automatically."
Margin="0,0,0,0"
TextWrapping="WrapWholeWords"
/>
Expand Down Expand Up @@ -135,6 +135,11 @@
</ListView.ItemTemplate>
</ListView>
</ScrollViewer>
<CheckBox
Content="Delete all desktop shortcuts after an install or upgrade."
IsChecked="{x:Bind DeleteAllShortcuts}"
Checked="HandleAllDesktop_Checked"
Unchecked="HandleAllDesktop_Unchecked" />
</StackPanel>
<!-- Close Button -->
<widgets:DialogCloseButton Margin="0,-63,-24,0" Click="CloseButton_Click"/>
Expand Down
26 changes: 24 additions & 2 deletions src/UniGetUI/Pages/DialogPages/DesktopShortcuts.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using UniGetUI.Core.Tools;
using UniGetUI.PackageEngine.Classes.Packages.Classes;
using UniGetUI.Pages.DialogPages;
using UniGetUI.Core.SettingsEngine;
using UniGetUI.Core.Logging;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
Expand All @@ -23,9 +25,13 @@ public sealed partial class DesktopShortcutsManager : Page
private readonly ObservableCollection<ShortcutEntry> desktopShortcuts = [];

private readonly bool NewOnly;
private bool DeleteAllShortcuts;
private bool IgnoreFirstCheck;

public DesktopShortcutsManager(List<string>? NewShortcuts)
{
DeleteAllShortcuts = Settings.Get("RemoveAllDesktopShortcuts");
IgnoreFirstCheck = DeleteAllShortcuts; // Otherwise the Checked handler is called when the dialog opens
if (NewShortcuts is not null)
{
NewOnly = true;
Expand Down Expand Up @@ -84,13 +90,13 @@ private void DeletableDesktopShortcutsList_DoubleTapped(object sender, DoubleTap
private async void ManualScanButton_Click(object sender, RoutedEventArgs e)
{
DesktopShortcutsDatabase.TryRemoveNewShortcuts([]);
Close?.Invoke(this, EventArgs.Empty);
SaveChangesAndClose();
var shortcuts = DesktopShortcutsDatabase.GetUnknownShortcuts();
if (shortcuts.Any())
{
await DialogHelper.ManageDesktopShortcuts(shortcuts);
}
else
else if (!Settings.Get("RemoveAllDesktopShortcuts"))
{
await DialogHelper.NoDesktopShortcutsFound();
}
Expand All @@ -116,6 +122,22 @@ private void NoResetButton_Click(object sender, RoutedEventArgs e)
ConfirmResetFlyout.Hide();
}

private async void HandleAllDesktop_Checked(object sender, RoutedEventArgs e)
{
if (!IgnoreFirstCheck)
{
SaveChangesAndClose();
await DialogHelper.ConfirmSetDeleteAllShortcutsSetting();
await DialogHelper.ManageDesktopShortcuts();
}
IgnoreFirstCheck = false;
}

private void HandleAllDesktop_Unchecked(object sender, RoutedEventArgs e)
{
Settings.Set("RemoveAllDesktopShortcuts", false);
}

public void SaveChangesAndClose()
{
Close?.Invoke(this, EventArgs.Empty);
Expand Down
15 changes: 14 additions & 1 deletion src/UniGetUI/Pages/DialogPages/DialogHelper_Generic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,5 +596,18 @@ public static async Task NoDesktopShortcutsFound()
dialog.CloseButtonText = CoreTools.Translate("Close");
await Window.ShowDialogAsync(dialog);
}
}

public static async Task ConfirmSetDeleteAllShortcutsSetting()
{
var dialog = DialogFactory.Create();
dialog.Title = CoreTools.Translate("Are you sure you want to delete all shortcuts?");
dialog.Content = CoreTools.Translate("By enabling this, after a package is installed or updated, ANY existing desktop shortcut will be deleted. (Desktop shortcuts unchecked above will be kept). Are you really sure you want to enable this feature?");
dialog.PrimaryButtonText = CoreTools.Translate("Yes");
dialog.CloseButtonText = CoreTools.Translate("No");
dialog.DefaultButton = ContentDialogButton.Close;
if (await Window.ShowDialogAsync(dialog) is ContentDialogResult.Primary)
{
Settings.Set("RemoveAllDesktopShortcuts", true);
}
}
}
Loading