aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview/darkmode.js
blob: 9830ef33c73f820259b85c9391ca31de56675d4c (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
import path from 'path';
import fs from 'fs-extra';

const ID = 'franz-theme-dark-mode';

export function injectDarkModeStyle(recipePath) {
  const darkModeStyle = path.join(recipePath, 'darkmode.css');
  if (fs.pathExistsSync(darkModeStyle)) {
    const data = fs.readFileSync(darkModeStyle);
    const styles = document.createElement('style');
    styles.id = ID;
    styles.innerHTML = data.toString();

    document.querySelector('head').appendChild(styles);
  }
}

export function removeDarkModeStyle() {
  const style = document.querySelector(`#${ID}`);

  if (style) {
    style.remove();
  }
}

export function isDarkModeStyleInjected() {
  return !!document.querySelector(`#${ID}`);
}