Update main window title with service navigation

This commit is contained in:
Alice Gaudon 2020-01-12 13:29:24 +01:00
parent f1c66b1db1
commit d723dc2511
3 changed files with 45 additions and 3 deletions

View File

@ -8,6 +8,7 @@ const {
dialog, dialog,
} = remote; } = remote;
const appInfo = {};
const icons = []; const icons = [];
let services = []; 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) { for (const icon of brandIcons) {
icons.push(icon); icons.push(icon);
} }
@ -332,6 +337,16 @@ function updateNavigation() {
if (view && view.canGoBack()) backButton.classList.remove('disabled'); if (view && view.canGoBack()) backButton.classList.remove('disabled');
else backButton.classList.add('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() { function goForward() {

View File

@ -1,12 +1,29 @@
export default class Meta { export default class Meta {
static #title = 'Tabs';
static #devMode = null; static #devMode = null;
static get title() {
return this.#title;
}
static isDevMode() { static isDevMode() {
if(this.#devMode === null) { if (this.#devMode === null) {
this.#devMode = process.argv.length > 2 && process.argv[2] === '--dev'; this.#devMode = process.argv.length > 2 && process.argv[2] === '--dev';
console.debug('Dev mode:', this.#devMode); console.debug('Dev mode:', this.#devMode);
} }
return 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;
}
} }

View File

@ -58,6 +58,7 @@ function createWindow() {
}, },
autoHideMenuBar: true, autoHideMenuBar: true,
icon: iconPath, icon: iconPath,
title: Meta.title,
}); });
window.maximize(); window.maximize();
window.on('closed', () => { window.on('closed', () => {
@ -157,12 +158,21 @@ function createWindow() {
window.webContents.send('deleteService', id); 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'); console.log('> App started');
} }
function sendData() { function sendData() {
console.log('Syncing data'); 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) { function setActiveService(index) {