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

Feature: Added a notification when the app goes to the background for the first time #14673

Merged
merged 3 commits into from
Feb 8, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// Licensed under the MIT License. See the LICENSE.

using CommunityToolkit.WinUI.Helpers;
using CommunityToolkit.WinUI.Notifications;
using Microsoft.Extensions.Logging;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Windows.AppLifecycle;
using Windows.ApplicationModel;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
using Windows.UI.Notifications;

namespace Files.App
{
Expand Down Expand Up @@ -234,6 +236,40 @@ private async void Window_Closed(object sender, WindowEventArgs args)

Thread.Yield();

// Displays a notification the first time the app goes to the background
if (userSettingsService.AppSettingsService.ShowBackgroundRunningNotification)
{
userSettingsService.AppSettingsService.ShowBackgroundRunningNotification = false;

var toastContent = new ToastContent()
{
Visual = new()
{
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Text = "BackgroundRunningNotificationHeader".GetLocalizedResource()
},
new AdaptiveText()
{
Text = "BackgroundRunningNotificationBody".GetLocalizedResource()
}
},
}
},
ActivationType = ToastActivationType.Protocol
};

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

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

if (Program.Pool.WaitOne())
{
// Resume the instance
Expand Down
6 changes: 6 additions & 0 deletions src/Files.App/Services/Settings/AppSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public bool ShowStatusCenterTeachingTip
set => Set(value);
}

public bool ShowBackgroundRunningNotification
{
get => Get(true);
set => Set(value);
}

public bool RestoreTabsOnStartup
{
get => Get(false);
Expand Down
6 changes: 6 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -3685,4 +3685,10 @@
<data name="ChangeAlbumCover" xml:space="preserve">
<value>Change album cover</value>
</data>
<data name="BackgroundRunningNotificationBody" xml:space="preserve">
<value>Files is still running in the background to improve startup performance.</value>
</data>
<data name="BackgroundRunningNotificationHeader" xml:space="preserve">
<value>Where did Files go?</value>
</data>
</root>
5 changes: 5 additions & 0 deletions src/Files.Core/Services/Settings/IAppSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public interface IAppSettingsService : IBaseSettingsService, INotifyPropertyChan
/// </summary>
bool ShowStatusCenterTeachingTip { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not to show the notification to inform background running.
/// </summary>
bool ShowBackgroundRunningNotification { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not to restore tabs on startup.
/// This is used when prompting users to restart after changing the app language.
Expand Down