@@ -27,6 +27,7 @@ public sealed class TrayContext : ApplicationContext
2727 private ToolStripMenuItem _headerItem = null ! ;
2828 private ToolStripMenuItem _connectItem = null ! ;
2929 private ToolStripMenuItem _updateItem = null ! ;
30+ private ToolStripSeparator _updateSeparator = null ! ;
3031 private string ? _updateShown ;
3132 private BridgeStatus _prevAggregate = BridgeStatus . Unknown ;
3233
@@ -45,6 +46,8 @@ public TrayContext()
4546 ContextMenuStrip = BuildMenu ( ) ,
4647 } ;
4748 _icon . DoubleClick += ( _ , _ ) => _icon . ContextMenuStrip ? . Show ( Cursor . Position ) ;
49+ // Clicking the "update available" toast starts the update directly — no hunting for the tray menu.
50+ _icon . BalloonTipClicked += ( _ , _ ) => { if ( Updater . PendingVersion != null && ! Updater . IsApplying ) ApplyUpdate ( ) ; } ;
4851
4952 // Control plane (:8550) — the extension / desktop app see + drive the connection over the model.
5053 _control = new ControlServer ( Snapshot , ConnectById , ( ) => _conn . Disconnect ( ) , RestartWorker ) ;
@@ -64,11 +67,16 @@ private async Task TickAsync()
6467 await _conn . RefreshAsync ( ) ;
6568
6669 var agg = _conn . Aggregate ( ) ;
70+ var pending = Updater . PendingVersion ;
6771 _icon . Icon = StatusIcons . For ( agg ) ;
68- _icon . Text = Truncate ( "Volt Connector — " + StatusText ( ) , 63 ) ;
72+ // Tooltip surfaces the update too, so it's discoverable on hover even after the toast fades.
73+ var tip = "Volt Connector — " + StatusText ( ) + ( pending != null ? " · update available" : "" ) ;
74+ _icon . Text = Truncate ( tip , 63 ) ;
6975 if ( agg != _prevAggregate ) { OnAggregateChanged ( _prevAggregate , agg ) ; _prevAggregate = agg ; }
7076
71- _headerItem . Text = $ "Volt Connector · { Updater . CurrentVersion } ";
77+ _headerItem . Text = pending != null
78+ ? $ "Volt Connector · { Updater . CurrentVersion } → { pending } "
79+ : $ "Volt Connector · { Updater . CurrentVersion } ";
7280 RebuildConnectMenu ( ) ;
7381 ShowUpdateIfReady ( ) ;
7482 }
@@ -131,30 +139,38 @@ private ContextMenuStrip BuildMenu()
131139 menu . Items . Add ( _headerItem ) ;
132140 menu . Items . Add ( new ToolStripSeparator ( ) ) ;
133141
134- _connectItem = new ToolStripMenuItem ( "Connect to" ) { Image = Glyph ( "" ) } ; // Link
142+ // Update lives at the TOP (right under the header) so it's the first thing seen, accent-tinted + bold to
143+ // stand out. Hidden with its own separator until a newer release is available.
144+ _updateItem = new ToolStripMenuItem ( "Restart to update" , Glyph ( 0xE777 , VoltAccent ) , ( _ , _ ) => ApplyUpdate ( ) ) // UpdateRestore
145+ {
146+ Visible = false ,
147+ ForeColor = VoltAccent ,
148+ Font = new Font ( SystemFonts . MenuFont ?? new Font ( "Segoe UI" , 9f ) , FontStyle . Bold ) ,
149+ } ;
150+ _updateSeparator = new ToolStripSeparator { Visible = false } ;
151+ menu . Items . Add ( _updateItem ) ;
152+ menu . Items . Add ( _updateSeparator ) ;
153+
154+ _connectItem = new ToolStripMenuItem ( "Connect to" ) { Image = Glyph ( 0xE71B ) } ; // Link
135155 _connectItem . DropDownItems . Add ( new ToolStripMenuItem ( "(no project detected)" ) { Enabled = false } ) ;
136156 menu . Items . Add ( _connectItem ) ;
137157 menu . Items . Add ( new ToolStripSeparator ( ) ) ;
138158
139- _updateItem = new ToolStripMenuItem ( "Restart to update" , null , ( _ , _ ) =>
140- {
141- _updateItem . Enabled = false ;
142- _updateItem . Text = "Downloading update…" ;
143- Updater . RestartToApply ( ) ;
144- } ) { Visible = false , Image = Glyph ( "" ) } ; // UpdateRestore
145- menu . Items . Add ( _updateItem ) ;
146- menu . Items . Add ( new ToolStripMenuItem ( "Show logs" , Glyph ( "" ) , ( _ , _ ) => ShowLogs ( ) ) ) ; // Page
159+ menu . Items . Add ( new ToolStripMenuItem ( "Show logs" , Glyph ( 0xE7C3 ) , ( _ , _ ) => ShowLogs ( ) ) ) ; // Page
147160
148161 // ── Help ──
149162 menu . Items . Add ( new ToolStripSeparator ( ) ) ;
150- menu . Items . Add ( new ToolStripMenuItem ( "Activate in CODESYS…" , Glyph ( "" , VoltAccent ) , ( _ , _ ) => ShowCodesysActivation ( ) ) ) ; // Help
151- menu . Items . Add ( new ToolStripMenuItem ( "Exit" , Glyph ( "" ) , ( _ , _ ) => ExitThreadCore ( ) ) ) ; // ChromeClose
163+ menu . Items . Add ( new ToolStripMenuItem ( "Activate in CODESYS…" , Glyph ( 0xE897 , VoltAccent ) , ( _ , _ ) => ShowCodesysActivation ( ) ) ) ; // Help
164+ menu . Items . Add ( new ToolStripMenuItem ( "Exit" , Glyph ( 0xE8BB ) , ( _ , _ ) => ExitThreadCore ( ) ) ) ; // ChromeClose
152165 return menu ;
153166 }
154167
155168 // Volt's accent (blue), used to tint the help glyph so it reads as a help affordance.
156169 private static readonly Color VoltAccent = Color . FromArgb ( 0x2F , 0x7C , 0xF6 ) ;
157170
171+ /// <summary>Menu icon by Segoe MDL2 codepoint (e.g. 0xE777) — avoids embedding raw glyph chars in source.</summary>
172+ private static Image Glyph ( int codepoint , Color ? color = null ) => Glyph ( char . ConvertFromUtf32 ( codepoint ) , color ) ;
173+
158174 /// <summary>A 16×16 monochrome menu icon from the built-in Segoe MDL2 Assets glyph font (ships on
159175 /// Win10/11) — a themed icon with no image assets to bundle. Colour defaults to the menu text colour.</summary>
160176 private static Image Glyph ( string ch , Color ? color = null )
@@ -195,7 +211,7 @@ private void RebuildConnectMenu()
195211 }
196212 // Disconnect = clear the active connection (every host stays live). Enabled only when one is connected.
197213 _connectItem . DropDownItems . Add ( new ToolStripSeparator ( ) ) ;
198- _connectItem . DropDownItems . Add ( new ToolStripMenuItem ( "Disconnect" , Glyph ( "" ) , ( _ , _ ) => _conn . Disconnect ( ) ) // PowerButton
214+ _connectItem . DropDownItems . Add ( new ToolStripMenuItem ( "Disconnect" , Glyph ( 0xE7E8 ) , ( _ , _ ) => _conn . Disconnect ( ) ) // PowerButton
199215 {
200216 Enabled = _conn . ActiveConnection != null ,
201217 } ) ;
@@ -228,14 +244,56 @@ private void ShowLogs()
228244 private void ShowUpdateIfReady ( )
229245 {
230246 var pending = Updater . PendingVersion ;
231- if ( pending == null ) return ;
232- _updateItem . Visible = true ;
233- _updateItem . Enabled = ! Updater . IsApplying ;
234- _updateItem . Text = Updater . IsApplying ? "Downloading update…" : $ "Restart to update to { pending } ";
247+ var show = pending != null ;
248+ _updateItem . Visible = show ;
249+ _updateSeparator . Visible = show ;
250+ if ( ! show ) return ;
251+ // While a download/apply is in flight, ApplyUpdate owns the item's text/enabled state — don't fight it.
252+ if ( ! Updater . IsApplying )
253+ {
254+ _updateItem . Enabled = true ;
255+ _updateItem . Text = $ "Restart to update to { pending } ";
256+ }
235257 if ( pending == _updateShown ) return ;
236258 _updateShown = pending ;
237259 _icon . ShowBalloonTip ( 8000 , "Volt update available" ,
238- $ "Volt { pending } is available. Pick “Restart to update to { pending } ” from the tray.", ToolTipIcon . Info ) ;
260+ $ "Volt { pending } is available — click here to update, or pick “Restart to update” from the tray.", ToolTipIcon . Info ) ;
261+ }
262+
263+ // The one-click update: download the installer, THEN orderly-stop everything holding {app} files so Inno's
264+ // silent upgrade never fails on a lock the Restart Manager can't clear (a tray/Electron window), then launch
265+ // it and exit. async void is correct here — it's a UI-thread action and the awaits resume on the UI thread.
266+ private async void ApplyUpdate ( )
267+ {
268+ if ( Updater . IsApplying ) return ;
269+ _updateItem . Enabled = false ;
270+ _updateItem . Text = "Downloading update…" ;
271+ var installer = await Updater . DownloadPendingAsync ( ) ;
272+ if ( installer == null ) // download failed / already in flight — restore the action (the tick refreshes it)
273+ {
274+ _updateItem . Enabled = true ;
275+ _updateItem . Text = $ "Restart to update to { Updater . PendingVersion } ";
276+ return ;
277+ }
278+ _updateItem . Text = "Installing update…" ;
279+ // Stop the timer FIRST so it can't respawn a worker we're about to kill, then drop everything under {app}:
280+ // the bridge-worker child tree (supervisor) and the Electron GUI. Now the installer replaces free files.
281+ _timer . Stop ( ) ;
282+ _supervisor . Dispose ( ) ;
283+ CloseDesktopGui ( ) ;
284+ Updater . LaunchInstallerAndExit ( installer ) ; // Process.Start(Setup) + Environment.Exit(0)
285+ }
286+
287+ /// <summary>Close the desktop GUI (the Electron shell, <c>Volt.exe</c>) if it's running, so the in-place
288+ /// upgrade can replace it — graceful close first, force-kill if it won't go. NOT the connector itself
289+ /// (VoltConnector) or the workers; the installer relaunches the connector when done.</summary>
290+ private static void CloseDesktopGui ( )
291+ {
292+ foreach ( var p in System . Diagnostics . Process . GetProcessesByName ( "Volt" ) )
293+ {
294+ try { if ( ! p . CloseMainWindow ( ) || ! p . WaitForExit ( 3000 ) ) p . Kill ( ) ; }
295+ catch { /* already gone / access denied — best effort */ }
296+ }
239297 }
240298
241299 private static string Truncate ( string s , int max ) => s . Length <= max ? s : s . Substring ( 0 , max - 1 ) + "…" ;
0 commit comments