Skip to content

Commit c65a77f

Browse files
authored
Feature: Less annoying review prompt (#17212)
1 parent a980200 commit c65a77f

File tree

4 files changed

+64
-55
lines changed

4 files changed

+64
-55
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,11 +2012,17 @@
20122012
<data name="Behaviors" xml:space="preserve">
20132013
<value>Behaviors</value>
20142014
</data>
2015-
<data name="ReviewFiles" xml:space="preserve">
2016-
<value>Review Files</value>
2015+
<data name="ReviewFilesTitle" xml:space="preserve">
2016+
<value>Hello!</value>
20172017
</data>
2018-
<data name="ReviewFilesContent" xml:space="preserve">
2019-
<value>Would you like to review Files?</value>
2018+
<data name="ReviewFilesSubtitle" xml:space="preserve">
2019+
<value>Enjoying Files? Please consider reviewing in the Microsoft Store.</value>
2020+
</data>
2021+
<data name="RateUs" xml:space="preserve">
2022+
<value>Rate us</value>
2023+
</data>
2024+
<data name="Dismiss" xml:space="preserve">
2025+
<value>Dismiss</value>
20202026
</data>
20212027
<data name="SetAsBackgroundFlyout" xml:space="preserve">
20222028
<value>Set as background</value>

src/Files.App/ViewModels/MainPageViewModel.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
using Microsoft.UI.Xaml.Media.Imaging;
99
using Microsoft.UI.Xaml.Navigation;
1010
using System.Windows.Input;
11+
using Windows.ApplicationModel;
12+
using Windows.Services.Store;
1113
using Windows.System;
14+
using WinRT.Interop;
1215

1316
namespace Files.App.ViewModels
1417
{
@@ -127,16 +130,31 @@ context.PageType is not ContentPageTypes.Home &&
127130
context.PageType is not ContentPageTypes.ReleaseNotes &&
128131
context.PageType is not ContentPageTypes.Settings;
129132

133+
public bool ShowReviewPrompt
134+
{
135+
get
136+
{
137+
var isTargetPackage = Package.Current.Id.Name == "49306atecsolution.FilesUWP" || Package.Current.Id.Name == "49306atecsolution.FilesPreview";
138+
var hasNotClickedReview = !UserSettingsService.ApplicationSettingsService.ClickedToReviewApp;
139+
var launchCountReached = AppLifecycleHelper.TotalLaunchCount == 30;
140+
141+
return isTargetPackage && hasNotClickedReview && launchCountReached;
142+
}
143+
}
130144

131145
// Commands
132146

133147
public ICommand NavigateToNumberedTabKeyboardAcceleratorCommand { get; }
148+
public ICommand ReviewAppCommand { get; }
149+
public ICommand DismissReviewPromptCommand { get; }
134150

135151
// Constructor
136152

137153
public MainPageViewModel()
138154
{
139155
NavigateToNumberedTabKeyboardAcceleratorCommand = new RelayCommand<KeyboardAcceleratorInvokedEventArgs>(ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand);
156+
ReviewAppCommand = new RelayCommand(ExecuteReviewAppCommand);
157+
DismissReviewPromptCommand = new RelayCommand(ExecuteDismissReviewPromptCommand);
140158

141159
AppearanceSettingsService.PropertyChanged += (s, e) =>
142160
{
@@ -302,6 +320,25 @@ await Task.WhenAll(
302320

303321
// Command methods
304322

323+
private async void ExecuteReviewAppCommand()
324+
{
325+
UserSettingsService.ApplicationSettingsService.ClickedToReviewApp = true;
326+
OnPropertyChanged(nameof(ShowReviewPrompt));
327+
328+
try
329+
{
330+
var storeContext = StoreContext.GetDefault();
331+
InitializeWithWindow.Initialize(storeContext, MainWindow.Instance.WindowHandle);
332+
await storeContext.RequestRateAndReviewAppAsync();
333+
}
334+
catch (Exception) { }
335+
}
336+
337+
private void ExecuteDismissReviewPromptCommand()
338+
{
339+
UserSettingsService.ApplicationSettingsService.ClickedToReviewApp = true;
340+
}
341+
305342
private async void ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand(KeyboardAcceleratorInvokedEventArgs? e)
306343
{
307344
var indexToSelect = e!.KeyboardAccelerator.Key switch

src/Files.App/Views/MainPage.xaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,19 @@
366366
</controls:SidebarView.Footer>
367367
</controls:SidebarView>
368368

369+
<!-- Review Files Prompt -->
370+
<TeachingTip
371+
Title="{helpers:ResourceString Name=ReviewFilesTitle}"
372+
Grid.RowSpan="3"
373+
HorizontalAlignment="Center"
374+
VerticalAlignment="Bottom"
375+
ActionButtonCommand="{x:Bind ViewModel.ReviewAppCommand}"
376+
ActionButtonContent="{helpers:ResourceString Name=RateUs}"
377+
CloseButtonCommand="{x:Bind ViewModel.DismissReviewPromptCommand}"
378+
CloseButtonContent="{helpers:ResourceString Name=Dismiss}"
379+
IsOpen="{x:Bind ViewModel.ShowReviewPrompt, Mode=OneWay}"
380+
Subtitle="{helpers:ResourceString Name=ReviewFilesSubtitle}" />
381+
369382
<VisualStateManager.VisualStateGroups>
370383
<VisualStateGroup x:Name="SidebarWidthStates">
371384
<VisualState x:Name="SmallSidebarWidthState">

src/Files.App/Views/MainPage.xaml.cs

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@
22
// Licensed under the MIT License.
33

44
using CommunityToolkit.WinUI;
5-
using CommunityToolkit.WinUI.Helpers;
6-
using CommunityToolkit.WinUI.Controls;
5+
using Files.App.Controls;
76
using Microsoft.Extensions.Logging;
87
using Microsoft.UI.Dispatching;
98
using Microsoft.UI.Input;
109
using Microsoft.UI.Xaml;
1110
using Microsoft.UI.Xaml.Controls;
1211
using Microsoft.UI.Xaml.Input;
12+
using Microsoft.UI.Xaml.Media;
1313
using Microsoft.UI.Xaml.Navigation;
14-
using Windows.ApplicationModel;
1514
using Windows.Foundation.Metadata;
1615
using Windows.Graphics;
17-
using Windows.Services.Store;
18-
using WinRT.Interop;
19-
using VirtualKey = Windows.System.VirtualKey;
2016
using GridSplitter = Files.App.Controls.GridSplitter;
21-
using Files.App.Controls;
22-
using Microsoft.UI.Xaml.Media;
17+
using VirtualKey = Windows.System.VirtualKey;
2318

2419
namespace Files.App.Views
2520
{
@@ -59,37 +54,6 @@ public MainPage()
5954
ApplySidebarWidthState();
6055
}
6156

62-
private async Task PromptForReviewAsync()
63-
{
64-
var promptForReviewDialog = new ContentDialog
65-
{
66-
Title = Strings.ReviewFiles.ToLocalized(),
67-
Content = Strings.ReviewFilesContent.ToLocalized(),
68-
PrimaryButtonText = Strings.Yes.ToLocalized(),
69-
SecondaryButtonText = Strings.No.ToLocalized()
70-
};
71-
72-
if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
73-
promptForReviewDialog.XamlRoot = MainWindow.Instance.Content.XamlRoot;
74-
75-
var result = await promptForReviewDialog.TryShowAsync();
76-
77-
if (result == ContentDialogResult.Primary)
78-
{
79-
try
80-
{
81-
var storeContext = StoreContext.GetDefault();
82-
InitializeWithWindow.Initialize(storeContext, MainWindow.Instance.WindowHandle);
83-
var storeRateAndReviewResult = await storeContext.RequestRateAndReviewAppAsync();
84-
85-
App.Logger.LogInformation($"STORE: review request status: {storeRateAndReviewResult.Status}");
86-
87-
UserSettingsService.ApplicationSettingsService.ClickedToReviewApp = true;
88-
}
89-
catch (Exception) { }
90-
}
91-
}
92-
9357
private async Task AppRunningAsAdminPromptAsync()
9458
{
9559
var runningAsAdminPrompt = new ContentDialog
@@ -250,7 +214,7 @@ private async Task OnPreviewKeyDownAsync(KeyRoutedEventArgs e)
250214

251215
if (command.Code is CommandCodes.OpenItem && source?.FindAscendantOrSelf<PathBreadcrumb>() is not null)
252216
break;
253-
217+
254218

255219
if (command.Code is not CommandCodes.None && keyReleased)
256220
{
@@ -310,17 +274,6 @@ AppLifecycleHelper.AppEnvironment is not AppEnvironment.Dev &&
310274
{
311275
DispatcherQueue.TryEnqueue(async () => await AppRunningAsAdminPromptAsync());
312276
}
313-
314-
// ToDo put this in a StartupPromptService
315-
if (Package.Current.Id.Name != "49306atecsolution.FilesUWP" || UserSettingsService.ApplicationSettingsService.ClickedToReviewApp)
316-
return;
317-
318-
var totalLaunchCount = AppLifecycleHelper.TotalLaunchCount;
319-
if (totalLaunchCount is 50 or 200)
320-
{
321-
// Prompt user to review app in the Store
322-
DispatcherQueue.TryEnqueue(async () => await PromptForReviewAsync());
323-
}
324277
}
325278

326279
private void PreviewPane_Loaded(object sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)