Skip to content

Fix: Fixed COMException loop due to failure to generate notification #14754

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

Merged
merged 1 commit into from
Feb 18, 2024
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
31 changes: 17 additions & 14 deletions src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ private async void Window_Closed(object sender, WindowEventArgs args)
// Displays a notification the first time the app goes to the background
if (userSettingsService.AppSettingsService.ShowBackgroundRunningNotification)
{
userSettingsService.AppSettingsService.ShowBackgroundRunningNotification = false;

var toastContent = new ToastContent()
SafetyExtensions.IgnoreExceptions(() =>
{
Visual = new()
var toastContent = new ToastContent()
{
BindingGeneric = new ToastBindingGeneric()
Visual = new()
{
Children =
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Expand All @@ -258,16 +258,19 @@ private async void Window_Closed(object sender, WindowEventArgs args)
Text = "BackgroundRunningNotificationBody".GetLocalizedResource()
}
},
}
},
ActivationType = ToastActivationType.Protocol
};
}
},
ActivationType = ToastActivationType.Protocol
};

// Create the toast notification
var toastNotification = new ToastNotification(toastContent.GetXml());

// Create the toast notification
var toastNotification = new ToastNotification(toastContent.GetXml());
// And send the notification
ToastNotificationManager.CreateToastNotifier().Show(toastNotification);

// And send the notification
ToastNotificationManager.CreateToastNotifier().Show(toastNotification);
userSettingsService.AppSettingsService.ShowBackgroundRunningNotification = false;
});
}

if (Program.Pool.WaitOne())
Expand Down
41 changes: 22 additions & 19 deletions src/Files.App/Helpers/Application/AppLifecycleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,15 @@ public static void HandleAppUnhandledException(Exception? ex, bool showToastNoti
if (!showToastNotification)
return;

var toastContent = new ToastContent()
SafetyExtensions.IgnoreExceptions(() =>
{
Visual = new()
var toastContent = new ToastContent()
{
BindingGeneric = new ToastBindingGeneric()
Visual = new()
{
Children =
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Expand All @@ -305,30 +307,31 @@ public static void HandleAppUnhandledException(Exception? ex, bool showToastNoti
Text = "ExceptionNotificationBody".GetLocalizedResource()
}
},
AppLogoOverride = new()
{
Source = "ms-appx:///Assets/error.png"
AppLogoOverride = new()
{
Source = "ms-appx:///Assets/error.png"
}
}
}
},
Actions = new ToastActionsCustom()
{
Buttons =
},
Actions = new ToastActionsCustom()
{
Buttons =
{
new ToastButton("ExceptionNotificationReportButton".GetLocalizedResource(), Constants.GitHub.BugReportUrl)
{
ActivationType = ToastActivationType.Protocol
}
}
},
ActivationType = ToastActivationType.Protocol
};
},
ActivationType = ToastActivationType.Protocol
};

// Create the toast notification
var toastNotification = new ToastNotification(toastContent.GetXml());
// Create the toast notification
var toastNotification = new ToastNotification(toastContent.GetXml());

// And send the notification
ToastNotificationManager.CreateToastNotifier().Show(toastNotification);
// And send the notification
ToastNotificationManager.CreateToastNotifier().Show(toastNotification);
});

// Restart the app
var userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
Expand Down
33 changes: 18 additions & 15 deletions src/Files.App/Helpers/UI/UIHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ public static async Task ShowDeviceEjectResultAsync(Data.Items.DriveType type, b
{
Debug.WriteLine("Device successfully ejected");

var toastContent = new ToastContent()
SafetyExtensions.IgnoreExceptions(() =>
{
Visual = new ToastVisual()
var toastContent = new ToastContent()
{
BindingGeneric = new ToastBindingGeneric()
Visual = new ToastVisual()
{
Children =
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Expand All @@ -57,20 +59,21 @@ public static async Task ShowDeviceEjectResultAsync(Data.Items.DriveType type, b
Text = "EjectNotificationBody".GetLocalizedResource()
}
},
Attribution = new ToastGenericAttributionText()
{
Text = "SettingsAboutAppName".GetLocalizedResource()
Attribution = new ToastGenericAttributionText()
{
Text = "SettingsAboutAppName".GetLocalizedResource()
}
}
}
},
ActivationType = ToastActivationType.Protocol
};
},
ActivationType = ToastActivationType.Protocol
};

// Create the toast notification
var toastNotif = new ToastNotification(toastContent.GetXml());
// Create the toast notification
var toastNotif = new ToastNotification(toastContent.GetXml());

// And send the notification
ToastNotificationManager.CreateToastNotifier().Show(toastNotif);
// And send the notification
ToastNotificationManager.CreateToastNotifier().Show(toastNotif);
});
}
else if (!result)
{
Expand Down