Skip to content

Commit

Permalink
Feature: Added a notification when the app goes to the background for…
Browse files Browse the repository at this point in the history
… the first time (#14673)

Co-authored-by: Yair <39923744+yaira2@users.noreply.github.com>
  • Loading branch information
hishitetsu and yaira2 committed Feb 8, 2024
1 parent fc1f0bc commit f21daca
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
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

0 comments on commit f21daca

Please sign in to comment.