|
1 | | -using System.Threading; |
| 1 | +using System; |
| 2 | +using System.Threading; |
2 | 3 | using System.Windows.Forms; |
3 | 4 | using CefSharp; |
4 | 5 | using CefSharp.WinForms.Internals; |
5 | 6 | using ServiceStack; |
| 7 | +using ServiceStack.Configuration; |
| 8 | +using Squirrel; |
6 | 9 |
|
7 | 10 | namespace ReactChat.AppWinForms |
8 | 11 | { |
@@ -140,6 +143,56 @@ public void Ready() |
140 | 143 | formMain.Controls.Remove(formMain.SplashPanel); |
141 | 144 | }); |
142 | 145 | } |
| 146 | + |
| 147 | + public void CheckForUpdates() |
| 148 | + { |
| 149 | + var appSettings = new AppSettings(); |
| 150 | + var checkForUpdates = appSettings.Get<bool>("EnableAutoUpdate"); |
| 151 | + if (!checkForUpdates) |
| 152 | + return; |
| 153 | + |
| 154 | + var releaseFolderUrl = appSettings.GetString("UpdateManagerUrl"); |
| 155 | + try |
| 156 | + { |
| 157 | + var updatesAvailableTask = AppUpdater.CheckForUpdates(releaseFolderUrl); |
| 158 | + updatesAvailableTask.ContinueWith(isAvailable => |
| 159 | + { |
| 160 | + isAvailable.Wait(TimeSpan.FromMinutes(1)); |
| 161 | + bool updatesAvailable = isAvailable.Result; |
| 162 | + //Only check once one launch then release UpdateManager. |
| 163 | + if (!updatesAvailable) |
| 164 | + { |
| 165 | + AppUpdater.Dispose(); |
| 166 | + return; |
| 167 | + } |
| 168 | + if (formMain == null) |
| 169 | + { |
| 170 | + return; |
| 171 | + } |
| 172 | + // Notify web client updates are available. |
| 173 | + formMain.InvokeOnUiThreadIfRequired(() => |
| 174 | + { |
| 175 | + formMain.ChromiumBrowser.GetMainFrame().ExecuteJavaScriptAsync("window.updateAvailable();"); |
| 176 | + }); |
| 177 | + }); |
| 178 | + } |
| 179 | + catch (Exception e) |
| 180 | + { |
| 181 | + // Error reaching update server |
| 182 | + } |
| 183 | + } |
| 184 | + |
| 185 | + public void PerformUpdate() |
| 186 | + { |
| 187 | + AppUpdater.ApplyUpdates(new AppSettings().GetString("UpdateManagerUrl")).ContinueWith(t => |
| 188 | + { |
| 189 | + formMain.InvokeOnUiThreadIfRequired(() => |
| 190 | + { |
| 191 | + formMain.Close(); |
| 192 | + }); |
| 193 | + UpdateManager.RestartApp(); |
| 194 | + }); |
| 195 | + } |
143 | 196 | } |
144 | 197 |
|
145 | 198 | #if DEBUG |
|
0 commit comments