mirror of
https://github.com/ckaczor/WorldClockStatusWindow.git
synced 2026-01-13 17:23:18 -05:00
Add update settings panel
This commit is contained in:
@@ -22,6 +22,9 @@
|
|||||||
<setting name="TimeZones" serializeAs="String">
|
<setting name="TimeZones" serializeAs="String">
|
||||||
<value>[]</value>
|
<value>[]</value>
|
||||||
</setting>
|
</setting>
|
||||||
|
<setting name="CheckVersionAtStartup" serializeAs="String">
|
||||||
|
<value>True</value>
|
||||||
|
</setting>
|
||||||
</WorldClockStatusWindow.Properties.Settings>
|
</WorldClockStatusWindow.Properties.Settings>
|
||||||
</userSettings>
|
</userSettings>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -1,16 +1,12 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using NuGet.Versioning;
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using System;
|
using System;
|
||||||
using Velopack;
|
using Velopack;
|
||||||
using Velopack.Sources;
|
|
||||||
|
|
||||||
namespace WorldClockStatusWindow;
|
namespace WorldClockStatusWindow;
|
||||||
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
private static UpdateManager _updateManager;
|
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
@@ -28,8 +24,4 @@ internal class Program
|
|||||||
|
|
||||||
Log.Logger.Information("End");
|
Log.Logger.Information("End");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UpdateManager UpdateManager => _updateManager ??= new UpdateManager(new GithubSource("https://github.com/ckaczor/WorldClockStatusWindow", null, false));
|
|
||||||
|
|
||||||
public static string LocalVersion => (UpdateManager.CurrentVersion ?? new SemanticVersion(0, 0, 0)).ToString();
|
|
||||||
}
|
}
|
||||||
58
Properties/Resources.Designer.cs
generated
58
Properties/Resources.Designer.cs
generated
@@ -88,6 +88,24 @@ namespace WorldClockStatusWindow.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Check _Now.
|
||||||
|
/// </summary>
|
||||||
|
public static string checkVersionNowButton {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("checkVersionNowButton", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to _Check for a new version on startup.
|
||||||
|
/// </summary>
|
||||||
|
public static string checkVersionOnStartupCheckBox {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("checkVersionOnStartupCheckBox", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Close.
|
/// Looks up a localized string similar to Close.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -115,6 +133,15 @@ namespace WorldClockStatusWindow.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Update.
|
||||||
|
/// </summary>
|
||||||
|
public static string optionCategoryUpdate {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("optionCategoryUpdate", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Settings.
|
/// Looks up a localized string similar to Settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -133,6 +160,37 @@ namespace WorldClockStatusWindow.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to You are already running the most recent version.
|
||||||
|
///
|
||||||
|
///No updates are available at this time..
|
||||||
|
/// </summary>
|
||||||
|
public static string UpdateCheckCurrent {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("UpdateCheckCurrent", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Version {1} of {0} is now available.
|
||||||
|
///
|
||||||
|
///Would you like to download and install it now?.
|
||||||
|
/// </summary>
|
||||||
|
public static string UpdateCheckNewVersion {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("UpdateCheckNewVersion", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to {0} Update.
|
||||||
|
/// </summary>
|
||||||
|
public static string UpdateCheckTitle {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("UpdateCheckTitle", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Version {0}.
|
/// Looks up a localized string similar to Version {0}.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -145,4 +145,26 @@
|
|||||||
<data name="Version" xml:space="preserve">
|
<data name="Version" xml:space="preserve">
|
||||||
<value>Version {0}</value>
|
<value>Version {0}</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="optionCategoryUpdate" xml:space="preserve">
|
||||||
|
<value>Update</value>
|
||||||
|
</data>
|
||||||
|
<data name="checkVersionOnStartupCheckBox" xml:space="preserve">
|
||||||
|
<value>_Check for a new version on startup</value>
|
||||||
|
</data>
|
||||||
|
<data name="checkVersionNowButton" xml:space="preserve">
|
||||||
|
<value>Check _Now</value>
|
||||||
|
</data>
|
||||||
|
<data name="UpdateCheckTitle" xml:space="preserve">
|
||||||
|
<value>{0} Update</value>
|
||||||
|
</data>
|
||||||
|
<data name="UpdateCheckCurrent" xml:space="preserve">
|
||||||
|
<value>You are already running the most recent version.
|
||||||
|
|
||||||
|
No updates are available at this time.</value>
|
||||||
|
</data>
|
||||||
|
<data name="UpdateCheckNewVersion" xml:space="preserve">
|
||||||
|
<value>Version {1} of {0} is now available.
|
||||||
|
|
||||||
|
Would you like to download and install it now?</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
12
Properties/Settings.Designer.cs
generated
12
Properties/Settings.Designer.cs
generated
@@ -70,5 +70,17 @@ namespace WorldClockStatusWindow.Properties {
|
|||||||
this["TimeZones"] = value;
|
this["TimeZones"] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Configuration.DefaultSettingValueAttribute("True")]
|
||||||
|
public bool CheckVersionAtStartup {
|
||||||
|
get {
|
||||||
|
return ((bool)(this["CheckVersionAtStartup"]));
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
this["CheckVersionAtStartup"] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,5 +14,8 @@
|
|||||||
<Setting Name="TimeZones" Type="System.String" Scope="User">
|
<Setting Name="TimeZones" Type="System.String" Scope="User">
|
||||||
<Value Profile="(Default)">[]</Value>
|
<Value Profile="(Default)">[]</Value>
|
||||||
</Setting>
|
</Setting>
|
||||||
|
<Setting Name="CheckVersionAtStartup" Type="System.Boolean" Scope="User">
|
||||||
|
<Value Profile="(Default)">True</Value>
|
||||||
|
</Setting>
|
||||||
</Settings>
|
</Settings>
|
||||||
</SettingsFile>
|
</SettingsFile>
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
<StackPanel windows:Spacing.Vertical="10">
|
<StackPanel windows:Spacing.Vertical="10">
|
||||||
<TextBlock Text="{x:Static properties:Resources.ApplicationName}"
|
<TextBlock Text="{x:Static properties:Resources.ApplicationName}"
|
||||||
FontWeight="Bold" />
|
FontWeight="Bold" />
|
||||||
<TextBlock Text="{Binding Source={x:Static worldClockStatusWindow:Program.LocalVersion}, StringFormat={x:Static properties:Resources.Version}}"
|
<TextBlock Text="{Binding Source={x:Static worldClockStatusWindow:UpdateCheck.LocalVersion}, StringFormat={x:Static properties:Resources.Version}}"
|
||||||
Name="VersionLabel" />
|
Name="VersionLabel" />
|
||||||
<TextBlock Text="Chris Kaczor" />
|
<TextBlock Text="Chris Kaczor" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
22
SettingsWindow/UpdateSettingsPanel.xaml
Normal file
22
SettingsWindow/UpdateSettingsPanel.xaml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<windows:CategoryPanelBase x:Class="WorldClockStatusWindow.SettingsWindow.UpdateSettingsPanel"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:properties="clr-namespace:WorldClockStatusWindow.Properties"
|
||||||
|
xmlns:windows="clr-namespace:ChrisKaczor.Wpf.Windows;assembly=ChrisKaczor.Wpf.Windows.CategoryWindow"
|
||||||
|
xmlns:worldClockStatusWindow="clr-namespace:WorldClockStatusWindow"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DesignHeight="150"
|
||||||
|
d:DesignWidth="250">
|
||||||
|
<StackPanel windows:Spacing.Vertical="10">
|
||||||
|
<CheckBox Content="{x:Static properties:Resources.checkVersionOnStartupCheckBox}"
|
||||||
|
Name="CheckVersionOnStartupCheckBox"
|
||||||
|
IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=CheckVersionAtStartup}"
|
||||||
|
Click="OnSaveSettings" />
|
||||||
|
<Button Content="{x:Static properties:Resources.checkVersionNowButton}"
|
||||||
|
IsEnabled="{Binding Source={x:Static worldClockStatusWindow:UpdateCheck.IsInstalled}}"
|
||||||
|
HorizontalAlignment="Left"
|
||||||
|
Click="HandleCheckVersionNowButtonClick" />
|
||||||
|
</StackPanel>
|
||||||
|
</windows:CategoryPanelBase>
|
||||||
31
SettingsWindow/UpdateSettingsPanel.xaml.cs
Normal file
31
SettingsWindow/UpdateSettingsPanel.xaml.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using System.Windows;
|
||||||
|
using WorldClockStatusWindow.Properties;
|
||||||
|
|
||||||
|
namespace WorldClockStatusWindow.SettingsWindow;
|
||||||
|
|
||||||
|
public partial class UpdateSettingsPanel
|
||||||
|
{
|
||||||
|
public UpdateSettingsPanel()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string CategoryName => Properties.Resources.optionCategoryUpdate;
|
||||||
|
|
||||||
|
private void HandleCheckVersionNowButtonClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
UpdateCheck.DisplayUpdateInformation(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnSaveSettings(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
SaveSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveSettings()
|
||||||
|
{
|
||||||
|
if (!HasLoaded) return;
|
||||||
|
|
||||||
|
Settings.Default.Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
60
UpdateCheck.cs
Normal file
60
UpdateCheck.cs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
using NuGet.Versioning;
|
||||||
|
using Serilog;
|
||||||
|
using System.Windows;
|
||||||
|
using Velopack;
|
||||||
|
using Velopack.Sources;
|
||||||
|
|
||||||
|
namespace WorldClockStatusWindow
|
||||||
|
{
|
||||||
|
internal static class UpdateCheck
|
||||||
|
{
|
||||||
|
private static UpdateManager _updateManager;
|
||||||
|
|
||||||
|
public static UpdateManager UpdateManager => _updateManager ??= new UpdateManager(new GithubSource("https://github.com/ckaczor/WorldClockStatusWindow", null, false));
|
||||||
|
|
||||||
|
public static string LocalVersion => (UpdateManager.CurrentVersion ?? new SemanticVersion(0, 0, 0)).ToString();
|
||||||
|
|
||||||
|
public static bool IsInstalled => UpdateManager.IsInstalled;
|
||||||
|
|
||||||
|
public static async void DisplayUpdateInformation(bool showIfCurrent)
|
||||||
|
{
|
||||||
|
UpdateInfo newVersion = null;
|
||||||
|
|
||||||
|
if (IsInstalled)
|
||||||
|
{
|
||||||
|
newVersion = await UpdateManager.CheckForUpdatesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newVersion != null)
|
||||||
|
{
|
||||||
|
// Format the check title
|
||||||
|
var updateCheckTitle = string.Format(Properties.Resources.UpdateCheckTitle, Properties.Resources.ApplicationName);
|
||||||
|
|
||||||
|
// Format the message
|
||||||
|
var updateCheckMessage = string.Format(Properties.Resources.UpdateCheckNewVersion, Properties.Resources.ApplicationName, newVersion.TargetFullRelease.Version);
|
||||||
|
|
||||||
|
// Ask the user to update
|
||||||
|
if (MessageBox.Show(updateCheckMessage, updateCheckTitle, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Log.Logger.Information("Downloading update");
|
||||||
|
|
||||||
|
await UpdateManager.DownloadUpdatesAsync(newVersion);
|
||||||
|
|
||||||
|
Log.Logger.Information("Installing update");
|
||||||
|
|
||||||
|
UpdateManager.ApplyUpdatesAndRestart(newVersion);
|
||||||
|
}
|
||||||
|
else if (showIfCurrent)
|
||||||
|
{
|
||||||
|
// Format the check title
|
||||||
|
var updateCheckTitle = string.Format(Properties.Resources.UpdateCheckTitle, Properties.Resources.ApplicationName);
|
||||||
|
|
||||||
|
// Format the message
|
||||||
|
var updateCheckMessage = string.Format(Properties.Resources.UpdateCheckCurrent, Properties.Resources.ApplicationName);
|
||||||
|
|
||||||
|
MessageBox.Show(updateCheckMessage, updateCheckTitle, MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using ChrisKaczor.Wpf.Windows.FloatingStatusWindow;
|
using ChrisKaczor.Wpf.Windows;
|
||||||
|
using ChrisKaczor.Wpf.Windows.FloatingStatusWindow;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -9,7 +10,6 @@ using System.Text.Json;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using ChrisKaczor.Wpf.Windows;
|
|
||||||
using WorldClockStatusWindow.SettingsWindow;
|
using WorldClockStatusWindow.SettingsWindow;
|
||||||
|
|
||||||
namespace WorldClockStatusWindow;
|
namespace WorldClockStatusWindow;
|
||||||
@@ -38,14 +38,17 @@ internal class WindowSource : IWindowSource, IDisposable
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!Program.UpdateManager.IsInstalled)
|
if (!UpdateCheck.IsInstalled)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Properties.Settings.Default.CheckVersionAtStartup)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Log.Logger.Information("Checking for update");
|
Log.Logger.Information("Checking for update");
|
||||||
|
|
||||||
await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Checking for update..."));
|
await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Checking for update..."));
|
||||||
|
|
||||||
var newVersion = await Program.UpdateManager.CheckForUpdatesAsync();
|
var newVersion = await UpdateCheck.UpdateManager.CheckForUpdatesAsync();
|
||||||
|
|
||||||
if (newVersion == null)
|
if (newVersion == null)
|
||||||
return false;
|
return false;
|
||||||
@@ -54,13 +57,13 @@ internal class WindowSource : IWindowSource, IDisposable
|
|||||||
|
|
||||||
await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Downloading update..."));
|
await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Downloading update..."));
|
||||||
|
|
||||||
await Program.UpdateManager.DownloadUpdatesAsync(newVersion);
|
await UpdateCheck.UpdateManager.DownloadUpdatesAsync(newVersion);
|
||||||
|
|
||||||
Log.Logger.Information("Installing update");
|
Log.Logger.Information("Installing update");
|
||||||
|
|
||||||
await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Installing update..."));
|
await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Installing update..."));
|
||||||
|
|
||||||
Program.UpdateManager.ApplyUpdatesAndRestart(newVersion);
|
UpdateCheck.UpdateManager.ApplyUpdatesAndRestart(newVersion);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -158,6 +161,7 @@ internal class WindowSource : IWindowSource, IDisposable
|
|||||||
var categoryPanels = new List<CategoryPanelBase>
|
var categoryPanels = new List<CategoryPanelBase>
|
||||||
{
|
{
|
||||||
new GeneralSettingsPanel(),
|
new GeneralSettingsPanel(),
|
||||||
|
new UpdateSettingsPanel(),
|
||||||
new AboutSettingsPanel()
|
new AboutSettingsPanel()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
2
WorldClockStatusWindow.sln.DotSettings
Normal file
2
WorldClockStatusWindow.sln.DotSettings
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Kaczor/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||||
Reference in New Issue
Block a user