Skip to content

Commit 2ea5894

Browse files
committed
Added cleanup
1 parent ff0b927 commit 2ea5894

File tree

2 files changed

+88
-8
lines changed

2 files changed

+88
-8
lines changed

Microsoft.Toolkit.Uwp.Notifications/Toasts/Compat/Desktop/Win32AppInfo.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ internal class Win32AppInfo
2727

2828
public string Aumid { get; set; }
2929

30+
/// <summary>
31+
/// Gets the AUMID before it was fixed up with the backslash issue
32+
/// </summary>
33+
public string Pre7_0_1Aumid { get; private set; }
34+
3035
public string DisplayName { get; set; }
3136

3237
public string IconPath { get; set; }
@@ -40,6 +45,7 @@ public static Win32AppInfo Get()
4045
appResolver.GetAppIDForProcess(Convert.ToUInt32(process.Id), out string appId, out _, out _, out _);
4146

4247
string aumid;
48+
string pre7_0_1Aumid = null;
4349

4450
// If the app ID is too long
4551
if (appId.Length > AUMID_MAX_LENGTH)
@@ -54,6 +60,7 @@ public static Win32AppInfo Get()
5460
// For versions 19042 and older of Windows 10, we can't use backslashes - Issue #3870
5561
// So we change it to not include those
5662
aumid = appId.Replace('\\', '/');
63+
pre7_0_1Aumid = appId;
5764
}
5865
else
5966
{
@@ -128,6 +135,7 @@ public static Win32AppInfo Get()
128135
return new Win32AppInfo()
129136
{
130137
Aumid = aumid,
138+
Pre7_0_1Aumid = pre7_0_1Aumid,
131139
DisplayName = displayName,
132140
IconPath = iconPath
133141
};

Microsoft.Toolkit.Uwp.Notifications/Toasts/Compat/ToastNotificationManagerCompat.cs

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static class ToastNotificationManagerCompat
2727
#if WIN32
2828
private const string TOAST_ACTIVATED_LAUNCH_ARG = "-ToastActivated";
2929
private const string REG_HAS_SENT_NOTIFICATION = "HasSentNotification";
30+
private const string REG_HAS_7_0_1_FIX = "Has7.0.1Fix";
3031
internal const string DEFAULT_GROUP = "toolkitGroupNull";
3132

3233
private const int CLASS_E_NOAGGREGATION = -2147221232;
@@ -175,6 +176,22 @@ private static void Initialize()
175176

176177
// Additionally, we need to read whether they've sent a notification before
177178
_hasSentNotification = rootKey.GetValue(REG_HAS_SENT_NOTIFICATION) != null;
179+
180+
// And read if we've already applied the 7_0_1 fix
181+
bool has7_0_1fix = rootKey.GetValue(REG_HAS_7_0_1_FIX) != null;
182+
183+
// If it doesn't have the fix yet
184+
if (!has7_0_1fix)
185+
{
186+
// If the AUMID changed
187+
if (win32AppInfo.Pre7_0_1Aumid != null)
188+
{
189+
// Uninstall the old AUMID
190+
}
191+
192+
// Set that it has the fix so we don't try uninstalling again in the future
193+
rootKey.SetValue(REG_HAS_7_0_1_FIX, 1);
194+
}
178195
}
179196

180197
rootKey.SetValue("CustomActivator", string.Format("{{{0}}}", activatorType.GUID));
@@ -183,7 +200,12 @@ private static void Initialize()
183200

184201
private static string GetRegistrySubKey()
185202
{
186-
return @"Software\Classes\AppUserModelId\" + _win32Aumid;
203+
return GetRegistrySubKey(_win32Aumid);
204+
}
205+
206+
private static string GetRegistrySubKey(string win32Aumid)
207+
{
208+
return @"Software\Classes\AppUserModelId\" + win32Aumid;
187209
}
188210

189211
private static Type CreateActivatorType()
@@ -516,21 +538,71 @@ public static void Uninstall()
516538
{
517539
}
518540

519-
if (!DesktopBridgeHelpers.HasIdentity() && _win32Aumid != null)
541+
try
520542
{
521-
try
543+
// Delete any of the app files
544+
var appDataFolderPath = Win32AppInfo.GetAppDataFolderPath(_win32Aumid);
545+
if (Directory.Exists(appDataFolderPath))
522546
{
523-
// Delete any of the app files
524-
var appDataFolderPath = Win32AppInfo.GetAppDataFolderPath(_win32Aumid);
525-
if (Directory.Exists(appDataFolderPath))
547+
Directory.Delete(appDataFolderPath, recursive: true);
548+
}
549+
}
550+
catch
551+
{
552+
}
553+
}
554+
555+
private static void CleanUpOldAumid(string oldAumid)
556+
{
557+
try
558+
{
559+
// Remove all scheduled notifications (do this first before clearing current notifications)
560+
var notifier = ToastNotificationManager.CreateToastNotifier(oldAumid);
561+
foreach (var scheduled in notifier.GetScheduledToastNotifications())
562+
{
563+
try
564+
{
565+
notifier.RemoveFromSchedule(scheduled);
566+
}
567+
catch
526568
{
527-
Directory.Delete(appDataFolderPath, recursive: true);
528569
}
529570
}
530-
catch
571+
}
572+
catch
573+
{
574+
}
575+
576+
try
577+
{
578+
// Clear all current notifications
579+
ToastNotificationManager.History.Clear(oldAumid);
580+
}
581+
catch
582+
{
583+
}
584+
585+
try
586+
{
587+
// Remove registry key
588+
Registry.CurrentUser.DeleteSubKey(GetRegistrySubKey(oldAumid));
589+
}
590+
catch
591+
{
592+
}
593+
594+
try
595+
{
596+
// Delete any of the app files
597+
var appDataFolderPath = Win32AppInfo.GetAppDataFolderPath(oldAumid);
598+
if (Directory.Exists(appDataFolderPath))
531599
{
600+
Directory.Delete(appDataFolderPath, recursive: true);
532601
}
533602
}
603+
catch
604+
{
605+
}
534606
}
535607
#endif
536608

0 commit comments

Comments
 (0)