Skip to content

Commit edb945b

Browse files
authored
Code Quality: Added sponsor flyout for sideload versions (#17240)
1 parent 8020434 commit edb945b

File tree

7 files changed

+71
-13
lines changed

7 files changed

+71
-13
lines changed

src/Files.App/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public static class ExternalUrl
205205
public const string FeatureRequestUrl = @"https://github.com/files-community/Files/issues/new?labels=feature+request&template=feature_request.yml";
206206
public const string BugReportUrl = @"https://github.com/files-community/Files/issues/new?labels=bug&template=bug_report.yml";
207207
public const string PrivacyPolicyUrl = @"https://files.community/privacy";
208-
public const string SupportUsUrl = @"https://github.com/sponsors/yaira2";
208+
public const string SupportUsUrl = @"https://github.com/files-community/Files?sponsor";
209209
public const string CrowdinUrl = @"https://crowdin.com/project/files-app";
210210
public static readonly string ReleaseNotesUrl= $"https://files.community/blog/posts/v{Package.Current.Id.Version.Major}-{Package.Current.Id.Version.Minor}-{Package.Current.Id.Version.Build}?minimal";
211211
}

src/Files.App/Data/Contracts/IApplicationSettingsService.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ namespace Files.App.Data.Contracts
66
public interface IApplicationSettingsService : IBaseSettingsService
77
{
88
/// <summary>
9-
/// Gets or sets a value indicating whether or not the user clicked to review the app.
9+
/// Gets or sets a value indicating whether or not the user clicked the 'review' prompt.
1010
/// </summary>
11-
bool ClickedToReviewApp { get; set; }
11+
bool HasClickedReviewPrompt { get; set; }
12+
13+
/// <summary>
14+
/// Gets or sets a value indicating whether or not the user clicked the 'sponsor' prompt.
15+
/// </summary>
16+
bool HasClickedSponsorPrompt { get; set; }
1217

1318
/// <summary>
1419
/// Gets or sets a value indicating whether or not to display a prompt when running the app as administrator.

src/Files.App/Helpers/Application/AppLifecycleHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ static AppLifecycleHelper()
6161
{
6262
IsAppUpdated = version.ToString() != AppVersion.ToString();
6363
}
64-
TotalLaunchCount = launchCount is long l ? l + 1 : 1;
64+
65+
TotalLaunchCount = long.TryParse(launchCount?.ToString(), out var v) ? v + 1 : 1;
6566
infoKey.SetValue("LastLaunchVersion", AppVersion.ToString());
6667
infoKey.SetValue("TotalLaunchCount", TotalLaunchCount);
6768
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ namespace Files.App.Services.Settings
88
{
99
internal sealed partial class ApplicationSettingsService : BaseObservableJsonSettings, IApplicationSettingsService
1010
{
11-
public bool ClickedToReviewApp
11+
public bool HasClickedReviewPrompt
12+
{
13+
get => Get(false);
14+
set => Set(value);
15+
}
16+
17+
public bool HasClickedSponsorPrompt
1218
{
1319
get => Get(false);
1420
set => Set(value);

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

Lines changed: 7 additions & 1 deletion
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="ReviewFilesTitle" xml:space="preserve">
2015+
<data name="Hello" xml:space="preserve">
20162016
<value>Hello!</value>
20172017
</data>
20182018
<data name="ReviewFilesSubtitle" xml:space="preserve">
20192019
<value>Enjoying Files? Please consider reviewing in the Microsoft Store.</value>
2020+
</data>
2021+
<data name="SponsorSubtitle" xml:space="preserve">
2022+
<value>Enjoying Files? Please consider supporting the project on GitHub.</value>
2023+
</data>
2024+
<data name="Sponsor" xml:space="preserve">
2025+
<value>Sponsor</value>
20202026
</data>
20212027
<data name="RateUs" xml:space="preserve">
20222028
<value>Rate us</value>

src/Files.App/ViewModels/MainPageViewModel.cs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Microsoft.UI.Xaml.Media.Imaging;
99
using Microsoft.UI.Xaml.Navigation;
1010
using System.Windows.Input;
11-
using Windows.ApplicationModel;
1211
using Windows.Services.Store;
1312
using Windows.System;
1413
using WinRT.Interop;
@@ -134,11 +133,23 @@ public bool ShowReviewPrompt
134133
{
135134
get
136135
{
137-
var isTargetPackage = Package.Current.Id.Name == "49306atecsolution.FilesUWP" || Package.Current.Id.Name == "49306atecsolution.FilesPreview";
138-
var hasNotClickedReview = !UserSettingsService.ApplicationSettingsService.ClickedToReviewApp;
136+
var isTargetEnvironment = AppLifecycleHelper.AppEnvironment is AppEnvironment.StoreStable or AppEnvironment.StorePreview;
137+
var hasClickedReviewPrompt = UserSettingsService.ApplicationSettingsService.HasClickedReviewPrompt;
139138
var launchCountReached = AppLifecycleHelper.TotalLaunchCount == 30;
140139

141-
return isTargetPackage && hasNotClickedReview && launchCountReached;
140+
return isTargetEnvironment && !hasClickedReviewPrompt && launchCountReached;
141+
}
142+
}
143+
144+
public bool ShowSponsorPrompt
145+
{
146+
get
147+
{
148+
var isTargetEnvironment = AppLifecycleHelper.AppEnvironment is AppEnvironment.Dev or AppEnvironment.SideloadStable or AppEnvironment.SideloadPreview;
149+
var hasClickedSponsorPrompt = UserSettingsService.ApplicationSettingsService.HasClickedSponsorPrompt;
150+
var launchCountReached = AppLifecycleHelper.TotalLaunchCount == 30;
151+
152+
return isTargetEnvironment && !hasClickedSponsorPrompt && launchCountReached;
142153
}
143154
}
144155

@@ -147,6 +158,8 @@ public bool ShowReviewPrompt
147158
public ICommand NavigateToNumberedTabKeyboardAcceleratorCommand { get; }
148159
public ICommand ReviewAppCommand { get; }
149160
public ICommand DismissReviewPromptCommand { get; }
161+
public ICommand SponsorCommand { get; }
162+
public ICommand DismissSponsorPromptCommand { get; }
150163

151164
// Constructor
152165

@@ -155,6 +168,8 @@ public MainPageViewModel()
155168
NavigateToNumberedTabKeyboardAcceleratorCommand = new RelayCommand<KeyboardAcceleratorInvokedEventArgs>(ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand);
156169
ReviewAppCommand = new RelayCommand(ExecuteReviewAppCommand);
157170
DismissReviewPromptCommand = new RelayCommand(ExecuteDismissReviewPromptCommand);
171+
SponsorCommand = new RelayCommand(ExecuteSponsorCommand);
172+
DismissSponsorPromptCommand = new RelayCommand(ExecuteDismissSponsorPromptCommand);
158173

159174
AppearanceSettingsService.PropertyChanged += (s, e) =>
160175
{
@@ -322,7 +337,7 @@ await Task.WhenAll(
322337

323338
private async void ExecuteReviewAppCommand()
324339
{
325-
UserSettingsService.ApplicationSettingsService.ClickedToReviewApp = true;
340+
UserSettingsService.ApplicationSettingsService.HasClickedReviewPrompt = true;
326341
OnPropertyChanged(nameof(ShowReviewPrompt));
327342

328343
try
@@ -336,7 +351,19 @@ private async void ExecuteReviewAppCommand()
336351

337352
private void ExecuteDismissReviewPromptCommand()
338353
{
339-
UserSettingsService.ApplicationSettingsService.ClickedToReviewApp = true;
354+
UserSettingsService.ApplicationSettingsService.HasClickedReviewPrompt = true;
355+
}
356+
357+
private async void ExecuteSponsorCommand()
358+
{
359+
UserSettingsService.ApplicationSettingsService.HasClickedSponsorPrompt = true;
360+
OnPropertyChanged(nameof(ShowSponsorPrompt));
361+
await Launcher.LaunchUriAsync(new Uri(Constants.ExternalUrl.SupportUsUrl)).AsTask();
362+
}
363+
364+
private void ExecuteDismissSponsorPromptCommand()
365+
{
366+
UserSettingsService.ApplicationSettingsService.HasClickedSponsorPrompt = true;
340367
}
341368

342369
private async void ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand(KeyboardAcceleratorInvokedEventArgs? e)

src/Files.App/Views/MainPage.xaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@
368368

369369
<!-- Review Files Prompt -->
370370
<TeachingTip
371-
Title="{helpers:ResourceString Name=ReviewFilesTitle}"
371+
Title="{helpers:ResourceString Name=Hello}"
372372
Grid.RowSpan="3"
373373
HorizontalAlignment="Center"
374374
VerticalAlignment="Bottom"
@@ -379,6 +379,19 @@
379379
IsOpen="{x:Bind ViewModel.ShowReviewPrompt, Mode=OneWay}"
380380
Subtitle="{helpers:ResourceString Name=ReviewFilesSubtitle}" />
381381

382+
<!-- Sponsor Prompt -->
383+
<TeachingTip
384+
Title="{helpers:ResourceString Name=Hello}"
385+
Grid.RowSpan="3"
386+
HorizontalAlignment="Center"
387+
VerticalAlignment="Bottom"
388+
ActionButtonCommand="{x:Bind ViewModel.SponsorCommand}"
389+
ActionButtonContent="{helpers:ResourceString Name=Sponsor}"
390+
CloseButtonCommand="{x:Bind ViewModel.DismissSponsorPromptCommand}"
391+
CloseButtonContent="{helpers:ResourceString Name=Dismiss}"
392+
IsOpen="{x:Bind ViewModel.ShowSponsorPrompt, Mode=OneWay}"
393+
Subtitle="{helpers:ResourceString Name=SponsorSubtitle}" />
394+
382395
<VisualStateManager.VisualStateGroups>
383396
<VisualStateGroup x:Name="SidebarWidthStates">
384397
<VisualState x:Name="SmallSidebarWidthState">

0 commit comments

Comments
 (0)