Skip to content
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
14 changes: 10 additions & 4 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2012,11 +2012,17 @@
<data name="Behaviors" xml:space="preserve">
<value>Behaviors</value>
</data>
<data name="ReviewFiles" xml:space="preserve">
<value>Review Files</value>
<data name="ReviewFilesTitle" xml:space="preserve">
<value>Hello!</value>
</data>
<data name="ReviewFilesContent" xml:space="preserve">
<value>Would you like to review Files?</value>
<data name="ReviewFilesSubtitle" xml:space="preserve">
<value>Enjoying Files? Please consider reviewing in the Microsoft Store.</value>
</data>
<data name="RateUs" xml:space="preserve">
<value>Rate us</value>
</data>
<data name="Dismiss" xml:space="preserve">
<value>Dismiss</value>
</data>
<data name="SetAsBackgroundFlyout" xml:space="preserve">
<value>Set as background</value>
Expand Down
37 changes: 37 additions & 0 deletions src/Files.App/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
using Microsoft.UI.Xaml.Media.Imaging;
using Microsoft.UI.Xaml.Navigation;
using System.Windows.Input;
using Windows.ApplicationModel;
using Windows.Services.Store;
using Windows.System;
using WinRT.Interop;

namespace Files.App.ViewModels
{
Expand Down Expand Up @@ -127,16 +130,31 @@ context.PageType is not ContentPageTypes.Home &&
context.PageType is not ContentPageTypes.ReleaseNotes &&
context.PageType is not ContentPageTypes.Settings;

public bool ShowReviewPrompt
{
get
{
var isTargetPackage = Package.Current.Id.Name == "49306atecsolution.FilesUWP" || Package.Current.Id.Name == "49306atecsolution.FilesPreview";
var hasNotClickedReview = !UserSettingsService.ApplicationSettingsService.ClickedToReviewApp;
var launchCountReached = AppLifecycleHelper.TotalLaunchCount == 30;

return isTargetPackage && hasNotClickedReview && launchCountReached;
}
}

// Commands

public ICommand NavigateToNumberedTabKeyboardAcceleratorCommand { get; }
public ICommand ReviewAppCommand { get; }
public ICommand DismissReviewPromptCommand { get; }

// Constructor

public MainPageViewModel()
{
NavigateToNumberedTabKeyboardAcceleratorCommand = new RelayCommand<KeyboardAcceleratorInvokedEventArgs>(ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand);
ReviewAppCommand = new RelayCommand(ExecuteReviewAppCommand);
DismissReviewPromptCommand = new RelayCommand(ExecuteDismissReviewPromptCommand);

AppearanceSettingsService.PropertyChanged += (s, e) =>
{
Expand Down Expand Up @@ -302,6 +320,25 @@ await Task.WhenAll(

// Command methods

private async void ExecuteReviewAppCommand()
{
UserSettingsService.ApplicationSettingsService.ClickedToReviewApp = true;
OnPropertyChanged(nameof(ShowReviewPrompt));

try
{
var storeContext = StoreContext.GetDefault();
InitializeWithWindow.Initialize(storeContext, MainWindow.Instance.WindowHandle);
await storeContext.RequestRateAndReviewAppAsync();
}
catch (Exception) { }
}

private void ExecuteDismissReviewPromptCommand()
{
UserSettingsService.ApplicationSettingsService.ClickedToReviewApp = true;
}

private async void ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand(KeyboardAcceleratorInvokedEventArgs? e)
{
var indexToSelect = e!.KeyboardAccelerator.Key switch
Expand Down
13 changes: 13 additions & 0 deletions src/Files.App/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,19 @@
</controls:SidebarView.Footer>
</controls:SidebarView>

<!-- Review Files Prompt -->
<TeachingTip
Title="{helpers:ResourceString Name=ReviewFilesTitle}"
Grid.RowSpan="3"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
ActionButtonCommand="{x:Bind ViewModel.ReviewAppCommand}"
ActionButtonContent="{helpers:ResourceString Name=RateUs}"
CloseButtonCommand="{x:Bind ViewModel.DismissReviewPromptCommand}"
CloseButtonContent="{helpers:ResourceString Name=Dismiss}"
IsOpen="{x:Bind ViewModel.ShowReviewPrompt, Mode=OneWay}"
Subtitle="{helpers:ResourceString Name=ReviewFilesSubtitle}" />

<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SidebarWidthStates">
<VisualState x:Name="SmallSidebarWidthState">
Expand Down
55 changes: 4 additions & 51 deletions src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@
// Licensed under the MIT License.

using CommunityToolkit.WinUI;
using CommunityToolkit.WinUI.Helpers;
using CommunityToolkit.WinUI.Controls;
using Files.App.Controls;
using Microsoft.Extensions.Logging;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Windows.ApplicationModel;
using Windows.Foundation.Metadata;
using Windows.Graphics;
using Windows.Services.Store;
using WinRT.Interop;
using VirtualKey = Windows.System.VirtualKey;
using GridSplitter = Files.App.Controls.GridSplitter;
using Files.App.Controls;
using Microsoft.UI.Xaml.Media;
using VirtualKey = Windows.System.VirtualKey;

namespace Files.App.Views
{
Expand Down Expand Up @@ -59,37 +54,6 @@ public MainPage()
ApplySidebarWidthState();
}

private async Task PromptForReviewAsync()
{
var promptForReviewDialog = new ContentDialog
{
Title = Strings.ReviewFiles.ToLocalized(),
Content = Strings.ReviewFilesContent.ToLocalized(),
PrimaryButtonText = Strings.Yes.ToLocalized(),
SecondaryButtonText = Strings.No.ToLocalized()
};

if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
promptForReviewDialog.XamlRoot = MainWindow.Instance.Content.XamlRoot;

var result = await promptForReviewDialog.TryShowAsync();

if (result == ContentDialogResult.Primary)
{
try
{
var storeContext = StoreContext.GetDefault();
InitializeWithWindow.Initialize(storeContext, MainWindow.Instance.WindowHandle);
var storeRateAndReviewResult = await storeContext.RequestRateAndReviewAppAsync();

App.Logger.LogInformation($"STORE: review request status: {storeRateAndReviewResult.Status}");

UserSettingsService.ApplicationSettingsService.ClickedToReviewApp = true;
}
catch (Exception) { }
}
}

private async Task AppRunningAsAdminPromptAsync()
{
var runningAsAdminPrompt = new ContentDialog
Expand Down Expand Up @@ -250,7 +214,7 @@ private async Task OnPreviewKeyDownAsync(KeyRoutedEventArgs e)

if (command.Code is CommandCodes.OpenItem && source?.FindAscendantOrSelf<PathBreadcrumb>() is not null)
break;


if (command.Code is not CommandCodes.None && keyReleased)
{
Expand Down Expand Up @@ -310,17 +274,6 @@ AppLifecycleHelper.AppEnvironment is not AppEnvironment.Dev &&
{
DispatcherQueue.TryEnqueue(async () => await AppRunningAsAdminPromptAsync());
}

// ToDo put this in a StartupPromptService
if (Package.Current.Id.Name != "49306atecsolution.FilesUWP" || UserSettingsService.ApplicationSettingsService.ClickedToReviewApp)
return;

var totalLaunchCount = AppLifecycleHelper.TotalLaunchCount;
if (totalLaunchCount is 50 or 200)
{
// Prompt user to review app in the Store
DispatcherQueue.TryEnqueue(async () => await PromptForReviewAsync());
}
}

private void PreviewPane_Loaded(object sender, RoutedEventArgs e)
Expand Down
Loading