aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview/dialogTitle.ts
blob: 14676100c8e9f50582544b88e305eac32b931714 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { ipcRenderer } from 'electron';

const debug = require('../preload-safe-debug')(
  'Ferdium:Plugin:DialogTitleHandler',
);

export default class DialogTitleHandler {
  titleCache: { title: string };

  constructor() {
    this.titleCache = {
      title: '',
    };
  }

  safeGetTitle(title: string | undefined | null) {
    if (!title) {
      return '';
    }

    return title;
  }

  setDialogTitle(title: string | undefined | null) {
    const newTitle = this.safeGetTitle(title);
    if (this.titleCache.title === newTitle) {
      return;
    }

    debug('Sending active dialog title to host %s', newTitle);
    ipcRenderer.sendToHost('active-dialog-title', newTitle);

    this.titleCache.title = newTitle;
  }
}