Skip to content

A Swiss Army knife for developers.

Added in-app notification, What's News UX and Update Available notification (#13)

Etienne Baudoux2b21c85d7603
diff --git a/src/dev/impl/DevToys/Api/Core/INotificationService.cs b/src/dev/impl/DevToys/Api/Core/INotificationService.cs
new file mode 100644
index 000000000..88c372da6
--- /dev/null
+++ b/src/dev/impl/DevToys/Api/Core/INotificationService.cs
@@ -0,0 +1,27 @@
+#nullable enable
+
+using System;
+
+namespace DevToys.Api.Core
+{
+ /// <summary>
+ /// Provides a service allowing to show in-app notification and Windows' toast notification.
+ /// </summary>
+ public interface INotificationService
+ {
+ /// <summary>
+ /// Raised when an in-app notification is added.
+ /// </summary>
+ event EventHandler<InAppNotificationAddedEventArgs>? InAppNotificationAdded;
+
+ /// <summary>
+ /// Displays an in-app notification.
+ /// </summary>
+ void ShowInAppNotification(string title, string? message = null);
+
+ /// <summary>
+ /// Displays an in-app notification with an actionable link.
+ /// </summary>
+ void ShowInAppNotification(string title, string actionableLinkText, Action actionableLinkBehavior, string? message = null);
+ }
+}
diff --git a/src/dev/impl/DevToys/Api/Core/InAppNotificationAddedEventArgs.cs b/src/dev/impl/DevToys/Api/Core/InAppNotificationAddedEventArgs.cs
new file mode 100644
index 000000000..f5ab531c9
--- /dev/null
+++ b/src/dev/impl/DevToys/Api/Core/InAppNotificationAddedEventArgs.cs
@@ -0,0 +1,37 @@
+#nullable enable
+
+using DevToys.Core;
+using System;
+
+namespace DevToys.Api.Core
+{
+ public sealed class InAppNotificationAddedEventArgs : EventArgs
+ {
+ public string Title { get; }
+
+ public string? Message { get; }
+
+ public string? ActionableLinkText { get; }
+
+ public Action? Action { get; }
+
+ internal InAppNotificationAddedEventArgs(
+ string title,
+ string? message,
+ string? actionableLinkText,
+ Action? action)
+ {
+ Title = Arguments.NotNullOrWhiteSpace(title, nameof(title));
+ Message = message;
+
+ if ((string.IsNullOrWhiteSpace(actionableLinkText) && action != null)
+ || (!string.IsNullOrWhiteSpace(actionableLinkText) && action == null))
+ {
+ throw new ArgumentException($"'{nameof(actionableLinkText)}' and '{nameof(action)}' should not be null.");
+ }
+
+ ActionableLinkText = actionableLinkText;
+ Action = action;
+ }
+ }
+}
diff --git a/src/dev/impl/DevToys/Assets/ReleaseNote.txt b/src/dev/impl/DevToys/Assets/ReleaseNote.txt
new file mode 100644
index 000000000..345fe8b6b
--- /dev/null
+++ b/src/dev/impl/DevToys/Assets/ReleaseNote.txt
@@ -0,0 +1,2 @@
+ • In-app notifications.
+ • Bugs fixed
\ No newline at end of file
diff --git a/src/dev/impl/DevToys/Core/AssetsHelper.cs b/src/dev/impl/DevToys/Core/AssetsHelper.cs
index f2122dc5b..50b02b1cb 100644
--- a/src/dev/impl/DevToys/Core/AssetsHelper.cs
+++ b/src/dev/impl/DevToys/Core/AssetsHelper.cs
@@ -11,6 +11,13 @@ namespace DevToys.Core
{
public static class AssetsHelper
{
+ public static async Task<string> GetReleaseNoteAsync()
+ {
+ string result = await GetLocalFileContentAsync($"Assets\\ReleaseNote.txt").ConfigureAwait(false);
+
+ return result;
+ }
+
public static async Task<string> GetPrivacyStatementAsync()
{
string result = await GetLocalFileContentAsync($"Assets\\PRIVACY-POLICY.md").ConfigureAwait(false);
diff --git a/src/dev/impl/DevToys/Core/NotificationService.cs b/src/dev/impl/DevToys/Core/NotificationService.cs
new file mode 100644
index 000000000..0459398bf
--- /dev/null
+++ b/src/dev/impl/DevToys/Core/NotificationService.cs
@@ -0,0 +1,25 @@
+#nullable enable
+
+using DevToys.Api.Core;
+using System;
+using System.Composition;
+
+namespace DevToys.Core
+{
+ [Export(typeof(INotificationService))]
+ [Shared]
+ internal sealed class NotificationService : INotificationService
+ {
+ public event EventHandler<InAppNotificationAddedEventArgs>? InAppNotificationAdded;
+
+ public void ShowInAppNotification(string title, string? message = null)
+ {
+ InAppNotificationAdded?.Invoke(this, new InAppNotificationAddedEventArgs(title, message, null, null));
+ }
+
+ public void ShowInAppNotification(string title, string actionableLinkText, Action actionableLinkBehavior, string? message = null)
+ {
+ InAppNotificationAdded?.Invoke(this, new InAppNotificationAddedEventArgs(title, message, actionableLinkText, actionableLinkBehavior));
+ }
+ }
+}
diff --git a/src/dev/impl/DevToys/Core/Settings/PredefinedSettings.cs b/src/dev/impl/DevToys/Core/Settings/PredefinedSettings.cs
index 93a49c129..238794378 100644
--- a/src/dev/impl/DevToys/Core/Settings/PredefinedSettings.cs
+++ b/src/dev/impl/DevToys/Core/Settings/PredefinedSettings.cs
@@ -7,6 +7,25 @@ namespace DevToys.Core.Settings
{
public static class PredefinedSettings
{
+ /// <summary>
+ /// Equals to the last version the app runs. This setting is used to determine whether the user started the app
+ /// for the first time after an update
+ /// </summary>
+ public static readonly SettingDefinition<string> LastVersionRan
+ = new(
+ name: nameof(LastVersionRan),
+ isRoaming: false,
+ defaultValue: string.Empty);
+
+ /// <summary>
+ /// Allows to know if it's the first time the app is started after being installed.
+ /// </summary>
+ public static readonly SettingDefinition<bool> FirstTimeStart
+ = new(
+ name: nameof(FirstTimeStart),
+ isRoaming: false,
+ defaultValue: true);
+
/// <summary>
/// The language to use for the texts in the user interface.
/// </summary>
diff --git a/src/dev/impl/DevToys/DevToys.csproj b/src/dev/impl/DevToys/DevToys.csproj
index 221c321d0..35870cfd8 100644
--- a/src/dev/impl/DevToys/DevToys.csproj
+++ b/src/dev/impl/DevToys/DevToys.csproj
@@ -142,13 +142,18 @@
<Link>Assets\Logo\Wide310x150Logo.scale-400.png</Link>
</Content>
<Content Include="Assets\DemoSmartDetection.gif" />
+ <Content Include="Assets\ReleaseNote.txt">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
<Content Include="Properties\Default.rd.rd.xml" />
<Compile Include="Api\Core\IClipboard.cs" />
<Compile Include="Api\Core\IMefProvider.cs" />
+ <Compile Include="Api\Core\InAppNotificationAddedEventArgs.cs" />
<Compile Include="Api\Core\ITitleBar.cs" />
<Compile Include="Api\Core\IUriActivationProtocolService.cs" />
<Compile Include="Api\Core\Navigation\IWindowManager.cs" />
<Compile Include="Api\Core\Navigation\NavigationParameter.cs" />
+ <Compile Include="Api\Core\INotificationService.cs" />
<Compile Include="Api\Core\Settings\ISettingsProvider.cs" />
<Compile Include="Api\Core\Settings\SettingChangedEventArgs.cs" />
<Compile Include="Api\Core\Settings\SettingDefinition.cs" />
@@ -176,6 +181,7 @@
<Compile Include="Core\MefComposer.cs" />
<Compile Include="Core\MefProvider.cs" />
<Compile Include="Core\Navigation\WindowManager.cs" />
+ <Compile Include="Core\NotificationService.cs" />
<Compile Include="Core\Settings\PredefinedSettings.cs" />
<Compile Include="Core\Settings\SettingsProvider.cs" />
<Compile Include="Core\Theme\ThemeListener.cs" />
@@ -187,6 +193,10 @@
<Compile Include="Core\Threading\ThreadPriority.cs" />
<Compile Include="Core\TitleBar.cs" />
<Compile Include="Core\ToolProviderFactory.cs" />
+ <Compile Include="UI\Controls\Notification.xaml.cs">
+ <DependentUpon>Notification.xaml</DependentUpon>
+ </Compile>
+ <Compile Include="UI\Converters\NullToVisibilityConverter.cs" />
<Compile Include="ViewModels\Tools\ToolProviderBase.cs" />
<Compile Include="Core\UriActivationProtocolService.cs" />
<Compile Include="LanguageDefinition.cs" />
@@ -337,6 +347,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
+ <Page Include="UI\Controls\Notification.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
<Page Include="UI\Controls\TextEditor\TextEditor.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
diff --git a/src/dev/impl/DevToys/LanguageManager.cs b/src/dev/impl/DevToys/LanguageManager.cs
index 920744fc6..b9dbf4e30 100644
--- a/src/dev/impl/DevToys/LanguageManager.cs
+++ b/src/dev/impl/DevToys/LanguageManager.cs
@@ -374,6 +374,34 @@ namespace DevToys
/// </summary>
public string ExitCompactOverlayTooltip => _resources.GetString("ExitCompactOverlayTooltip");
+ /// <summary>
+ /// Gets the resource NotificationReleaseNoteActionableActionText.
+ /// </summary>
+ public string NotificationReleaseNoteActionableActionText => _resources.GetString("NotificationReleaseNoteActionableActionText");
+
+ /// <summary>
+ /// Gets the resource NotificationReleaseNoteTitle.
+ /// </summary>
+ public string NotificationReleaseNoteTitle => _resources.GetString("NotificationReleaseNoteTitle");
+
+ /// <summary>
+ /// Gets the resource NotificationReleaseNoteTitle with format.
+ /// </summary>
+ public string GetFormattedNotificationReleaseNoteTitle(string? param0)
+ {
+ return string.Format(NotificationReleaseNoteTitle, param0);
+ }
+
+ /// <summary>
+ /// Gets the resource NotificationUpdateAvailableActionableActionText.
+ /// </summary>
+ public string NotificationUpdateAvailableActionableActionText => _resources.GetString("NotificationUpdateAvailableActionableActionText");
+
+ /// <summary>
+ /// Gets the resource NotificationUpdateAvailableTitle.
+ /// </summary>
+ public string NotificationUpdateAvailableTitle => _resources.GetString("NotificationUpdateAvailableTitle");
+
/// <summary>
/// Gets the resource OpenInNewWindow.
/// </summary>
diff --git a/src/dev/impl/DevToys/Strings/en/MainPage.resw b/src/dev/impl/DevToys/Strings/en/MainPage.resw
index 8446d3edb..54b2459be 100644
--- a/src/dev/impl/DevToys/Strings/en/MainPage.resw
+++ b/src/dev/impl/DevToys/Strings/en/MainPage.resw
@@ -123,6 +123,19 @@
<data name="ExitCompactOverlayTooltip" xml:space="preserve">
<value>Back to full view (Ctrl+Down)</value>
</data>
+ <data name="NotificationReleaseNoteActionableActionText" xml:space="preserve">
+ <value>read more...</value>
+ </data>
+ <data name="NotificationReleaseNoteTitle" xml:space="preserve">
+ <value>We just updated! What's new in {0}? 🚀</value>
+ <comment>{0} is the current app version</comment>
+ </data>
+ <data name="NotificationUpdateAvailableActionableActionText" xml:space="preserve">
+ <value>update now...</value>
+ </data>
+ <data name="NotificationUpdateAvailableTitle" xml:space="preserve">
+ <value>An update is available! 🚀</value>
+ </data>
<data name="OpenInNewWindow" xml:space="preserve">
<value>Open in a new window</value>
</data>
diff --git a/src/dev/impl/DevToys/Strings/fr/MainPage.resw b/src/dev/impl/DevToys/Strings/fr/MainPage.resw
index 4667fcb80..4933fc84f 100644
--- a/src/dev/impl/DevToys/Strings/fr/MainPage.resw
+++ b/src/dev/impl/DevToys/Strings/fr/MainPage.resw
@@ -123,6 +123,19 @@
<data name="ExitCompactOverlayTooltip" xml:space="preserve">
<value>Retour en vue normal (Ctrl+Down)</value>
</data>
+ <data name="NotificationReleaseNoteActionableActionText" xml:space="preserve">
+ <value>en savoir plus...</value>
+ </data>
+ <data name="NotificationReleaseNoteTitle" xml:space="preserve">
+ <value>On vient de mettre à jour! Quoi de neuf dans la version {0}? 🚀</value>
+ <comment>{0} is the current app version</comment>
+ </data>
+ <data name="NotificationUpdateAvailableActionableActionText" xml:space="preserve">
+ <value>mettre à jour maintenant...</value>
+ </data>
+ <data name="NotificationUpdateAvailableTitle" xml:space="preserve">
+ <value>Une mise à jour est disponible! 🚀</value>
+ </data>
<data name="OpenInNewWindow" xml:space="preserve">
<value>Ouvrir dans une nouvelle fenêtre</value>
</data>
diff --git a/src/dev/impl/DevToys/UI/Controls/Notification.xaml b/src/dev/impl/DevToys/UI/Controls/Notification.xaml
new file mode 100644
index 000000000..adf31c8d5
--- /dev/null
+++ b/src/dev/impl/DevToys/UI/Controls/Notification.xaml
@@ -0,0 +1,75 @@
+<UserControl
+ x:Class="DevToys.UI.Controls.Notification"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:core="using:DevToys.Api.Core"
+ xmlns:converters="using:DevToys.UI.Converters"
+ xmlns:wct="using:Microsoft.Toolkit.Uwp.UI.Controls"
+ xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
+ mc:Ignorable="d"
+ d:DesignHeight="300"
+ d:DesignWidth="400">
+ <UserControl.Resources>
+ <converters:NullToVisibilityConverter x:Key="InvertedEmptyStringToVisibilityConverter" EnforceNonWhiteSpaceString="True" IsInverted="True"/>
+ </UserControl.Resources>
+
+ <ItemsControl
+ x:Name="ItemsControl"
+ HorizontalAlignment="Right"
+ VerticalAlignment="Top"
+ Margin="0,48,16,0"
+ ScrollViewer.VerticalScrollMode="Disabled"
+ ScrollViewer.HorizontalScrollMode="Disabled"
+ HorizontalContentAlignment="Stretch">
+ <ItemsControl.ItemContainerTransitions>
+ <TransitionCollection>
+ <AddDeleteThemeTransition/>
+ </TransitionCollection>
+ </ItemsControl.ItemContainerTransitions>
+ <ItemsControl.ItemTemplate>
+ <DataTemplate x:DataType="core:InAppNotificationAddedEventArgs">
+ <wct:DropShadowPanel
+ Margin="0,0,0,24"
+ BlurRadius="24"
+ ShadowOpacity="0.5"
+ OffsetX="0"
+ OffsetY="7"
+ HorizontalAlignment="Right"
+ IsMasked="True"
+ Color="Black">
+ <muxc:InfoBar
+ Background="{ThemeResource SystemChromeMediumHighColor}"
+ BorderBrush="{ThemeResource ToggleSwitchStrokeOn}"
+ BorderThickness="0,4,0,0"
+ CornerRadius="4"
+ MinWidth="250"
+ MaxWidth="450"
+ MaxHeight="400"
+ Padding="8"
+ Title="{Binding Title}"
+ IsOpen="True"
+ Severity="Informational"
+ IsIconVisible="False"
+ Closing="InfoBar_Closing">
+ <muxc:InfoBar.Content>
+ <StackPanel Margin="0,0,0,4">
+ <TextBlock
+ Visibility="{Binding Message, Converter={StaticResource InvertedEmptyStringToVisibilityConverter}}"
+ Margin="2 -10 0 4"
+ TextWrapping="WrapWholeWords"
+ Text="{Binding Message}"/>
+ <HyperlinkButton
+ Margin="-10,0,0,0"
+ Visibility="{Binding ActionableLinkText, Converter={StaticResource InvertedEmptyStringToVisibilityConverter}}"
+ Content="{Binding ActionableLinkText}"
+ Click="ActionableButton_Click"/>
+ </StackPanel>
+ </muxc:InfoBar.Content>
+ </muxc:InfoBar>
+ </wct:DropShadowPanel>
+ </DataTemplate>
+ </ItemsControl.ItemTemplate>
+ </ItemsControl>
+</UserControl>
diff --git a/src/dev/impl/DevToys/UI/Controls/Notification.xaml.cs b/src/dev/impl/DevToys/UI/Controls/Notification.xaml.cs
new file mode 100644
index 000000000..1b490458b
--- /dev/null
+++ b/src/dev/impl/DevToys/UI/Controls/Notification.xaml.cs
@@ -0,0 +1,68 @@
+#nullable enable
+
+using DevToys.Api.Core;
+using DevToys.Core.Threading;
+using System.Collections.ObjectModel;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+
+namespace DevToys.UI.Controls
+{
+ public sealed partial class Notification : UserControl
+ {
+ private readonly ObservableCollection<InAppNotificationAddedEventArgs> _notifications = new();
+
+ public static readonly DependencyProperty NotificationServiceProperty
+ = DependencyProperty.Register(
+ nameof(NotificationService),
+ typeof(INotificationService),
+ typeof(Notification),
+ new PropertyMetadata(null, OnNotificationServicePropertyChangedCallback));
+
+ public INotificationService? NotificationService
+ {
+ get => (INotificationService?)GetValue(NotificationServiceProperty);
+ set => SetValue(NotificationServiceProperty, value);
+ }
+
+ public Notification()
+ {
+ InitializeComponent();
+ ItemsControl.ItemsSource = _notifications;
+ }
+
+ private void ListenToNotifications(INotificationService notificationService)
+ {
+ notificationService.InAppNotificationAdded += NotificationService_InAppNotificationAdded;
+ }
+
+ private void NotificationService_InAppNotificationAdded(object sender, InAppNotificationAddedEventArgs e)
+ {
+ ThreadHelper.RunOnUIThreadAsync(() =>
+ {
+ _notifications.Add(e);
+ });
+ }
+
+ private void InfoBar_Closing(Microsoft.UI.Xaml.Controls.InfoBar sender, Microsoft.UI.Xaml.Controls.InfoBarClosingEventArgs args)
+ {
+ _notifications.Remove((InAppNotificationAddedEventArgs)sender.DataContext);
+ }
+
+ private void ActionableButton_Click(object sender, RoutedEventArgs e)
+ {
+ var model = (InAppNotificationAddedEventArgs)((FrameworkElement)sender).DataContext;
+ model.Action!.Invoke();
+ _notifications.Remove(model);
+ }
+
+ private static void OnNotificationServicePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ INotificationService? notificationService = e.NewValue as INotificationService;
+ if (notificationService is not null)
+ {
+ ((Notification)d).ListenToNotifications(notificationService);
+ }
+ }
+ }
+}
diff --git a/src/dev/impl/DevToys/UI/Converters/NullToVisibilityConverter.cs b/src/dev/impl/DevToys/UI/Converters/NullToVisibilityConverter.cs
new file mode 100644
index 000000000..0bae04328
--- /dev/null
+++ b/src/dev/impl/DevToys/UI/Converters/NullToVisibilityConverter.cs
@@ -0,0 +1,50 @@
+#nullable enable
+
+using System;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Data;
+
+namespace DevToys.UI.Converters
+{
+ /// <summary>
+ /// Converts a null value to a <see cref="Visibility"/> value.
+ /// </summary>
+ public sealed class NullToVisibilityConverter : IValueConverter
+ {
+ public bool IsInverted { get; set; }
+
+ public bool EnforceNonWhiteSpaceString { get; set; }
+
+ public object Convert(object value, Type targetType, object parameter, string language)
+ {
+ if (value?.GetType() == typeof(string))
+ {
+ if (IsInverted)
+ {
+ if (EnforceNonWhiteSpaceString)
+ {
+ return !string.IsNullOrWhiteSpace((string)value) ? Visibility.Visible : Visibility.Collapsed;
+ }
+ return !string.IsNullOrEmpty((string)value) ? Visibility.Visible : Visibility.Collapsed;
+ }
+
+ if (EnforceNonWhiteSpaceString)
+ {
+ return !string.IsNullOrWhiteSpace((string)value) ? Visibility.Visible : Visibility.Collapsed;
+ }
+ return string.IsNullOrEmpty((string)value) ? Visibility.Visible : Visibility.Collapsed;
+ }
+
+ if (IsInverted)
+ {
+ return value != null ? Visibility.Visible : Visibility.Collapsed;
+ }
+ return value == null ? Visibility.Visible : Visibility.Collapsed;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, string language)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/src/dev/impl/DevToys/ViewModels/MainPageViewModel.cs b/src/dev/impl/DevToys/ViewModels/MainPageViewModel.cs
index d8d27aafe..301a21933 100644
--- a/src/dev/impl/DevToys/ViewModels/MainPageViewModel.cs
+++ b/src/dev/impl/DevToys/ViewModels/MainPageViewModel.cs
@@ -23,7 +23,9 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
+using Windows.ApplicationModel;
using Windows.Foundation;
+using Windows.Management.Deployment;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using ThreadPriority = DevToys.Core.Threading.ThreadPriority;
@@ -37,6 +39,7 @@ namespace DevToys.ViewModels
private readonly IToolProviderFactory _toolProviderFactory;
private readonly IUriActivationProtocolService _launchProtocolService;
private readonly ISettingsProvider _settingsProvider;
+ private readonly INotificationService _notificationService;
private readonly List<MatchedToolProviderViewData> _allToolsMenuitems = new();
private readonly DisposableSempahore _sempahore = new();
private readonly Lazy<Task> _firstUpdateMenuTask;
@@ -198,15 +201,16 @@ namespace DevToys.ViewModels
ITitleBar titleBar,
IToolProviderFactory toolProviderFactory,
IUriActivationProtocolService launchProtocolService,
- ISettingsProvider settingsProvider)
+ ISettingsProvider settingsProvider,
+ INotificationService notificationService)
{
_clipboard = clipboard;
_toolProviderFactory = toolProviderFactory;
_launchProtocolService = launchProtocolService;
_settingsProvider = settingsProvider;
+ _notificationService = notificationService;
TitleBar = titleBar;
- NavigationViewItemClickCommand = new RelayCommand<MatchedToolProviderViewData>(ExecuteNavigationViewItemClickCommand);
OpenToolInNewWindowCommand = new AsyncRelayCommand<ToolProviderMetadata>(ExecuteOpenToolInNewWindowCommandAsync);
ChangeViewModeCommand = new AsyncRelayCommand<ApplicationViewMode>(ExecuteChangeViewModeCommandAsync);
@@ -218,18 +222,6 @@ namespace DevToys.ViewModels
IsActive = true;
}
- #region NavigationViewItemClickCommand
-
- public IRelayCommand<MatchedToolProviderViewData> NavigationViewItemClickCommand { get; }
-
- private void ExecuteNavigationViewItemClickCommand(MatchedToolProviderViewData? item)
- {
- Arguments.NotNull(item, nameof(item));
- SelectedMenuItem = item;
- }
-
- #endregion
-
#region OpenToolInNewWindowCommand
public IAsyncRelayCommand<ToolProviderMetadata> OpenToolInNewWindowCommand { get; }
@@ -297,6 +289,9 @@ namespace DevToys.ViewModels
}
}
+ ShowReleaseNoteAsync().Forget();
+ ShowAvailableUpdateAsync().Forget();
+
await ThreadHelper.RunOnUIThreadAsync(
ThreadPriority.Low,
() =>
@@ -475,6 +470,56 @@ namespace DevToys.ViewModels
}
}
+ private async Task ShowReleaseNoteAsync()
+ {
+ // Make sure we work in background.
+ await TaskScheduler.Default;
+
+ PackageVersion v = Package.Current.Id.Version;
+ string currentVersion = $"{v.Major}.{v.Minor}.{v.Build}.{v.Revision}";
+ string lastVersion = _settingsProvider.GetSetting(PredefinedSettings.LastVersionRan);
+
+ if (!_settingsProvider.GetSetting(PredefinedSettings.FirstTimeStart) && currentVersion != lastVersion)
+ {
+ _notificationService.ShowInAppNotification(
+ Strings.GetFormattedNotificationReleaseNoteTitle(currentVersion),
+ Strings.NotificationReleaseNoteActionableActionText,
+ () =>
+ {
+ ThreadHelper.ThrowIfNotOnUIThread();
+ Windows.System.Launcher.LaunchUriAsync(new Uri("https://github.com/veler/DevToys/releases")).AsTask().Forget();
+ },
+ await AssetsHelper.GetReleaseNoteAsync());
+ }
+
+ _settingsProvider.SetSetting(PredefinedSettings.FirstTimeStart, false);
+ _settingsProvider.SetSetting(PredefinedSettings.LastVersionRan, currentVersion);
+ }
+
+ private async Task ShowAvailableUpdateAsync()
+ {
+ // 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();
+
+ if (result.Availability == PackageUpdateAvailability.Required || result.Availability == PackageUpdateAvailability.Available)
+ {
+ _notificationService.ShowInAppNotification(
+ Strings.NotificationUpdateAvailableTitle,
+ Strings.NotificationUpdateAvailableActionableActionText,
+ () =>
+ {
+ ThreadHelper.ThrowIfNotOnUIThread();
+ Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store://downloadsandupdates")).AsTask().Forget();
+ });
+ }
+ }
+
private void Window_Activated(object sender, Windows.UI.Core.WindowActivatedEventArgs e)
{
if (e.WindowActivationState
diff --git a/src/dev/impl/DevToys/Views/MainPage.xaml b/src/dev/impl/DevToys/Views/MainPage.xaml
index 8c9115d97..ac18e2f1b 100644
--- a/src/dev/impl/DevToys/Views/MainPage.xaml
+++ b/src/dev/impl/DevToys/Views/MainPage.xaml
@@ -234,5 +234,7 @@
<Frame x:Name="contentFrame" />
</ScrollViewer>
</muxc:NavigationView>
+
+ <controls:Notification x:Name="NotificationControl"/>
</Grid>
</Page>
diff --git a/src/dev/impl/DevToys/Views/MainPage.xaml.cs b/src/dev/impl/DevToys/Views/MainPage.xaml.cs
index aeb133273..6226cc555 100644
--- a/src/dev/impl/DevToys/Views/MainPage.xaml.cs
+++ b/src/dev/impl/DevToys/Views/MainPage.xaml.cs
@@ -1,5 +1,6 @@
#nullable enable
+using DevToys.Api.Core;
using DevToys.Api.Core.Injection;
using DevToys.Api.Core.Navigation;
using DevToys.Core;
@@ -51,10 +52,13 @@ namespace DevToys.Views
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
Assumes.NotNull(_parameters, nameof(_parameters));
+ Assumes.NotNull(_mefProvider, nameof(_mefProvider));
// Calling OnNavigatedToAsync in Loaded event instead of OnNavigatedTo because it needs access to CoreDispatcher,
// which isn't available before the main window is created.
ViewModel.OnNavigatedToAsync(_parameters!).Forget();
+
+ NotificationControl.NotificationService = _mefProvider!.Import<INotificationService>();
}
protected override void OnNavigatedTo(NavigationEventArgs e)