@@ -21,12 +21,16 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2121OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222SOFTWARE.
2323*/
24+ using Hardcodet . Wpf . TaskbarNotification ;
2425using InternetTest . Commands ;
2526using InternetTest . Enums ;
2627using InternetTest . Helpers ;
2728using InternetTest . Interfaces ;
2829using InternetTest . Models ;
2930using InternetTest . ViewModels . Components ;
31+ using PeyrSharp . Core ;
32+ using PeyrSharp . Env ;
33+ using System . IO ;
3034using System . Windows ;
3135using 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