Skip to content

Commit fdb3b85

Browse files
committed
Added a notification when updates are available
1 parent fcfb4c7 commit fdb3b85

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

InternetTest/InternetTest/InternetTest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
<ItemGroup>
3131
<PackageReference Include="DnsClient" Version="1.8.0" />
32+
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="2.0.1" />
3233
<PackageReference Include="ManagedNativeWifi" Version="3.0.2" />
3334
<PackageReference Include="MicaWPF.Lite" Version="6.3.0" />
3435
<PackageReference Include="PeyrSharp.Core" Version="2.1.0.2312" />

InternetTest/InternetTest/ViewModels/MainViewModel.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2121
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
SOFTWARE.
2323
*/
24+
using Hardcodet.Wpf.TaskbarNotification;
2425
using InternetTest.Commands;
2526
using InternetTest.Enums;
2627
using InternetTest.Helpers;
2728
using InternetTest.Interfaces;
2829
using InternetTest.Models;
2930
using InternetTest.ViewModels.Components;
31+
using PeyrSharp.Core;
32+
using PeyrSharp.Env;
33+
using System.IO;
3034
using System.Windows;
3135
using System.Windows.Input;
3236

@@ -103,7 +107,7 @@ public bool ConfidentialMode
103107
public ICommand ToggleConfidentialModeCommand => new RelayCommand(o =>
104108
{
105109
ConfidentialMode = !ConfidentialMode;
106-
});
110+
});
107111
public MainViewModel(Settings settings, ActivityHistory history, Window mainWindow)
108112
{
109113
Settings = settings;
@@ -130,6 +134,8 @@ public MainViewModel(Settings settings, ActivityHistory history, Window mainWind
130134

131135

132136
PinCommand = new RelayCommand(Pin);
137+
138+
CheckUpdates();
133139
}
134140

135141
public void Pin(object? obj)
@@ -142,4 +148,34 @@ public void Pin(object? obj)
142148
Settings.Save();
143149
}
144150
}
151+
152+
private async void CheckUpdates()
153+
{
154+
if (!Settings.CheckUpdateOnStart) return;
155+
if (!await Internet.IsAvailableAsync()) return;
156+
var lastVersion = await Update.GetLastVersionAsync(Context.UpdateVersionUrl);
157+
if (!Update.IsAvailable(Context.Version, lastVersion)) return;
158+
159+
var notify = new TaskbarIcon()
160+
{
161+
Icon = System.Drawing.Icon.ExtractAssociatedIcon(AppDomain.CurrentDomain.BaseDirectory + @"\InternetTest.exe"),
162+
ToolTipText = "InternetTest",
163+
};
164+
notify.TrayBalloonTipClosed += (s, e) => { notify.Dispose(); };
165+
notify.TrayBalloonTipClicked += (s, e) =>
166+
{
167+
#if PORTABLE
168+
MessageBox.Show(Properties.Resources.PortableNoAutoUpdates, $"{Properties.Resources.InstallVersion} {lastVersion}", MessageBoxButton.OK, MessageBoxImage.Information);
169+
return;
170+
#else
171+
if (MessageBox.Show(Properties.Resources.InstallConfirmMsg, $"{Properties.Resources.InstallVersion} {lastVersion}", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
172+
{
173+
Sys.ExecuteAsAdmin(Directory.GetCurrentDirectory() + @"\Xalyus Updater.exe"); // Start the updater
174+
Application.Current.Shutdown(); // Close
175+
}
176+
#endif
177+
notify.Dispose();
178+
};
179+
notify.ShowBalloonTip(Properties.Resources.Updates, Properties.Resources.AvailableUpdates, BalloonIcon.Info);
180+
}
145181
}

0 commit comments

Comments
 (0)