diff options
author | Iaroslav <yavoloh@mail.ru> | 2021-10-23 19:16:01 +0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-23 19:46:01 +0530 |
commit | 4d02744dfab8a49075b82a5ddbdc02e08c7e8a66 (patch) | |
tree | dc7b08818a8f116d41886924552c92719c4d081a /src/webview/dialogTitle.ts | |
parent | chore: upgrade npm modules (diff) | |
download | ferdium-app-4d02744dfab8a49075b82a5ddbdc02e08c7e8a66.tar.gz ferdium-app-4d02744dfab8a49075b82a5ddbdc02e08c7e8a66.tar.zst ferdium-app-4d02744dfab8a49075b82a5ddbdc02e08c7e8a66.zip |
Add active dialog title feature (#2114)
https://github.com/getferdi/ferdi/issues/1280
WhatsApp-like services can set active dialog title to the app title eg. Ferdi - WhatsApp - Contact Name
Diffstat (limited to 'src/webview/dialogTitle.ts')
-rw-r--r-- | src/webview/dialogTitle.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/webview/dialogTitle.ts b/src/webview/dialogTitle.ts new file mode 100644 index 000000000..f9a1aac6f --- /dev/null +++ b/src/webview/dialogTitle.ts | |||
@@ -0,0 +1,33 @@ | |||
1 | import { ipcRenderer } from 'electron'; | ||
2 | |||
3 | const debug = require('debug')('Ferdi:Plugin:DialogTitleHandler'); | ||
4 | |||
5 | export class DialogTitleHandler { | ||
6 | titleCache: { title: string }; | ||
7 | |||
8 | constructor() { | ||
9 | this.titleCache = { | ||
10 | title: '', | ||
11 | }; | ||
12 | } | ||
13 | |||
14 | safeGetTitle(title: string | undefined | null) { | ||
15 | if (!title) { | ||
16 | return ''; | ||
17 | } | ||
18 | |||
19 | return title; | ||
20 | } | ||
21 | |||
22 | setDialogTitle(title: string | undefined | null) { | ||
23 | const newTitle = this.safeGetTitle(title); | ||
24 | if (this.titleCache.title === newTitle) { | ||
25 | return; | ||
26 | } | ||
27 | |||
28 | debug('Sending active dialog title to host %s', newTitle); | ||
29 | ipcRenderer.sendToHost('active-dialog-title', newTitle); | ||
30 | |||
31 | this.titleCache.title = newTitle; | ||
32 | } | ||
33 | } | ||