@@ -39,6 +39,7 @@ import { createRoot } from "react-dom/client";
3939const platform = getApi ( ) . getPlatform ( ) ;
4040document . title = `Wave Terminal` ;
4141let savedInitOpts : WaveInitOpts = null ;
42+ let tabTitleUnsub : ( ( ) => void ) | null = null ;
4243
4344( window as any ) . WOS = WOS ;
4445( window as any ) . globalStore = globalStore ;
@@ -56,6 +57,27 @@ function updateZoomFactor(zoomFactor: number) {
5657 document . documentElement . style . setProperty ( "--zoomfactor-inv" , String ( 1 / zoomFactor ) ) ;
5758}
5859
60+ function formatWaveWindowTitle ( tabName ?: string | null ) {
61+ const trimmedTabName = tabName ?. trim ( ) ;
62+ return trimmedTabName ? `Wave Terminal - ${ trimmedTabName } ` : "Wave Terminal" ;
63+ }
64+
65+ function installWaveWindowTitleSync ( tabId : string ) {
66+ tabTitleUnsub ?.( ) ;
67+ tabTitleUnsub = null ;
68+ if ( ! tabId ) {
69+ document . title = formatWaveWindowTitle ( ) ;
70+ return ;
71+ }
72+ const tabAtom = WOS . getWaveObjectAtom < Tab > ( WOS . makeORef ( "tab" , tabId ) ) ;
73+ const updateTitle = ( ) => {
74+ const tab = globalStore . get ( tabAtom ) ;
75+ document . title = formatWaveWindowTitle ( tab ?. name ) ;
76+ } ;
77+ updateTitle ( ) ;
78+ tabTitleUnsub = globalStore . sub ( tabAtom , updateTitle ) ;
79+ }
80+
5981async function initBare ( ) {
6082 getApi ( ) . sendLog ( "Init Bare" ) ;
6183 document . body . style . visibility = "hidden" ;
@@ -113,7 +135,7 @@ async function reinitWave() {
113135 const initialTab = await WOS . reloadWaveObject < Tab > ( WOS . makeORef ( "tab" , savedInitOpts . tabId ) ) ;
114136 await WOS . reloadWaveObject < LayoutState > ( WOS . makeORef ( "layout" , initialTab . layoutstate ) ) ;
115137 reloadAllWorkspaceTabs ( ws ) ;
116- document . title = `Wave Terminal - ${ initialTab . name } ` ; // TODO update with tab name change
138+ installWaveWindowTitleSync ( initialTab . oid ) ;
117139 getApi ( ) . setWindowInitStatus ( "wave-ready" ) ;
118140 globalStore . set ( atoms . reinitVersion , globalStore . get ( atoms . reinitVersion ) + 1 ) ;
119141 globalStore . set ( atoms . updaterStatusAtom , getApi ( ) . getUpdaterStatus ( ) ) ;
@@ -182,7 +204,7 @@ async function initWave(initOpts: WaveInitOpts) {
182204 ] ) ;
183205 loadAllWorkspaceTabs ( ws ) ;
184206 WOS . wpsSubscribeToObject ( WOS . makeORef ( "workspace" , waveWindow . workspaceid ) ) ;
185- document . title = `Wave Terminal - ${ initialTab . name } ` ; // TODO update with tab name change
207+ installWaveWindowTitleSync ( initialTab . oid ) ;
186208 } catch ( e ) {
187209 console . error ( "Failed initialization error" , e ) ;
188210 getApi ( ) . sendLog ( "Error in initialization (wave.ts, loading required objects) " + e . message + "\n" + e . stack ) ;
0 commit comments