mirror of
https://github.com/ckaczor/ProcessCpuUsageStatusWindow.git
synced 2026-01-15 01:25:39 -05:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d9d0f33788 | |||
| 8f550463b7 |
@@ -4,21 +4,43 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:windows="clr-namespace:Common.Wpf.Windows;assembly=Common.Wpf"
|
xmlns:windows="clr-namespace:Common.Wpf.Windows;assembly=Common.Wpf"
|
||||||
|
xmlns:properties="clr-namespace:ProcessCpuUsageStatusWindow.Properties"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="300"
|
d:DesignHeight="300"
|
||||||
d:DesignWidth="300">
|
d:DesignWidth="300">
|
||||||
<Grid>
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"></RowDefinition>
|
||||||
|
<RowDefinition Height="Auto"></RowDefinition>
|
||||||
|
<RowDefinition Height="Auto"></RowDefinition>
|
||||||
|
<RowDefinition Height="Auto"></RowDefinition>
|
||||||
|
<RowDefinition Height="*"></RowDefinition>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
<TextBlock Text="[Application Name]"
|
<TextBlock Text="[Application Name]"
|
||||||
Name="ApplicationNameLabel"
|
Name="ApplicationNameLabel"
|
||||||
VerticalAlignment="Top"
|
VerticalAlignment="Top"
|
||||||
FontWeight="Bold" />
|
FontWeight="Bold"
|
||||||
|
Grid.Row="0" />
|
||||||
<TextBlock Text="[Application Version]"
|
<TextBlock Text="[Application Version]"
|
||||||
Margin="0,22,0,0"
|
Margin="0,6,0,0"
|
||||||
Name="VersionLabel"
|
Name="VersionLabel"
|
||||||
VerticalAlignment="Top" />
|
VerticalAlignment="Top"
|
||||||
|
Grid.Row="1" />
|
||||||
<TextBlock Text="[Company]"
|
<TextBlock Text="[Company]"
|
||||||
Margin="0,44,0,0"
|
Margin="0,6,0,0"
|
||||||
Name="CompanyLabel"
|
Name="CompanyLabel"
|
||||||
VerticalAlignment="Top" />
|
VerticalAlignment="Top"
|
||||||
|
Grid.Row="2" />
|
||||||
|
<StackPanel Grid.Row="3"
|
||||||
|
Grid.Column="0"
|
||||||
|
Margin="0,20,0,0"
|
||||||
|
Orientation="Horizontal">
|
||||||
|
<Button Content="{x:Static properties:Resources.CheckUpdate}"
|
||||||
|
HorizontalAlignment="Left"
|
||||||
|
Padding="6,2"
|
||||||
|
Click="HandleCheckForUpdateButtonClick"
|
||||||
|
VerticalContentAlignment="Center" />
|
||||||
|
<Label Name="UpdateMessage" Content="" VerticalContentAlignment="Center" Padding="6,0" />
|
||||||
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</windows:CategoryPanel>
|
</windows:CategoryPanel>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using Common.Update;
|
using System.Reflection;
|
||||||
using System.Reflection;
|
using System.Windows;
|
||||||
|
|
||||||
namespace ProcessCpuUsageStatusWindow.Options
|
namespace ProcessCpuUsageStatusWindow.Options
|
||||||
{
|
{
|
||||||
@@ -32,5 +32,10 @@ namespace ProcessCpuUsageStatusWindow.Options
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override string CategoryName => Properties.Resources.OptionCategory_About;
|
public override string CategoryName => Properties.Resources.OptionCategory_About;
|
||||||
|
|
||||||
|
private async void HandleCheckForUpdateButtonClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
await UpdateCheck.CheckUpdate((status, message) => UpdateMessage.Content = message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,14 +27,16 @@
|
|||||||
<Label Grid.Column="0"
|
<Label Grid.Column="0"
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
Content="{x:Static properties:Resources.NumberOfProcesses}"
|
Content="{x:Static properties:Resources.NumberOfProcesses}"
|
||||||
Margin="0,6,6,6"
|
Margin="0,4,6,0"
|
||||||
Padding="0"
|
Padding="0"
|
||||||
VerticalContentAlignment="Center" VerticalAlignment="Center" />
|
VerticalContentAlignment="Center" VerticalAlignment="Center" Target="{x:Reference NumberOfProcesses}" />
|
||||||
<xctk:IntegerUpDown Grid.Column="1"
|
<xctk:IntegerUpDown Grid.Column="1"
|
||||||
Grid.Row="1" x:Name="NumberOfProcesses"
|
Grid.Row="1" x:Name="NumberOfProcesses"
|
||||||
Minimum="1" Maximum="20"
|
Minimum="1" Maximum="20"
|
||||||
TextAlignment="Left" Margin="6"
|
TextAlignment="Left" Margin="0,12,6,6"
|
||||||
Width="50"
|
Width="50"
|
||||||
|
VerticalContentAlignment="Center"
|
||||||
|
VerticalAlignment="Center"
|
||||||
HorizontalAlignment="Left" />
|
HorizontalAlignment="Left" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</windows:CategoryPanel>
|
</windows:CategoryPanel>
|
||||||
|
|||||||
@@ -136,6 +136,7 @@
|
|||||||
<Compile Include="Options\GeneralOptionsPanel.xaml.cs">
|
<Compile Include="Options\GeneralOptionsPanel.xaml.cs">
|
||||||
<DependentUpon>GeneralOptionsPanel.xaml</DependentUpon>
|
<DependentUpon>GeneralOptionsPanel.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="UpdateCheck.cs" />
|
||||||
<Compile Include="WindowSource.cs" />
|
<Compile Include="WindowSource.cs" />
|
||||||
<Page Include="Options\AboutOptionsPanel.xaml">
|
<Page Include="Options\AboutOptionsPanel.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
|||||||
54
Properties/Resources.Designer.cs
generated
54
Properties/Resources.Designer.cs
generated
@@ -88,6 +88,33 @@ namespace ProcessCpuUsageStatusWindow.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Checking for update....
|
||||||
|
/// </summary>
|
||||||
|
public static string CheckingForUpdate {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("CheckingForUpdate", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to _Check for Update.
|
||||||
|
/// </summary>
|
||||||
|
public static string CheckUpdate {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("CheckUpdate", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Downloading update....
|
||||||
|
/// </summary>
|
||||||
|
public static string DownloadingUpdate {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("DownloadingUpdate", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to CPU: {0,4:f1}% - Total.
|
/// Looks up a localized string similar to CPU: {0,4:f1}% - Total.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -106,6 +133,15 @@ namespace ProcessCpuUsageStatusWindow.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Installing update....
|
||||||
|
/// </summary>
|
||||||
|
public static string InstallingUpdate {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("InstallingUpdate", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Loading....
|
/// Looks up a localized string similar to Loading....
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -115,6 +151,15 @@ namespace ProcessCpuUsageStatusWindow.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to No update found.
|
||||||
|
/// </summary>
|
||||||
|
public static string NoUpdate {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("NoUpdate", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to _Number of processes:.
|
/// Looks up a localized string similar to _Number of processes:.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -188,6 +233,15 @@ namespace ProcessCpuUsageStatusWindow.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Restarting application....
|
||||||
|
/// </summary>
|
||||||
|
public static string RestartingAfterUpdate {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("RestartingAfterUpdate", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to _Start when Windows starts.
|
/// Looks up a localized string similar to _Start when Windows starts.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -127,15 +127,30 @@
|
|||||||
<data name="ApplicationName" xml:space="preserve">
|
<data name="ApplicationName" xml:space="preserve">
|
||||||
<value>Process CPU Usage</value>
|
<value>Process CPU Usage</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="CheckingForUpdate" xml:space="preserve">
|
||||||
|
<value>Checking for update...</value>
|
||||||
|
</data>
|
||||||
|
<data name="CheckUpdate" xml:space="preserve">
|
||||||
|
<value>_Check for Update</value>
|
||||||
|
</data>
|
||||||
|
<data name="DownloadingUpdate" xml:space="preserve">
|
||||||
|
<value>Downloading update...</value>
|
||||||
|
</data>
|
||||||
<data name="FooterLine" xml:space="preserve">
|
<data name="FooterLine" xml:space="preserve">
|
||||||
<value>CPU: {0,4:f1}% - Total</value>
|
<value>CPU: {0,4:f1}% - Total</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="HeaderLine" xml:space="preserve">
|
<data name="HeaderLine" xml:space="preserve">
|
||||||
<value />
|
<value />
|
||||||
</data>
|
</data>
|
||||||
|
<data name="InstallingUpdate" xml:space="preserve">
|
||||||
|
<value>Installing update...</value>
|
||||||
|
</data>
|
||||||
<data name="Loading" xml:space="preserve">
|
<data name="Loading" xml:space="preserve">
|
||||||
<value>Loading...</value>
|
<value>Loading...</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="NoUpdate" xml:space="preserve">
|
||||||
|
<value>No update found</value>
|
||||||
|
</data>
|
||||||
<data name="NumberOfProcesses" xml:space="preserve">
|
<data name="NumberOfProcesses" xml:space="preserve">
|
||||||
<value>_Number of processes:</value>
|
<value>_Number of processes:</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -166,4 +181,7 @@
|
|||||||
<data name="Updating" xml:space="preserve">
|
<data name="Updating" xml:space="preserve">
|
||||||
<value>Updating application...</value>
|
<value>Updating application...</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="RestartingAfterUpdate" xml:space="preserve">
|
||||||
|
<value>Restarting application...</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
71
UpdateCheck.cs
Normal file
71
UpdateCheck.cs
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
using Squirrel;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProcessCpuUsageStatusWindow
|
||||||
|
{
|
||||||
|
public static class UpdateCheck
|
||||||
|
{
|
||||||
|
public enum UpdateStatus
|
||||||
|
{
|
||||||
|
Checking,
|
||||||
|
None,
|
||||||
|
Downloading,
|
||||||
|
Installing,
|
||||||
|
Restarting
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate void UpdateStatusDelegate(UpdateStatus updateStatus, string message);
|
||||||
|
|
||||||
|
public static Version LocalVersion => Assembly.GetEntryAssembly().GetName().Version;
|
||||||
|
|
||||||
|
public static async Task<bool> CheckUpdate(UpdateStatusDelegate onUpdateStatus)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
onUpdateStatus.Invoke(UpdateStatus.Checking, Properties.Resources.CheckingForUpdate);
|
||||||
|
|
||||||
|
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
||||||
|
|
||||||
|
using (var updateManager = await UpdateManager.GitHubUpdateManager(App.UpdateUrl))
|
||||||
|
{
|
||||||
|
var updates = await updateManager.CheckForUpdate();
|
||||||
|
|
||||||
|
var lastVersion = updates?.ReleasesToApply?.OrderBy(releaseEntry => releaseEntry.Version).LastOrDefault();
|
||||||
|
|
||||||
|
if (lastVersion == null)
|
||||||
|
{
|
||||||
|
onUpdateStatus.Invoke(UpdateStatus.None, Properties.Resources.NoUpdate);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
onUpdateStatus.Invoke(UpdateStatus.Downloading, Properties.Resources.DownloadingUpdate);
|
||||||
|
|
||||||
|
Common.Settings.Extensions.BackupSettings();
|
||||||
|
|
||||||
|
await updateManager.DownloadReleases(new[] { lastVersion });
|
||||||
|
|
||||||
|
onUpdateStatus.Invoke(UpdateStatus.Installing, Properties.Resources.InstallingUpdate);
|
||||||
|
|
||||||
|
await updateManager.ApplyReleases(updates);
|
||||||
|
await updateManager.UpdateApp();
|
||||||
|
}
|
||||||
|
|
||||||
|
onUpdateStatus.Invoke(UpdateStatus.Restarting, Properties.Resources.RestartingAfterUpdate);
|
||||||
|
|
||||||
|
UpdateManager.RestartApp();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
Console.WriteLine(exception);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,48 +29,28 @@ namespace ProcessCpuUsageStatusWindow
|
|||||||
|
|
||||||
_processCpuUsageWatcher = new ProcessCpuUsageWatcher();
|
_processCpuUsageWatcher = new ProcessCpuUsageWatcher();
|
||||||
|
|
||||||
Task.Factory.StartNew(UpdateApp);
|
Task.Factory.StartNew(UpdateApp).ContinueWith(task => StartUpdate(task.Result.Result));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UpdateApp()
|
private void StartUpdate(bool updateRequired)
|
||||||
{
|
{
|
||||||
try
|
if (updateRequired)
|
||||||
{
|
return;
|
||||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
|
||||||
|
|
||||||
using (var updateManager = await UpdateManager.GitHubUpdateManager(App.UpdateUrl))
|
Task.Factory.StartNew(() => _processCpuUsageWatcher.Initialize(Settings.Default.UpdateInterval, UpdateDisplay, _dispatcher));
|
||||||
{
|
}
|
||||||
var updates = await updateManager.CheckForUpdate();
|
|
||||||
|
|
||||||
var lastVersion = updates?.ReleasesToApply?.OrderBy(releaseEntry => releaseEntry.Version).LastOrDefault();
|
private async Task<bool> UpdateApp()
|
||||||
|
{
|
||||||
|
return await UpdateCheck.CheckUpdate(HandleUpdateStatus);
|
||||||
|
}
|
||||||
|
|
||||||
if (lastVersion == null)
|
private void HandleUpdateStatus(UpdateCheck.UpdateStatus status, string message)
|
||||||
return;
|
{
|
||||||
|
if (status == UpdateCheck.UpdateStatus.None)
|
||||||
|
message = Resources.Loading;
|
||||||
|
|
||||||
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.Updating));
|
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(message));
|
||||||
Thread.Sleep(500);
|
|
||||||
|
|
||||||
Common.Settings.Extensions.BackupSettings();
|
|
||||||
|
|
||||||
#if !DEBUG
|
|
||||||
await updateManager.DownloadReleases(new[] { lastVersion });
|
|
||||||
await updateManager.ApplyReleases(updates);
|
|
||||||
await updateManager.UpdateApp();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !DEBUG
|
|
||||||
UpdateManager.RestartApp();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
Console.WriteLine(exception);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
await Task.Factory.StartNew(() => _processCpuUsageWatcher.Initialize(Settings.Default.UpdateInterval, UpdateDisplay, _dispatcher));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
@@ -141,7 +121,7 @@ namespace ProcessCpuUsageStatusWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateDisplay(Dictionary<string, ProcessCpuUsage> currentProcessList)
|
private void UpdateDisplay(Dictionary<string, ProcessCpuUsage> currentProcessList)
|
||||||
{
|
{
|
||||||
// Filter the process list to valid ones and exclude the idle and total values
|
// Filter the process list to valid ones and exclude the idle and total values
|
||||||
var validProcessList = (currentProcessList.Values.Where(
|
var validProcessList = (currentProcessList.Values.Where(
|
||||||
process =>
|
process =>
|
||||||
|
|||||||
Reference in New Issue
Block a user