From f03a495b24d0812f0fbac70c3e282f585ecfddf3 Mon Sep 17 00:00:00 2001 From: SimonLaux Date: Fri, 29 Sep 2023 03:00:05 +0200 Subject: [PATCH 1/2] fix webxdc title not updated in document title changes fixes #3412 --- src/main/deltachat/webxdc.ts | 30 +++++++++++++++++++---- src/renderer/runtime.ts | 7 ++++++ src/renderer/system-integration/webxdc.ts | 3 +++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/main/deltachat/webxdc.ts b/src/main/deltachat/webxdc.ts index 1f0ad034e4..fe47cea82b 100644 --- a/src/main/deltachat/webxdc.ts +++ b/src/main/deltachat/webxdc.ts @@ -25,6 +25,7 @@ import { DesktopSettings } from '../desktop_settings' import { window as main_window } from '../windows/main' import { writeTempFileFromBase64 } from '../ipc' import { refresh as refreshTitleMenu } from '../menu' +import { T } from '@deltachat/jsonrpc-client' const open_apps: { [instanceId: string]: { @@ -233,11 +234,7 @@ export default class DCWebxdc extends SplitOut { 'webxdc-preload.js' ), }, - title: `${ - webxdcInfo.document - ? truncateText(webxdcInfo.document, 32) + ' - ' - : '' - }${truncateText(webxdcInfo.name, 42)} – ${chatName}`, + title: makeTitle(webxdcInfo, chatName), icon: app_icon || undefined, width: 375, height: 667, @@ -604,6 +601,23 @@ If you think that's a bug and you need that permission, then please open an issu } } ) + + ipcMain.handle( + 'webxdc:message-changed', + async (_ev, accountId: number, instanceId: number) => { + const instance = open_apps[`${accountId}.${instanceId}`] + if (instance) { + const { chatId, webxdcInfo } = await this.rpc.getMessage( + accountId, + instanceId + ) + const { name } = await this.rpc.getBasicChatInfo(accountId, chatId) + if (instance.win && webxdcInfo) { + instance.win.title = makeTitle(webxdcInfo, name) + } + } + } + ) ipcMain.handle( 'webxdc:instance-deleted', (_ev, accountId: number, instanceId: number) => { @@ -627,6 +641,12 @@ If you think that's a bug and you need that permission, then please open an issu } } +function makeTitle(webxdcInfo: T.WebxdcMessageInfo, chatName: string): string { + return `${ + webxdcInfo.document ? truncateText(webxdcInfo.document, 32) + ' - ' : '' + }${truncateText(webxdcInfo.name, 42)} – ${chatName}` +} + function partitionFromAccountId(accountId: number) { return `persist:webxdc_${accountId}` } diff --git a/src/renderer/runtime.ts b/src/renderer/runtime.ts index f2b2f22923..a9cef8d1d3 100644 --- a/src/renderer/runtime.ts +++ b/src/renderer/runtime.ts @@ -89,6 +89,7 @@ interface Runtime { deleteWebxdcAccountData(accountId: number): Promise closeAllWebxdcInstances(): void notifyWebxdcStatusUpdate(accountId: number, instanceId: number): void + notifyWebxdcMessageChanged(accountId: number, instanceId: number): void notifyWebxdcInstanceDeleted(accountId: number, instanceId: number): void // control app @@ -179,6 +180,9 @@ class Browser implements Runtime { notifyWebxdcStatusUpdate(_accountId: number, _instanceId: number): void { throw new Error('Method not implemented.') } + notifyWebxdcMessageChanged(_accountId: number, _instanceId: number): void { + throw new Error('Method not implemented.') + } notifyWebxdcInstanceDeleted(_accountId: number, _instanceId: number): void { throw new Error('Method not implemented.') } @@ -366,6 +370,9 @@ class Electron implements Runtime { notifyWebxdcStatusUpdate(accountId: number, instanceId: number): void { ipcBackend.invoke('webxdc:status-update', accountId, instanceId) } + notifyWebxdcMessageChanged(accountId: number, instanceId: number): void { + ipcBackend.invoke('webxdc:message-changed', accountId, instanceId) + } notifyWebxdcInstanceDeleted(accountId: number, instanceId: number): void { ipcBackend.invoke('webxdc:instance-deleted', accountId, instanceId) } diff --git a/src/renderer/system-integration/webxdc.ts b/src/renderer/system-integration/webxdc.ts index 511d23f703..f45fa44f6e 100644 --- a/src/renderer/system-integration/webxdc.ts +++ b/src/renderer/system-integration/webxdc.ts @@ -9,6 +9,9 @@ export function initWebxdc() { BackendRemote.on('WebxdcStatusUpdate', (accountId, { msgId }) => { runtime.notifyWebxdcStatusUpdate(accountId, msgId) }) + BackendRemote.on('MsgsChanged', (accountId, { msgId }) => { + runtime.notifyWebxdcMessageChanged(accountId, msgId) + }) BackendRemote.on('WebxdcInstanceDeleted', (accountId, { msgId }) => { runtime.notifyWebxdcInstanceDeleted(accountId, msgId) }) From 08431a57ffbd3af40e51fbcf914755ded2540508 Mon Sep 17 00:00:00 2001 From: SimonLaux Date: Fri, 29 Sep 2023 03:01:23 +0200 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c92bc1808..38be0b873c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - fix `target=_blank` links in html emails don't work #3408 - add description for enableChatAuditLog setting - fix: import key from file instead of folder, fixes #1863 +- fix webxdc title not updated in document title changes #3412