Skip to content

Commit f21daca

Browse files
hishitetsuyaira2
andauthored
Feature: Added a notification when the app goes to the background for the first time (#14673)
Co-authored-by: Yair <39923744+yaira2@users.noreply.github.com>
1 parent fc1f0bc commit f21daca

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

src/Files.App/App.xaml.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using CommunityToolkit.WinUI.Helpers;
5+
using CommunityToolkit.WinUI.Notifications;
56
using Microsoft.Extensions.Logging;
67
using Microsoft.UI.Xaml;
78
using Microsoft.UI.Xaml.Controls;
89
using Microsoft.Windows.AppLifecycle;
910
using Windows.ApplicationModel;
1011
using Windows.ApplicationModel.DataTransfer;
1112
using Windows.Storage;
13+
using Windows.UI.Notifications;
1214

1315
namespace Files.App
1416
{
@@ -234,6 +236,40 @@ private async void Window_Closed(object sender, WindowEventArgs args)
234236

235237
Thread.Yield();
236238

239+
// Displays a notification the first time the app goes to the background
240+
if (userSettingsService.AppSettingsService.ShowBackgroundRunningNotification)
241+
{
242+
userSettingsService.AppSettingsService.ShowBackgroundRunningNotification = false;
243+
244+
var toastContent = new ToastContent()
245+
{
246+
Visual = new()
247+
{
248+
BindingGeneric = new ToastBindingGeneric()
249+
{
250+
Children =
251+
{
252+
new AdaptiveText()
253+
{
254+
Text = "BackgroundRunningNotificationHeader".GetLocalizedResource()
255+
},
256+
new AdaptiveText()
257+
{
258+
Text = "BackgroundRunningNotificationBody".GetLocalizedResource()
259+
}
260+
},
261+
}
262+
},
263+
ActivationType = ToastActivationType.Protocol
264+
};
265+
266+
// Create the toast notification
267+
var toastNotification = new ToastNotification(toastContent.GetXml());
268+
269+
// And send the notification
270+
ToastNotificationManager.CreateToastNotifier().Show(toastNotification);
271+
}
272+
237273
if (Program.Pool.WaitOne())
238274
{
239275
// Resume the instance

src/Files.App/Services/Settings/AppSettingsService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ public bool ShowStatusCenterTeachingTip
2121
set => Set(value);
2222
}
2323

24+
public bool ShowBackgroundRunningNotification
25+
{
26+
get => Get(true);
27+
set => Set(value);
28+
}
29+
2430
public bool RestoreTabsOnStartup
2531
{
2632
get => Get(false);

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3685,4 +3685,10 @@
36853685
<data name="ChangeAlbumCover" xml:space="preserve">
36863686
<value>Change album cover</value>
36873687
</data>
3688+
<data name="BackgroundRunningNotificationBody" xml:space="preserve">
3689+
<value>Files is still running in the background to improve startup performance.</value>
3690+
</data>
3691+
<data name="BackgroundRunningNotificationHeader" xml:space="preserve">
3692+
<value>Where did Files go?</value>
3693+
</data>
36883694
</root>

src/Files.Core/Services/Settings/IAppSettingsService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ public interface IAppSettingsService : IBaseSettingsService, INotifyPropertyChan
1010
/// </summary>
1111
bool ShowStatusCenterTeachingTip { get; set; }
1212

13+
/// <summary>
14+
/// Gets or sets a value indicating whether or not to show the notification to inform background running.
15+
/// </summary>
16+
bool ShowBackgroundRunningNotification { get; set; }
17+
1318
/// <summary>
1419
/// Gets or sets a value indicating whether or not to restore tabs on startup.
1520
/// This is used when prompting users to restart after changing the app language.

0 commit comments

Comments
 (0)