diff --git a/app/main/index.ts b/app/main/index.ts index 784c8600..e2cb9360 100644 --- a/app/main/index.ts +++ b/app/main/index.ts @@ -355,7 +355,7 @@ ${error}` AppMenu.setMenu(props); const activeTab = props.tabs[props.activeTabIndex]; if (activeTab) { - mainWindow.setTitle(`Zulip - ${activeTab.webview.props.name}`); + mainWindow.setTitle(`Zulip - ${activeTab.webviewName}`); } }); diff --git a/app/main/menu.ts b/app/main/menu.ts index 9129f4a8..4e8c8b35 100644 --- a/app/main/menu.ts +++ b/app/main/menu.ts @@ -2,7 +2,7 @@ import {app, shell, BrowserWindow, Menu} from 'electron'; import AdmZip from 'adm-zip'; -import type {ServerOrFunctionalTab} from '../renderer/js/main'; +import type {TabData} from '../renderer/js/main'; import * as ConfigUtil from '../renderer/js/utils/config-util'; import * as DNDUtil from '../renderer/js/utils/dnd-util'; import * as LinkUtil from '../renderer/js/utils/link-util'; @@ -11,7 +11,7 @@ import * as t from '../renderer/js/utils/translation-util'; import {appUpdater} from './autoupdater'; export interface MenuProps { - tabs: ServerOrFunctionalTab[]; + tabs: TabData[]; activeTabIndex?: number; enableMenu?: boolean; } @@ -215,7 +215,7 @@ function getHelpSubmenu(): Electron.MenuItemConstructorOptions[] { ]; } -function getWindowSubmenu(tabs: ServerOrFunctionalTab[], activeTabIndex: number): Electron.MenuItemConstructorOptions[] { +function getWindowSubmenu(tabs: TabData[], activeTabIndex: number): Electron.MenuItemConstructorOptions[] { const initialSubmenu: Electron.MenuItemConstructorOptions[] = [{ label: t.__('Minimize'), role: 'minimize' @@ -231,17 +231,17 @@ function getWindowSubmenu(tabs: ServerOrFunctionalTab[], activeTabIndex: number) }); tabs.forEach(tab => { // Do not add functional tab settings to list of windows in menu bar - if (tab.props.role === 'function' && tab.props.name === 'Settings') { + if (tab.role === 'function' && tab.name === 'Settings') { return; } initialSubmenu.push({ - label: tab.props.name, - accelerator: tab.props.role === 'function' ? '' : `${ShortcutKey} + ${tab.props.index + 1}`, - checked: tab.props.index === activeTabIndex, + label: tab.name, + accelerator: tab.role === 'function' ? '' : `${ShortcutKey} + ${tab.index + 1}`, + checked: tab.index === activeTabIndex, click(_item, focusedWindow) { if (focusedWindow) { - sendAction('switch-server-tab', tab.props.index); + sendAction('switch-server-tab', tab.index); } }, type: 'checkbox' @@ -547,20 +547,20 @@ async function checkForUpdate(): Promise { await appUpdater(true); } -function getNextServer(tabs: ServerOrFunctionalTab[], activeTabIndex: number): number { +function getNextServer(tabs: TabData[], activeTabIndex: number): number { do { activeTabIndex = (activeTabIndex + 1) % tabs.length; } - while (tabs[activeTabIndex].props.role !== 'server'); + while (tabs[activeTabIndex].role !== 'server'); return activeTabIndex; } -function getPreviousServer(tabs: ServerOrFunctionalTab[], activeTabIndex: number): number { +function getPreviousServer(tabs: TabData[], activeTabIndex: number): number { do { activeTabIndex = (activeTabIndex - 1 + tabs.length) % tabs.length; } - while (tabs[activeTabIndex].props.role !== 'server'); + while (tabs[activeTabIndex].role !== 'server'); return activeTabIndex; } diff --git a/app/renderer/js/main.ts b/app/renderer/js/main.ts index ffbccf53..375cf32e 100644 --- a/app/renderer/js/main.ts +++ b/app/renderer/js/main.ts @@ -61,7 +61,14 @@ const logger = new Logger({ }); const rendererDirectory = path.resolve(__dirname, '..'); -export type ServerOrFunctionalTab = ServerTab | FunctionalTab; +type ServerOrFunctionalTab = ServerTab | FunctionalTab; + +export interface TabData { + role: string; + name: string; + index: number; + webviewName: string; +} class ServerManagerView { $addServerButton: HTMLButtonElement; @@ -592,19 +599,13 @@ class ServerManagerView { // not crash app when this.tabs is passed into // ipcRenderer. Something about webview, and props.webview // properties in ServerTab causes the app to crash. - get tabsForIpc(): ServerOrFunctionalTab[] { - const tabs: ServerOrFunctionalTab[] = []; - this.tabs.forEach((tab: ServerOrFunctionalTab) => { - const proto = Object.create(Object.getPrototypeOf(tab)); - const tabClone = Object.assign(proto, tab); - - tabClone.webview = {props: {}}; - tabClone.webview.props.name = tab.webview.props.name; - delete tabClone.props.webview; - tabs.push(tabClone); - }); - - return tabs; + get tabsForIpc(): TabData[] { + return this.tabs.map(tab => ({ + role: tab.props.role, + name: tab.props.name, + index: tab.props.index, + webviewName: tab.webview.props.name + })); } activateTab(index: number, hideOldTab = true): void {