Skip to content

A Swiss Army knife for developers.

Added a way to automatically offer the user to rate the app (#62)

Etienne Baudoux86f48b0ba157
diff --git a/README.md b/README.md
index 31454df12..964ad34b2 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,7 @@ DevToys helps in everyday tasks like formatting JSON, comparing text, testing Re
Many tools are available.
- Base 64 Encoder/Decoder
- Hash Generator (MD5, SHA1, SHA256, SHA512)
+- Guid Generator
- JWT Decoder
- Json Formatter
- RegExp Tester
@@ -67,6 +68,7 @@ For example, `start devtoys:?tool=jsonyaml` will open DevToys and start on the `
Here is the list of tool name you can use:
- `base64` - Base64 Encoder/Decoder
- `hash` - Hash Generator
+- `guid` - Guid Generator
- `jsonformat` Json Formatter
- `jsonyaml` - Json <> Yaml
- `jwt` - JWT Decoder
diff --git a/src/dev/impl/DevToys/Api/Core/IMarketingService.cs b/src/dev/impl/DevToys/Api/Core/IMarketingService.cs
new file mode 100644
index 000000000..9b2057816
--- /dev/null
+++ b/src/dev/impl/DevToys/Api/Core/IMarketingService.cs
@@ -0,0 +1,27 @@
+#nullable enable
+
+using System.Threading.Tasks;
+
+namespace DevToys.Api.Core
+{
+ /// <summary>
+ /// Provides a service that help to generate positive review of the DevToys app.
+ /// </summary>
+ /// <remarks>
+ /// This service should be called when the app started, crashed, successfuly performed a task.
+ /// By monitoring these events, the service will try to decide of the most ideal moment
+ /// for proposing to the user to share constructive feedback to the developer.
+ /// </remarks>
+ public interface IMarketingService
+ {
+ Task NotifyAppEncounteredAProblemAsync();
+
+ void NotifyToolSuccessfullyWorked();
+
+ void NotifyAppJustUpdated();
+
+ void NotifyAppStarted();
+
+ void NotifySmartDetectionWorked();
+ }
+}
diff --git a/src/dev/impl/DevToys/App.xaml.cs b/src/dev/impl/DevToys/App.xaml.cs
index 0e6a30705..2caec4c7a 100644
--- a/src/dev/impl/DevToys/App.xaml.cs
+++ b/src/dev/impl/DevToys/App.xaml.cs
@@ -30,8 +30,9 @@ namespace DevToys
sealed partial class App : Application, IDisposable
{
private readonly Task<MefComposer> _mefComposer;
- private readonly Lazy<Task<IThemeListener>> _themeListener;
- private readonly Lazy<Task<ISettingsProvider>> _settingsProvider;
+ private readonly AsyncLazy<IThemeListener> _themeListener;
+ private readonly AsyncLazy<ISettingsProvider> _settingsProvider;
+ private readonly AsyncLazy<IMarketingService> _marketingService;
private bool _isDisposed;
@@ -56,8 +57,9 @@ namespace DevToys
UnhandledException += OnUnhandledException;
// Importing it in a Lazy because we can't import it before a Window is created.
- _themeListener = new Lazy<Task<IThemeListener>>(async () => (await _mefComposer).ExportProvider.GetExport<IThemeListener>());
- _settingsProvider = new Lazy<Task<ISettingsProvider>>(async () => (await _mefComposer).ExportProvider.GetExport<ISettingsProvider>());
+ _themeListener = new AsyncLazy<IThemeListener>(async () => (await _mefComposer).ExportProvider.GetExport<IThemeListener>());
+ _settingsProvider = new AsyncLazy<ISettingsProvider>(async () => (await _mefComposer).ExportProvider.GetExport<ISettingsProvider>());
+ _marketingService = new AsyncLazy<IMarketingService>(async () => (await _mefComposer).ExportProvider.GetExport<IMarketingService>());
InitializeComponent();
Suspending += OnSuspending;
@@ -179,9 +181,10 @@ namespace DevToys
deferral.Complete();
}
- private void OnUnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
+ private async void OnUnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
{
Logger.LogFault("Unhandled problem", e.Exception);
+ await (await _marketingService.GetValueAsync()).NotifyAppEncounteredAProblemAsync();
}
private async Task<Frame> EnsureWindowIsInitializedAsync()
@@ -210,7 +213,7 @@ namespace DevToys
LanguageManager.Instance.SetCurrentCulture(languageDefinition);
// Apply the app color theme.
- (await _themeListener.Value).ApplyDesiredColorTheme();
+ (await _themeListener.GetValueAsync()).ApplyDesiredColorTheme();
// Change the text editor font if the current font isn't available on the system.
ValidateDefaultTextEditorFontAsync().Forget();
@@ -240,7 +243,7 @@ namespace DevToys
{
await TaskScheduler.Default;
- ISettingsProvider settingsProvider = await _settingsProvider.Value;
+ ISettingsProvider settingsProvider = await _settingsProvider.GetValueAsync();
string currentFont = settingsProvider.GetSetting(PredefinedSettings.TextEditorFont);
string[] systemFonts = CanvasTextFormat.GetSystemFontFamilies();
diff --git a/src/dev/impl/DevToys/Core/MarketingService.cs b/src/dev/impl/DevToys/Core/MarketingService.cs
new file mode 100644
index 000000000..51d6eaec4
--- /dev/null
+++ b/src/dev/impl/DevToys/Core/MarketingService.cs
@@ -0,0 +1,297 @@
+#nullable enable
+
+using DevToys.Api.Core;
+using DevToys.Core.Threading;
+using DevToys.Models;
+using Newtonsoft.Json;
+using System;
+using System.Composition;
+using System.Threading;
+using System.Threading.Tasks;
+using Windows.Services.Store;
+using Windows.Storage;
+
+namespace DevToys.Core
+{
+ [Export(typeof(IMarketingService))]
+ [Shared]
+ internal sealed class MarketingService : IMarketingService, IDisposable
+ {
+ private const string StoredFileName = "marketingInfo.json";
+
+ private readonly INotificationService _notificationService;
+ private readonly DisposableSempahore _semaphore = new DisposableSempahore();
+ private readonly object _lock = new object();
+
+ private bool _rateOfferInProgress;
+ private AsyncLazy<MarketingState> _marketingState;
+
+ [ImportingConstructor]
+ public MarketingService(INotificationService notificationService)
+ {
+ _notificationService = notificationService;
+ _marketingState = new AsyncLazy<MarketingState>(LoadStateAsync);
+ }
+
+ public void Dispose()
+ {
+ _semaphore.Dispose();
+ }
+
+ public async Task NotifyAppEncounteredAProblemAsync()
+ {
+ await UpdateMarketingStateAsync(state =>
+ {
+ state.LastProblemEncounteredDate = DateTime.Now;
+ state.StartSinceLastProblemEncounteredCount = 0;
+ });
+ }
+
+ public void NotifyAppJustUpdated()
+ {
+ UpdateMarketingStateAsync(state =>
+ {
+ state.LastUpdateDate = DateTime.Now;
+ }).ForgetSafely();
+ }
+
+ public void NotifyAppStarted()
+ {
+ UpdateMarketingStateAsync(state =>
+ {
+ state.StartSinceLastProblemEncounteredCount++;
+ }).ForgetSafely();
+ }
+
+ public void NotifySmartDetectionWorked()
+ {
+ UpdateMarketingStateAsync(state =>
+ {
+ state.SmartDetectionCount++;
+ }).ContinueWith(_ =>
+ {
+ TryOfferUserToRateApp();
+ }).ForgetSafely();
+ }
+
+ public void NotifyToolSuccessfullyWorked()
+ {
+ UpdateMarketingStateAsync(state =>
+ {
+ state.ToolSuccessfulyWorkedCount++;
+ }).ContinueWith(_ =>
+ {
+ TryOfferUserToRateApp();
+ }).ForgetSafely();
+ }
+
+ private void TryOfferUserToRateApp()
+ {
+ lock (_lock)
+ {
+ if (_rateOfferInProgress)
+ {
+ return;
+ }
+
+ if (_marketingState.IsValueCreated
+ && DetermineWhetherAppRatingShouldBeOffered(_marketingState.GetValueAsync().Result))
+ {
+ _rateOfferInProgress = true;
+
+ _notificationService.ShowInAppNotification(
+ LanguageManager.Instance.MainPage.NotificationRateAppTitle,
+ LanguageManager.Instance.MainPage.NotificationRateAppActionableActionText,
+ () =>
+ {
+ RateAsync().ForgetSafely();
+ },
+ LanguageManager.Instance.MainPage.NotificationRateAppMessage);
+ }
+ }
+ }
+
+ private async Task RateAsync()
+ {
+ await UpdateMarketingStateAsync(state =>
+ {
+ state.AppRatingOfferCount++;
+ state.LastAppRatingOfferDate = DateTime.Now;
+ });
+
+ StoreContext storeContext = StoreContext.GetDefault();
+
+ StoreRateAndReviewResult result = await ThreadHelper.RunOnUIThreadAsync(async () =>
+ {
+ return await storeContext.RequestRateAndReviewAppAsync();
+ }).ConfigureAwait(false);
+
+ if (result.Status == StoreRateAndReviewStatus.Succeeded)
+ {
+ await UpdateMarketingStateAsync(state =>
+ {
+ state.AppGotRated = true;
+ });
+ }
+
+ lock (_lock)
+ {
+ _rateOfferInProgress = false;
+ }
+ }
+
+ private bool DetermineWhetherAppRatingShouldBeOffered(MarketingState state)
+ {
+ // The user already rated the app. Let's not offer him to rate it again.
+ if (state.AppGotRated)
+ {
+ return false;
+ }
+
+ // We already offered the user to rate the app many times.
+ // It's very unlikely that he will rate it at this point. Let's stop asking.
+ if (state.AppRatingOfferCount >= 10)
+ {
+ return false;
+ }
+
+ // If it's been less than 8 days since the last time the app crashed or that the app
+ // has been installed on the machine. Let's not ask the user to rate the app.
+ if (DateTime.Now - state.LastProblemEncounteredDate < TimeSpan.FromDays(8))
+ {
+ return false;
+ }
+
+ // If the app have been started less than 4 times since the last crash or since the app
+ // got installed on the machine, let's not ask the user to rate the app.
+ if (state.StartSinceLastProblemEncounteredCount < 4)
+ {
+ return false;
+ }
+
+ // The app got updated 2 days ago. Potentially, we introduced some instability (not necessarily crash,
+ // but maybe visual issues, inconsistencies...etc).
+ // Let's make sure we don't offer the user to rate the app as soon as it got updated, just in case
+ // if the app is completely broken.
+ if (DateTime.Now - state.LastUpdateDate < TimeSpan.FromDays(2))
+ {
+ return false;
+ }
+
+ // Let's make sure we don't offer to rate the app more than once within 2 days.
+ if (state.AppRatingOfferCount > 0 && DateTime.Now - state.LastAppRatingOfferDate < TimeSpan.FromDays(2))
+ {
+ return false;
+ }
+
+ // If we already offered to rate the app more than 2 times, let's make sure we
+ // don't offer it again before the next 5 days.
+ if (state.AppRatingOfferCount > 2 && DateTime.Now - state.LastAppRatingOfferDate < TimeSpan.FromDays(5))
+ {
+ return false;
+ }
+
+ // If we already offered to rate the app more than 5 times, let's make sure we
+ // don't offer it again before the next 10 days.
+ if (state.AppRatingOfferCount > 5 && DateTime.Now - state.LastAppRatingOfferDate < TimeSpan.FromDays(10))
+ {
+ return false;
+ }
+
+ // If we already offered to rate the app more than 7 times, let's make sure we
+ // don't offer it again before the next 60 days.
+ if (state.AppRatingOfferCount > 7 && DateTime.Now - state.LastAppRatingOfferDate < TimeSpan.FromDays(60))
+ {
+ return false;
+ }
+
+ // Smart Detection has been used at least twice. Let's offer the use to rate the app.
+ if (state.SmartDetectionCount > 3)
+ {
+ return true;
+ }
+
+ // The user used tools at least 10 times already. Let's offer the use to rate the app.
+ if (state.ToolSuccessfulyWorkedCount > 10)
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ private async Task UpdateMarketingStateAsync(Action<MarketingState> updateAction)
+ {
+ await TaskScheduler.Default;
+
+ MarketingState state = await _marketingState.GetValueAsync();
+
+ using (await _semaphore.WaitAsync(CancellationToken.None))
+ {
+ updateAction(state);
+ }
+
+ await SaveStateAsync(state);
+ }
+
+ private async Task SaveStateAsync(MarketingState state)
+ {
+ await TaskScheduler.Default;
+
+ try
+ {
+ using (await _semaphore.WaitAsync(CancellationToken.None))
+ {
+ StorageFolder localCacheFolder = ApplicationData.Current.LocalCacheFolder;
+
+ StorageFile file = await localCacheFolder.CreateFileAsync(StoredFileName, CreationCollisionOption.ReplaceExisting);
+
+ string fileContent
+ = JsonConvert.SerializeObject(
+ state,
+ Formatting.Indented);
+
+ await FileIO.WriteTextAsync(file, fileContent);
+ }
+ }
+ catch (Exception)
+ {
+ }
+ }
+
+ private async Task<MarketingState> LoadStateAsync()
+ {
+ await TaskScheduler.Default;
+
+ try
+ {
+ using (await _semaphore.WaitAsync(CancellationToken.None))
+ {
+ StorageFolder localCacheFolder = ApplicationData.Current.LocalCacheFolder;
+
+ IStorageItem? file = await localCacheFolder.TryGetItemAsync(StoredFileName);
+
+ if (file is not null && file is StorageFile storageFile)
+ {
+ string fileContent = await FileIO.ReadTextAsync(storageFile);
+ var result = JsonConvert.DeserializeObject<MarketingState>(fileContent);
+ if (result is not null)
+ {
+ return result;
+ }
+ }
+ }
+ }
+ catch (Exception)
+ {
+ }
+
+ return new MarketingState
+ {
+ LastAppRatingOfferDate = DateTime.Now,
+ LastProblemEncounteredDate = DateTime.Now,
+ LastUpdateDate = DateTime.Now
+ };
+ }
+ }
+}
diff --git a/src/dev/impl/DevToys/Core/Threading/AsyncLazy.cs b/src/dev/impl/DevToys/Core/Threading/AsyncLazy.cs
new file mode 100644
index 000000000..a07837e9e
--- /dev/null
+++ b/src/dev/impl/DevToys/Core/Threading/AsyncLazy.cs
@@ -0,0 +1,57 @@
+#nullable enable
+
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace DevToys.Core.Threading
+{
+ internal sealed class AsyncLazy<T>
+ {
+ private static Func<Task<T>> FromFuncT(Func<T> valueFunc) => () => Task.FromResult(valueFunc());
+
+ private readonly Lazy<Task<T>> _innerLazy;
+
+ public bool IsValueCreated => _innerLazy.IsValueCreated && _innerLazy.Value.IsCompletedSuccessfully;
+
+ public AsyncLazy(T value)
+ {
+ _innerLazy = new Lazy<Task<T>>(Task.FromResult(value));
+ }
+
+ public AsyncLazy(Func<T> valueFactory)
+ {
+ _innerLazy = new Lazy<Task<T>>(FromFuncT(valueFactory));
+ }
+
+ public AsyncLazy(Func<T> valueFactory, bool isThreadSafe)
+ {
+ _innerLazy = new Lazy<Task<T>>(FromFuncT(valueFactory), isThreadSafe);
+ }
+
+ public AsyncLazy(Func<T> valueFactory, LazyThreadSafetyMode mode)
+ {
+ _innerLazy = new Lazy<Task<T>>(FromFuncT(valueFactory), mode);
+ }
+
+ public AsyncLazy(Func<Task<T>> valueFactory)
+ {
+ _innerLazy = new Lazy<Task<T>>(valueFactory);
+ }
+
+ public AsyncLazy(Func<Task<T>> valueFactory, bool isThreadSafe)
+ {
+ _innerLazy = new Lazy<Task<T>>(valueFactory, isThreadSafe);
+ }
+
+ public AsyncLazy(Func<Task<T>> valueFactory, LazyThreadSafetyMode mode)
+ {
+ _innerLazy = new Lazy<Task<T>>(valueFactory, mode);
+ }
+
+ public async Task<T> GetValueAsync()
+ {
+ return IsValueCreated? await _innerLazy.Value : _innerLazy.Value.Result;
+ }
+ }
+}
diff --git a/src/dev/impl/DevToys/DevToys.csproj b/src/dev/impl/DevToys/DevToys.csproj
index 62c69ab29..a6577c905 100644
--- a/src/dev/impl/DevToys/DevToys.csproj
+++ b/src/dev/impl/DevToys/DevToys.csproj
@@ -151,6 +151,7 @@
</Content>
<Content Include="Properties\Default.rd.rd.xml" />
<Compile Include="Api\Core\IClipboard.cs" />
+ <Compile Include="Api\Core\IMarketingService.cs" />
<Compile Include="Api\Core\IMefProvider.cs" />
<Compile Include="Api\Core\InAppNotificationAddedEventArgs.cs" />
<Compile Include="Api\Core\ITitleBar.cs" />
@@ -182,6 +183,7 @@
<Compile Include="Core\Collections\OrderedObservableCollection.cs" />
<Compile Include="Core\Constants.cs" />
<Compile Include="Core\Logger.cs" />
+ <Compile Include="Core\MarketingService.cs" />
<Compile Include="Core\MefComposer.cs" />
<Compile Include="Core\MefProvider.cs" />
<Compile Include="Core\Navigation\WindowManager.cs" />
@@ -189,6 +191,7 @@
<Compile Include="Core\Settings\PredefinedSettings.cs" />
<Compile Include="Core\Settings\SettingsProvider.cs" />
<Compile Include="Core\Theme\ThemeListener.cs" />
+ <Compile Include="Core\Threading\AsyncLazy.cs" />
<Compile Include="Core\Threading\DisposableSempahore.cs" />
<Compile Include="Core\Threading\TaskCompletionNotifier.cs" />
<Compile Include="Core\Threading\TaskExtension.cs" />
@@ -201,6 +204,7 @@
<Compile Include="Messages\NavigateToMarkdownPreviewHtmlMessage.cs" />
<Compile Include="Models\IndentationDisplayPair.cs" />
<Compile Include="Models\Indentation.cs" />
+ <Compile Include="Models\MarketingState.cs" />
<Compile Include="UI\Controls\CodeEditor.xaml.cs">
<DependentUpon>CodeEditor.xaml</DependentUpon>
</Compile>
diff --git a/src/dev/impl/DevToys/LanguageManager.cs b/src/dev/impl/DevToys/LanguageManager.cs
index c1e05aa83..b5eaa482f 100644
--- a/src/dev/impl/DevToys/LanguageManager.cs
+++ b/src/dev/impl/DevToys/LanguageManager.cs
@@ -569,6 +569,21 @@ namespace DevToys
/// </summary>
public string ExitCompactOverlayTooltip => _resources.GetString("ExitCompactOverlayTooltip");
+ /// <summary>
+ /// Gets the resource NotificationRateAppActionableActionText.
+ /// </summary>
+ public string NotificationRateAppActionableActionText => _resources.GetString("NotificationRateAppActionableActionText");
+
+ /// <summary>
+ /// Gets the resource NotificationRateAppMessage.
+ /// </summary>
+ public string NotificationRateAppMessage => _resources.GetString("NotificationRateAppMessage");
+
+ /// <summary>
+ /// Gets the resource NotificationRateAppTitle.
+ /// </summary>
+ public string NotificationRateAppTitle => _resources.GetString("NotificationRateAppTitle");
+
/// <summary>
/// Gets the resource NotificationReleaseNoteActionableActionText.
/// </summary>
diff --git a/src/dev/impl/DevToys/Models/MarketingState.cs b/src/dev/impl/DevToys/Models/MarketingState.cs
new file mode 100644
index 000000000..7084ca03f
--- /dev/null
+++ b/src/dev/impl/DevToys/Models/MarketingState.cs
@@ -0,0 +1,34 @@
+#nullable enable
+
+using Newtonsoft.Json;
+using System;
+
+namespace DevToys.Models
+{
+ internal sealed class MarketingState
+ {
+ [JsonProperty]
+ internal DateTime LastProblemEncounteredDate { get; set; }
+
+ [JsonProperty]
+ internal int StartSinceLastProblemEncounteredCount { get; set; }
+
+ [JsonProperty]
+ internal int SmartDetectionCount { get; set; }
+
+ [JsonProperty]
+ internal DateTime LastUpdateDate { get; set; }
+
+ [JsonProperty]
+ internal int ToolSuccessfulyWorkedCount { get; set; }
+
+ [JsonProperty]
+ internal DateTime LastAppRatingOfferDate { get; set; }
+
+ [JsonProperty]
+ internal int AppRatingOfferCount { get; set; }
+
+ [JsonProperty]
+ internal bool AppGotRated { get; set; }
+ }
+}
diff --git a/src/dev/impl/DevToys/Strings/cs-CZ/MainPage.resw b/src/dev/impl/DevToys/Strings/cs-CZ/MainPage.resw
index aee283675..3cdc97903 100644
--- a/src/dev/impl/DevToys/Strings/cs-CZ/MainPage.resw
+++ b/src/dev/impl/DevToys/Strings/cs-CZ/MainPage.resw
@@ -123,6 +123,15 @@
<data name="ExitCompactOverlayTooltip" xml:space="preserve">
<value>Zpět na plné zobrazení (Ctrl+Down)</value>
</data>
+ <data name="NotificationRateAppActionableActionText" xml:space="preserve">
+ <value>rate us now...</value>
+ </data>
+ <data name="NotificationRateAppMessage" xml:space="preserve">
+ <value>Enjoying DevToys? Please consider rating us!</value>
+ </data>
+ <data name="NotificationRateAppTitle" xml:space="preserve">
+ <value>Um... hi! 😅</value>
+ </data>
<data name="NotificationReleaseNoteActionableActionText" xml:space="preserve">
<value>zjistit více...</value>
</data>
diff --git a/src/dev/impl/DevToys/Strings/en-US/MainPage.resw b/src/dev/impl/DevToys/Strings/en-US/MainPage.resw
index 54b2459be..c9fc56044 100644
--- a/src/dev/impl/DevToys/Strings/en-US/MainPage.resw
+++ b/src/dev/impl/DevToys/Strings/en-US/MainPage.resw
@@ -123,6 +123,15 @@
<data name="ExitCompactOverlayTooltip" xml:space="preserve">
<value>Back to full view (Ctrl+Down)</value>
</data>
+ <data name="NotificationRateAppActionableActionText" xml:space="preserve">
+ <value>rate us now...</value>
+ </data>
+ <data name="NotificationRateAppMessage" xml:space="preserve">
+ <value>Enjoying DevToys? Please consider rating us!</value>
+ </data>
+ <data name="NotificationRateAppTitle" xml:space="preserve">
+ <value>Um... hi! 😅</value>
+ </data>
<data name="NotificationReleaseNoteActionableActionText" xml:space="preserve">
<value>read more...</value>
</data>
diff --git a/src/dev/impl/DevToys/Strings/fr-FR/MainPage.resw b/src/dev/impl/DevToys/Strings/fr-FR/MainPage.resw
index 4933fc84f..4beebd846 100644
--- a/src/dev/impl/DevToys/Strings/fr-FR/MainPage.resw
+++ b/src/dev/impl/DevToys/Strings/fr-FR/MainPage.resw
@@ -123,6 +123,15 @@
<data name="ExitCompactOverlayTooltip" xml:space="preserve">
<value>Retour en vue normal (Ctrl+Down)</value>
</data>
+ <data name="NotificationRateAppActionableActionText" xml:space="preserve">
+ <value>évaluez maintenant...</value>
+ </data>
+ <data name="NotificationRateAppMessage" xml:space="preserve">
+ <value>Vous aimez DevToys? N'hésitez pas à évaluer l'app!</value>
+ </data>
+ <data name="NotificationRateAppTitle" xml:space="preserve">
+ <value>Hum... bonjour! 😅</value>
+ </data>
<data name="NotificationReleaseNoteActionableActionText" xml:space="preserve">
<value>en savoir plus...</value>
</data>
diff --git a/src/dev/impl/DevToys/Strings/ru-RU/MainPage.resw b/src/dev/impl/DevToys/Strings/ru-RU/MainPage.resw
index 1a17f0afc..b7b4f1b81 100644
--- a/src/dev/impl/DevToys/Strings/ru-RU/MainPage.resw
+++ b/src/dev/impl/DevToys/Strings/ru-RU/MainPage.resw
@@ -123,6 +123,15 @@
<data name="ExitCompactOverlayTooltip" xml:space="preserve">
<value>Вернуться к полному представлению (CTRL + СТРЕЛКА ВНИЗ)</value>
</data>
+ <data name="NotificationRateAppActionableActionText" xml:space="preserve">
+ <value>rate us now...</value>
+ </data>
+ <data name="NotificationRateAppMessage" xml:space="preserve">
+ <value>Enjoying DevToys? Please consider rating us!</value>
+ </data>
+ <data name="NotificationRateAppTitle" xml:space="preserve">
+ <value>Um... hi! 😅</value>
+ </data>
<data name="NotificationReleaseNoteActionableActionText" xml:space="preserve">
<value>подробнее...</value>
</data>
diff --git a/src/dev/impl/DevToys/ViewModels/MainPageViewModel.cs b/src/dev/impl/DevToys/ViewModels/MainPageViewModel.cs
index f20b99e46..acfa2208d 100644
--- a/src/dev/impl/DevToys/ViewModels/MainPageViewModel.cs
+++ b/src/dev/impl/DevToys/ViewModels/MainPageViewModel.cs
@@ -40,6 +40,7 @@ namespace DevToys.ViewModels
private readonly IUriActivationProtocolService _launchProtocolService;
private readonly ISettingsProvider _settingsProvider;
private readonly INotificationService _notificationService;
+ private readonly IMarketingService _marketingService;
private readonly List<MatchedToolProviderViewData> _allToolsMenuitems = new();
private readonly DisposableSempahore _sempahore = new();
private readonly Lazy<Task> _firstUpdateMenuTask;
@@ -192,13 +193,15 @@ namespace DevToys.ViewModels
IToolProviderFactory toolProviderFactory,
IUriActivationProtocolService launchProtocolService,
ISettingsProvider settingsProvider,
- INotificationService notificationService)
+ INotificationService notificationService,
+ IMarketingService marketingService)
{
_clipboard = clipboard;
_toolProviderFactory = toolProviderFactory;
_launchProtocolService = launchProtocolService;
_settingsProvider = settingsProvider;
_notificationService = notificationService;
+ _marketingService = marketingService;
TitleBar = titleBar;
OpenToolInNewWindowCommand = new AsyncRelayCommand<ToolProviderMetadata>(ExecuteOpenToolInNewWindowCommandAsync);
@@ -279,6 +282,7 @@ namespace DevToys.ViewModels
}
}
+ _marketingService.NotifyAppStarted();
ShowReleaseNoteAsync().Forget();
ShowAvailableUpdateAsync().Forget();
@@ -464,6 +468,10 @@ namespace DevToys.ViewModels
else
{
_pasteInFirstSelectedToolIsAllowed = true;
+ if (newRecommendedTools.Length > 0)
+ {
+ _marketingService.NotifySmartDetectionWorked();
+ }
}
using (await _sempahore.WaitAsync(CancellationToken.None).ConfigureAwait(false))
@@ -508,6 +516,8 @@ namespace DevToys.ViewModels
Windows.System.Launcher.LaunchUriAsync(new Uri("https://github.com/veler/DevToys/releases")).AsTask().Forget();
},
await AssetsHelper.GetReleaseNoteAsync());
+
+ _marketingService.NotifyAppJustUpdated();
}
_settingsProvider.SetSetting(PredefinedSettings.FirstTimeStart, false);
@@ -519,11 +529,7 @@ namespace DevToys.ViewModels
// Make sure we work in background.
await TaskScheduler.Default;
- // Get the current app's package for the current user.
- var packageManager = new PackageManager();
- var currentPackage = packageManager.FindPackageForUser(string.Empty, Package.Current.Id.FullName);
-
- PackageUpdateAvailabilityResult result = await currentPackage.CheckUpdateAvailabilityAsync();
+ PackageUpdateAvailabilityResult result = await Package.Current.CheckUpdateAvailabilityAsync();
if (result.Availability == PackageUpdateAvailability.Required || result.Availability == PackageUpdateAvailability.Available)
{
diff --git a/src/dev/impl/DevToys/ViewModels/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolViewModel.cs
index bb796905f..9551bc725 100644
--- a/src/dev/impl/DevToys/ViewModels/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolViewModel.cs
+++ b/src/dev/impl/DevToys/ViewModels/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolViewModel.cs
@@ -1,5 +1,6 @@
#nullable enable
+using DevToys.Api.Core;
using DevToys.Api.Core.Settings;
using DevToys.Api.Tools;
using DevToys.Core;
@@ -39,6 +40,7 @@ namespace DevToys.ViewModels.Tools.Base64EncoderDecoder
private const string DefaultConversion = "Encode";
internal const string DecodeConversion = "Decode";
+ private readonly IMarketingService _marketingService;
private readonly ISettingsProvider _settingsProvider;
private readonly Queue<string> _conversionQueue = new();
@@ -46,6 +48,7 @@ namespace DevToys.ViewModels.Tools.Base64EncoderDecoder
private string? _outputValue;
private bool _conversionInProgress;
private bool _setPropertyInProgress;
+ private bool _toolSuccessfullyWorked;
public Type View { get; } = typeof(Base64EncoderDecoderToolPage);
@@ -116,9 +119,10 @@ namespace DevToys.ViewModels.Tools.Base64EncoderDecoder
}
[ImportingConstructor]
- public Base64EncoderDecoderToolViewModel(ISettingsProvider settingsProvider)
+ public Base64EncoderDecoderToolViewModel(ISettingsProvider settingsProvider, IMarketingService marketingService)
{
_settingsProvider = settingsProvider;
+ _marketingService = marketingService;
}
private void QueueConversionCalculation()
@@ -153,6 +157,12 @@ namespace DevToys.ViewModels.Tools.Base64EncoderDecoder
ThreadHelper.RunOnUIThreadAsync(ThreadPriority.Low, () =>
{
OutputValue = conversionResult;
+
+ if (!_toolSuccessfullyWorked)
+ {
+ _toolSuccessfullyWorked = true;
+ _marketingService.NotifyToolSuccessfullyWorked();
+ }
}).ForgetSafely();
}
diff --git a/src/dev/impl/DevToys/ViewModels/Tools/GuidGenerator/GuidGeneratorToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/GuidGenerator/GuidGeneratorToolViewModel.cs
index 47699b30e..6f9ebf7e6 100644
--- a/src/dev/impl/DevToys/ViewModels/Tools/GuidGenerator/GuidGeneratorToolViewModel.cs
+++ b/src/dev/impl/DevToys/ViewModels/Tools/GuidGenerator/GuidGeneratorToolViewModel.cs
@@ -1,5 +1,6 @@
#nullable enable
+using DevToys.Api.Core;
using DevToys.Api.Core.Settings;
using DevToys.Api.Tools;
using DevToys.UI.Controls;
@@ -42,8 +43,11 @@ namespace DevToys.ViewModels.Tools.GuidGenerator
isRoaming: true,
defaultValue: 1);
+ private readonly IMarketingService _marketingService;
private readonly ISettingsProvider _settingsProvider;
+
private string _output = string.Empty;
+ private bool _toolSuccessfullyWorked;
public Type View { get; } = typeof(GuidGeneratoToolPage);
@@ -97,9 +101,10 @@ namespace DevToys.ViewModels.Tools.GuidGenerator
internal ICustomTextBox? OutputTextBox { private get; set; }
[ImportingConstructor]
- public GuidGeneratorToolViewModel(ISettingsProvider settingsProvider)
+ public GuidGeneratorToolViewModel(ISettingsProvider settingsProvider, IMarketingService marketingService)
{
_settingsProvider = settingsProvider;
+ _marketingService = marketingService;
GenerateCommand = new RelayCommand(ExecuteGenerateCommand);
}
@@ -134,6 +139,12 @@ namespace DevToys.ViewModels.Tools.GuidGenerator
Output += newGuids.ToString();
OutputTextBox?.ScrollToBottom();
+
+ if (!_toolSuccessfullyWorked)
+ {
+ _toolSuccessfullyWorked = true;
+ _marketingService.NotifyToolSuccessfullyWorked();
+ }
}
#endregion
diff --git a/src/dev/impl/DevToys/ViewModels/Tools/HashGenerator/HashGeneratorToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/HashGenerator/HashGeneratorToolViewModel.cs
index c656d98ce..2d0636545 100644
--- a/src/dev/impl/DevToys/ViewModels/Tools/HashGenerator/HashGeneratorToolViewModel.cs
+++ b/src/dev/impl/DevToys/ViewModels/Tools/HashGenerator/HashGeneratorToolViewModel.cs
@@ -1,5 +1,6 @@
#nullable enable
+using DevToys.Api.Core;
using DevToys.Api.Core.Settings;
using DevToys.Api.Tools;
using DevToys.Core;
@@ -28,9 +29,11 @@ namespace DevToys.ViewModels.Tools.HashGenerator
isRoaming: true,
defaultValue: false);
+ private readonly IMarketingService _marketingService;
private readonly ISettingsProvider _settingsProvider;
private readonly Queue<string> _hashCalculationQueue = new();
+ private bool _toolSuccessfullyWorked;
private bool _calculationInProgress;
private string? _input;
private string? _md5;
@@ -91,9 +94,10 @@ namespace DevToys.ViewModels.Tools.HashGenerator
}
[ImportingConstructor]
- public HashGeneratorToolViewModel(ISettingsProvider settingsProvider)
+ public HashGeneratorToolViewModel(ISettingsProvider settingsProvider, IMarketingService marketingService)
{
_settingsProvider = settingsProvider;
+ _marketingService = marketingService;
}
private void QueueHashCalculation()
@@ -128,6 +132,12 @@ namespace DevToys.ViewModels.Tools.HashGenerator
SHA1 = sha1CalculationTask.Result;
SHA256 = sha256CalculationTask.Result;
SHA512 = sha512CalculationTask.Result;
+
+ if (!_toolSuccessfullyWorked)
+ {
+ _toolSuccessfullyWorked = true;
+ _marketingService.NotifyToolSuccessfullyWorked();
+ }
}).ForgetSafely();
}
diff --git a/src/dev/impl/DevToys/ViewModels/Tools/JsonFormatter/JsonFormatterToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/JsonFormatter/JsonFormatterToolViewModel.cs
index e5d40771f..857421e99 100644
--- a/src/dev/impl/DevToys/ViewModels/Tools/JsonFormatter/JsonFormatterToolViewModel.cs
+++ b/src/dev/impl/DevToys/ViewModels/Tools/JsonFormatter/JsonFormatterToolViewModel.cs
@@ -1,5 +1,6 @@
#nullable enable
+using DevToys.Api.Core;
using DevToys.Api.Core.Settings;
using DevToys.Api.Tools;
using DevToys.Core.Threading;
@@ -28,8 +29,10 @@ namespace DevToys.ViewModels.Tools.JsonFormatter
isRoaming: true,
defaultValue: Models.Indentation.TwoSpaces);
+ private readonly IMarketingService _marketingService;
private readonly Queue<string> _formattingQueue = new();
+ private bool _toolSuccessfullyWorked;
private bool _formattingInProgress;
private string? _inputValue;
private string? _outputValue;
@@ -92,9 +95,10 @@ namespace DevToys.ViewModels.Tools.JsonFormatter
internal ISettingsProvider SettingsProvider { get; }
[ImportingConstructor]
- public JsonFormatterToolViewModel(ISettingsProvider settingsProvider)
+ public JsonFormatterToolViewModel(ISettingsProvider settingsProvider, IMarketingService marketingService)
{
SettingsProvider = settingsProvider;
+ _marketingService = marketingService;
}
private void QueueFormatting()
@@ -122,6 +126,12 @@ namespace DevToys.ViewModels.Tools.JsonFormatter
ThreadHelper.RunOnUIThreadAsync(ThreadPriority.Low, () =>
{
OutputValue = result;
+
+ if (!_toolSuccessfullyWorked)
+ {
+ _toolSuccessfullyWorked = true;
+ _marketingService.NotifyToolSuccessfullyWorked();
+ }
}).ForgetSafely();
}
}
diff --git a/src/dev/impl/DevToys/ViewModels/Tools/JsonYaml/JsonYamlToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/JsonYaml/JsonYamlToolViewModel.cs
index 3f0fef000..1b97e3db3 100644
--- a/src/dev/impl/DevToys/ViewModels/Tools/JsonYaml/JsonYamlToolViewModel.cs
+++ b/src/dev/impl/DevToys/ViewModels/Tools/JsonYaml/JsonYamlToolViewModel.cs
@@ -1,5 +1,6 @@
#nullable enable
+using DevToys.Api.Core;
using DevToys.Api.Core.Settings;
using DevToys.Api.Tools;
using DevToys.Core;
@@ -46,8 +47,10 @@ namespace DevToys.ViewModels.Tools.JsonYaml
private const string TwoSpaceIndentation = "TwoSpaces";
private const string FourSpaceIndentation = "FourSpaces";
+ private readonly IMarketingService _marketingService;
private readonly Queue<string> _conversionQueue = new();
+ private bool _toolSuccessfullyWorked;
private bool _conversionInProgress;
private bool _setPropertyInProgress;
private string? _inputValue;
@@ -163,9 +166,10 @@ namespace DevToys.ViewModels.Tools.JsonYaml
internal ISettingsProvider SettingsProvider { get; }
[ImportingConstructor]
- public JsonYamlToolViewModel(ISettingsProvider settingsProvider)
+ public JsonYamlToolViewModel(ISettingsProvider settingsProvider, IMarketingService marketingService)
{
SettingsProvider = settingsProvider;
+ _marketingService = marketingService;
InputValueLanguage = "json";
OutputValueLanguage = "yaml";
}
@@ -203,6 +207,12 @@ namespace DevToys.ViewModels.Tools.JsonYaml
ThreadHelper.RunOnUIThreadAsync(ThreadPriority.Low, () =>
{
OutputValue = result;
+
+ if (success && !_toolSuccessfullyWorked)
+ {
+ _toolSuccessfullyWorked = true;
+ _marketingService.NotifyToolSuccessfullyWorked();
+ }
}).ForgetSafely();
}
diff --git a/src/dev/impl/DevToys/ViewModels/Tools/JwtDecoderEncoder/JwtDecoderEncoderToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/JwtDecoderEncoder/JwtDecoderEncoderToolViewModel.cs
index 572c3df21..a9e03bbb7 100644
--- a/src/dev/impl/DevToys/ViewModels/Tools/JwtDecoderEncoder/JwtDecoderEncoderToolViewModel.cs
+++ b/src/dev/impl/DevToys/ViewModels/Tools/JwtDecoderEncoder/JwtDecoderEncoderToolViewModel.cs
@@ -1,5 +1,6 @@
#nullable enable
+using DevToys.Api.Core;
using DevToys.Api.Tools;
using DevToys.Core.Threading;
using DevToys.Helpers;
@@ -17,8 +18,10 @@ namespace DevToys.ViewModels.Tools.JwtDecoderEncoder
[Export(typeof(JwtDecoderEncoderToolViewModel))]
public sealed class JwtDecoderEncoderToolViewModel : ObservableRecipient, IToolViewModel
{
+ private readonly IMarketingService _marketingService;
private readonly Queue<string> _decodingQueue = new();
+ private bool _toolSuccessfullyWorked;
private bool _decodingInProgress;
private string? _jwtToken;
private string? _jwtHeader;
@@ -59,6 +62,12 @@ namespace DevToys.ViewModels.Tools.JwtDecoderEncoder
set => SetProperty(ref _jwtPayload, value);
}
+ [ImportingConstructor]
+ public JwtDecoderEncoderToolViewModel(IMarketingService marketingService)
+ {
+ _marketingService = marketingService;
+ }
+
private void QueueConversion()
{
_decodingQueue.Enqueue(JwtToken ?? string.Empty);
@@ -83,6 +92,12 @@ namespace DevToys.ViewModels.Tools.JwtDecoderEncoder
{
JwtHeader = header;
JwtPayload = payload;
+
+ if (!_toolSuccessfullyWorked)
+ {
+ _toolSuccessfullyWorked = true;
+ _marketingService.NotifyToolSuccessfullyWorked();
+ }
}).ForgetSafely();
}
diff --git a/src/dev/impl/DevToys/ViewModels/Tools/MarkdownPreview/MarkdownPreviewToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/MarkdownPreview/MarkdownPreviewToolViewModel.cs
index a51848dc0..e431b1ec1 100644
--- a/src/dev/impl/DevToys/ViewModels/Tools/MarkdownPreview/MarkdownPreviewToolViewModel.cs
+++ b/src/dev/impl/DevToys/ViewModels/Tools/MarkdownPreview/MarkdownPreviewToolViewModel.cs
@@ -1,5 +1,6 @@
#nullable enable
+using DevToys.Api.Core;
using DevToys.Api.Core.Settings;
using DevToys.Api.Core.Theme;
using DevToys.Api.Tools;
@@ -30,9 +31,11 @@ namespace DevToys.ViewModels.Tools.MarkdownPreview
isRoaming: true,
defaultValue: null);
+ private readonly IMarketingService _marketingService;
private readonly IThemeListener _themeListener;
private readonly Queue<string> _workQueue = new();
+ private bool _toolSuccessfullyWorked;
private bool _workInProgress;
private string? _inputValue;
@@ -78,8 +81,9 @@ namespace DevToys.ViewModels.Tools.MarkdownPreview
internal ISettingsProvider SettingsProvider { get; }
[ImportingConstructor]
- public MarkdownPreviewToolViewModel(ISettingsProvider settingsProvider, IThemeListener themeListener)
+ public MarkdownPreviewToolViewModel(ISettingsProvider settingsProvider, IMarketingService marketingService, IThemeListener themeListener)
{
+ _marketingService = marketingService;
_themeListener = themeListener;
SettingsProvider = settingsProvider;
@@ -113,6 +117,12 @@ namespace DevToys.ViewModels.Tools.MarkdownPreview
ThreadHelper.RunOnUIThreadAsync(() =>
{
Messenger.Send(new NavigateToMarkdownPreviewHtmlMessage(html));
+
+ if (!_toolSuccessfullyWorked)
+ {
+ _toolSuccessfullyWorked = true;
+ _marketingService.NotifyToolSuccessfullyWorked();
+ }
}).ForgetSafely();
}
diff --git a/src/dev/impl/DevToys/ViewModels/Tools/RegEx/RegExToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/RegEx/RegExToolViewModel.cs
index 4c9cfab27..0a6f34d12 100644
--- a/src/dev/impl/DevToys/ViewModels/Tools/RegEx/RegExToolViewModel.cs
+++ b/src/dev/impl/DevToys/ViewModels/Tools/RegEx/RegExToolViewModel.cs
@@ -1,5 +1,6 @@
#nullable enable
+using DevToys.Api.Core;
using DevToys.Api.Core.Settings;
using DevToys.Api.Tools;
using DevToys.Core.Threading;
@@ -60,8 +61,10 @@ namespace DevToys.ViewModels.Tools.RegEx
isRoaming: true,
defaultValue: false);
+ private readonly IMarketingService _marketingService;
private readonly Queue<(string pattern, string text)> _regExMatchingQueue = new();
+ private bool _toolSuccessfullyWorked;
private bool _calculationInProgress;
private string? _regularExpression;
private string? _text;
@@ -193,9 +196,10 @@ namespace DevToys.ViewModels.Tools.RegEx
internal ICustomTextBox? MatchTextBox { private get; set; }
[ImportingConstructor]
- public RegExToolViewModel(ISettingsProvider settingsProvider)
+ public RegExToolViewModel(ISettingsProvider settingsProvider, IMarketingService marketingService)
{
SettingsProvider = settingsProvider;
+ _marketingService = marketingService;
}
private void QueueRegExMatch()
@@ -248,6 +252,12 @@ namespace DevToys.ViewModels.Tools.RegEx
() =>
{
MatchTextBox?.SetHighlights(spans);
+
+ if (spans.Count > 0 && !_toolSuccessfullyWorked)
+ {
+ _toolSuccessfullyWorked = true;
+ _marketingService.NotifyToolSuccessfullyWorked();
+ }
}).ForgetSafely();
}
diff --git a/src/dev/impl/DevToys/ViewModels/Tools/StringUtilities/StringUtilitiesToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/StringUtilities/StringUtilitiesToolViewModel.cs
index 1efc9eed9..ecf65fa9a 100644
--- a/src/dev/impl/DevToys/ViewModels/Tools/StringUtilities/StringUtilitiesToolViewModel.cs
+++ b/src/dev/impl/DevToys/ViewModels/Tools/StringUtilities/StringUtilitiesToolViewModel.cs
@@ -1,5 +1,6 @@
#nullable enable
+using DevToys.Api.Core;
using DevToys.Api.Tools;
using DevToys.Core.Threading;
using DevToys.Views.Tools.StringUtilities;
@@ -20,6 +21,9 @@ namespace DevToys.ViewModels.Tools.StringUtilities
{
private static readonly object _lockObject = new();
+ private readonly IMarketingService _marketingService;
+
+ private bool _toolSuccessfullyWorked;
private bool _forbidBackup;
private string? _text;
private string? _textBackup;
@@ -135,8 +139,9 @@ namespace DevToys.ViewModels.Tools.StringUtilities
}
[ImportingConstructor]
- public StringUtilitiesToolViewModel()
+ public StringUtilitiesToolViewModel(IMarketingService marketingService)
{
+ _marketingService = marketingService;
OriginalCaseCommand = new RelayCommand(ExecuteOriginalCaseCommand, CanExecuteOriginalCaseCommand);
SentenceCaseCommand = new RelayCommand(ExecuteSentenceCaseCommand);
LowerCaseCommand = new RelayCommand(ExecuteLowerCaseCommand);
@@ -787,6 +792,12 @@ namespace DevToys.ViewModels.Tools.StringUtilities
Bytes = bytes;
WordDistribution = wordDistribution;
CharacterDistribution = characterDistribution;
+
+ if (!_toolSuccessfullyWorked)
+ {
+ _toolSuccessfullyWorked = true;
+ _marketingService.NotifyToolSuccessfullyWorked();
+ }
});
}