From d723dc2511534b5016f43f356d93c34649f84065 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Sun, 12 Jan 2020 13:29:24 +0100 Subject: [PATCH] Update main window title with service navigation --- resources/js/index.js | 17 ++++++++++++++++- src/Meta.js | 19 ++++++++++++++++++- src/main.js | 12 +++++++++++- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/resources/js/index.js b/resources/js/index.js index 2cc24f9..eac4dca 100644 --- a/resources/js/index.js +++ b/resources/js/index.js @@ -8,6 +8,7 @@ const { dialog, } = remote; +const appInfo = {}; const icons = []; let services = []; @@ -68,7 +69,11 @@ function openServiceContextMenu(event, serviceId) { } -ipcRenderer.on('data', (event, brandIcons, solidIcons, actualServices, actualSelectedService) => { +ipcRenderer.on('data', (event, appData, brandIcons, solidIcons, actualServices, actualSelectedService) => { + // App info + appInfo.title = appData.title; + + // Icons for (const icon of brandIcons) { icons.push(icon); } @@ -332,6 +337,16 @@ function updateNavigation() { if (view && view.canGoBack()) backButton.classList.remove('disabled'); else backButton.classList.add('disabled'); } + + updateWindowTitle(); +} + +function updateWindowTitle() { + if (selectedService === null) { + ipcRenderer.send('updateWindowTitle', null); + } else { + ipcRenderer.send('updateWindowTitle', selectedService, services[selectedService].view.getWebContents().getTitle()); + } } function goForward() { diff --git a/src/Meta.js b/src/Meta.js index 4ee96b3..65dec44 100644 --- a/src/Meta.js +++ b/src/Meta.js @@ -1,12 +1,29 @@ export default class Meta { + static #title = 'Tabs'; static #devMode = null; + static get title() { + return this.#title; + } + static isDevMode() { - if(this.#devMode === null) { + if (this.#devMode === null) { this.#devMode = process.argv.length > 2 && process.argv[2] === '--dev'; console.debug('Dev mode:', this.#devMode); } return this.#devMode; } + + /** + * @param service {Service} + * @param viewTitle {string} + */ + static getTitleForService(service, viewTitle) { + let suffix = ''; + if (typeof viewTitle === 'string' && viewTitle.length > 0) { + suffix = ' - ' + viewTitle; + } + return this.title + ' - ' + service.name + suffix; + } } \ No newline at end of file diff --git a/src/main.js b/src/main.js index 9a6a5bd..6d86ed6 100644 --- a/src/main.js +++ b/src/main.js @@ -58,6 +58,7 @@ function createWindow() { }, autoHideMenuBar: true, icon: iconPath, + title: Meta.title, }); window.maximize(); window.on('closed', () => { @@ -157,12 +158,21 @@ function createWindow() { window.webContents.send('deleteService', id); }); + ipcMain.on('updateWindowTitle', (event, serviceId, viewTitle) => { + if (serviceId === null) { + window.setTitle(Meta.title); + } else { + const service = config.services[serviceId]; + window.setTitle(Meta.getTitleForService(service, viewTitle)); + } + }); + console.log('> App started'); } function sendData() { console.log('Syncing data'); - window.webContents.send('data', brandIcons, solidIcons, config.services, selectedService); + window.webContents.send('data', Meta.title, brandIcons, solidIcons, config.services, selectedService); } function setActiveService(index) {