diff --git a/js/browserUI.js b/js/browserUI.js index eab152329..05bba6a27 100644 --- a/js/browserUI.js +++ b/js/browserUI.js @@ -142,16 +142,32 @@ function closeTab (tabId) { } } -/* changes the currently-selected task and updates the UI */ +function setWindowTitle () { + const task = tasks.getSelected() + const tab = task.tabs.get(task.tabs.getSelected()) -function setWindowTitle (taskData) { - if (taskData.name) { - document.title = (taskData.name.length > 100 ? taskData.name.substring(0, 100) + '...' : taskData.name) - } else { - document.title = 'Min' + const truncateString = (str, len) => { + if (str.length > len) { + return str.substring(0, len) + '...' + } else { + return str + } + } + + const title = [ + truncateString(tab.title || '', 100), + truncateString(task.name || '', 100), + 'Min' + ].filter(str => !!str).join(' | ') + + if (document.title !== title) { + document.title = title + ipc.send('set-window-title', title) } } +/* changes the currently-selected task and updates the UI */ + function switchToTask (id) { tasks.setSelected(id) @@ -180,7 +196,17 @@ function switchToTask (id) { tasks.on('task-updated', function (id, key) { if (key === 'name' && id === tasks.getSelected().id) { - setWindowTitle(tasks.get(id)) + setWindowTitle() + } +}) + +tasks.on('tab-selected', function () { + setWindowTitle() +}) + +tasks.on('tab-updated', function (id, key) { + if (key === 'title') { + setWindowTitle() } }) diff --git a/main/main.js b/main/main.js index 4881ad024..3d1ff2ab3 100644 --- a/main/main.js +++ b/main/main.js @@ -249,6 +249,10 @@ function createWindowWithBounds (bounds, customArgs) { mainView.setBounds({x: 0, y: 0, width: winBounds.width, height: winBounds.height}) }) + mainView.webContents.ipc.on('set-window-title', function(e, title) { + newWin.title = title + }) + newWin.on('resize', function () { // The result of getContentBounds doesn't update until the next tick setTimeout(function () {