@@ -142,16 +142,32 @@ function closeTab (tabId) {
142142 }
143143}
144144
145- /* changes the currently-selected task and updates the UI */
145+ function setWindowTitle ( ) {
146+ const task = tasks . getSelected ( )
147+ const tab = task . tabs . get ( task . tabs . getSelected ( ) )
146148
147- function setWindowTitle ( taskData ) {
148- if ( taskData . name ) {
149- document . title = ( taskData . name . length > 100 ? taskData . name . substring ( 0 , 100 ) + '...' : taskData . name )
150- } else {
151- document . title = 'Min'
149+ const truncateString = ( str , len ) => {
150+ if ( str . length > len ) {
151+ return str . substring ( 0 , len ) + '...'
152+ } else {
153+ return str
154+ }
155+ }
156+
157+ const title = [
158+ truncateString ( tab . title || '' , 100 ) ,
159+ truncateString ( task . name || '' , 100 ) ,
160+ 'Min'
161+ ] . filter ( str => ! ! str ) . join ( ' | ' )
162+
163+ if ( document . title !== title ) {
164+ document . title = title
165+ ipc . send ( 'set-window-title' , title )
152166 }
153167}
154168
169+ /* changes the currently-selected task and updates the UI */
170+
155171function switchToTask ( id ) {
156172 tasks . setSelected ( id )
157173
@@ -180,7 +196,17 @@ function switchToTask (id) {
180196
181197tasks . on ( 'task-updated' , function ( id , key ) {
182198 if ( key === 'name' && id === tasks . getSelected ( ) . id ) {
183- setWindowTitle ( tasks . get ( id ) )
199+ setWindowTitle ( )
200+ }
201+ } )
202+
203+ tasks . on ( 'tab-selected' , function ( ) {
204+ setWindowTitle ( )
205+ } )
206+
207+ tasks . on ( 'tab-updated' , function ( id , key ) {
208+ if ( key === 'title' ) {
209+ setWindowTitle ( )
184210 }
185211} )
186212
0 commit comments