aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview/lib/RecipeWebview.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/webview/lib/RecipeWebview.js')
-rw-r--r--src/webview/lib/RecipeWebview.js25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/webview/lib/RecipeWebview.js b/src/webview/lib/RecipeWebview.js
index 74d05fc2d..4fac21c55 100644
--- a/src/webview/lib/RecipeWebview.js
+++ b/src/webview/lib/RecipeWebview.js
@@ -19,6 +19,8 @@ class RecipeWebview {
19 19
20 loopFunc = () => null; 20 loopFunc = () => null;
21 21
22 darkModeHandler = false;
23
22 /** 24 /**
23 * Initialize the loop 25 * Initialize the loop
24 * 26 *
@@ -67,17 +69,28 @@ class RecipeWebview {
67 * be an absolute path to the file 69 * be an absolute path to the file
68 */ 70 */
69 injectCSS(...files) { 71 injectCSS(...files) {
70 files.forEach((file) => { 72 files.forEach(async (file) => {
71 const data = fs.readFileSync(file); 73 if (await fs.exists(file)) {
72 const styles = document.createElement('style'); 74 const data = await fs.readFile(file);
73 styles.innerHTML = data.toString(); 75 const styles = document.createElement('style');
76 styles.innerHTML = data.toString();
74 77
75 document.querySelector('head').appendChild(styles); 78 document.querySelector('head').appendChild(styles);
76 79
77 debug('Append styles', styles); 80 debug('Append styles', styles);
81 }
78 }); 82 });
79 } 83 }
80 84
85 /**
86 * Set a custom handler for turning on and off dark mode
87 *
88 * @param {function} handler
89 */
90 handleDarkMode(handler) {
91 this.darkModeHandler = handler;
92 }
93
81 onNotify(fn) { 94 onNotify(fn) {
82 if (typeof fn === 'function') { 95 if (typeof fn === 'function') {
83 window.Notification.prototype.onNotify = fn; 96 window.Notification.prototype.onNotify = fn;