Skip to content

Commit

Permalink
fix webxdc title not updated in document title changes (#3422)
Browse files Browse the repository at this point in the history
* fix webxdc title not updated in document title changes

fixes #3412

* update changelog
  • Loading branch information
Simon-Laux committed Sep 29, 2023
1 parent 9cd635b commit 7bbe47a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<a id="1_40_4"></a>

Expand Down
30 changes: 25 additions & 5 deletions src/main/deltachat/webxdc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]: {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand All @@ -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}`
}
Expand Down
7 changes: 7 additions & 0 deletions src/renderer/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ interface Runtime {
deleteWebxdcAccountData(accountId: number): Promise<void>
closeAllWebxdcInstances(): void
notifyWebxdcStatusUpdate(accountId: number, instanceId: number): void
notifyWebxdcMessageChanged(accountId: number, instanceId: number): void
notifyWebxdcInstanceDeleted(accountId: number, instanceId: number): void

// control app
Expand Down Expand Up @@ -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.')
}
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/system-integration/webxdc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down

0 comments on commit 7bbe47a

Please sign in to comment.