Skip to content

Commit d8ae7b2

Browse files
authored
Update window title with tab and task name (#2660)
Previously, we were only using the task name, and it looks like the old approach wasn't working at all regardless
1 parent 42a5a9e commit d8ae7b2

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

js/browserUI.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
155171
function switchToTask (id) {
156172
tasks.setSelected(id)
157173

@@ -180,7 +196,17 @@ function switchToTask (id) {
180196

181197
tasks.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

main/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ function createWindowWithBounds (bounds, customArgs) {
249249
mainView.setBounds({x: 0, y: 0, width: winBounds.width, height: winBounds.height})
250250
})
251251

252+
mainView.webContents.ipc.on('set-window-title', function(e, title) {
253+
newWin.title = title
254+
})
255+
252256
newWin.on('resize', function () {
253257
// The result of getContentBounds doesn't update until the next tick
254258
setTimeout(function () {

0 commit comments

Comments
 (0)