diff options
Diffstat (limited to 'src/webview/lib/RecipeWebview.js')
-rw-r--r-- | src/webview/lib/RecipeWebview.js | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/webview/lib/RecipeWebview.js b/src/webview/lib/RecipeWebview.js index 157da7693..4085b925b 100644 --- a/src/webview/lib/RecipeWebview.js +++ b/src/webview/lib/RecipeWebview.js | |||
@@ -1,5 +1,5 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import { exists, pathExistsSync, readFileSync } from 'fs-extra'; | 2 | import { pathExistsSync, readFileSync, existsSync } from 'fs-extra'; |
3 | 3 | ||
4 | const debug = require('debug')('Ferdi:Plugin:RecipeWebview'); | 4 | const debug = require('debug')('Ferdi:Plugin:RecipeWebview'); |
5 | 5 | ||
@@ -62,12 +62,13 @@ class RecipeWebview { | |||
62 | * be an absolute path to the file | 62 | * be an absolute path to the file |
63 | */ | 63 | */ |
64 | injectCSS(...files) { | 64 | injectCSS(...files) { |
65 | files.forEach(async (file) => { | 65 | // eslint-disable-next-line unicorn/no-array-for-each |
66 | files.forEach(file => { | ||
66 | if (pathExistsSync(file)) { | 67 | if (pathExistsSync(file)) { |
67 | const styles = document.createElement('style'); | 68 | const styles = document.createElement('style'); |
68 | styles.innerHTML = readFileSync(file, 'utf8'); | 69 | styles.innerHTML = readFileSync(file, 'utf8'); |
69 | 70 | ||
70 | document.querySelector('head').appendChild(styles); | 71 | document.querySelector('head').append(styles); |
71 | 72 | ||
72 | debug('Append styles', styles); | 73 | debug('Append styles', styles); |
73 | } | 74 | } |
@@ -75,14 +76,16 @@ class RecipeWebview { | |||
75 | } | 76 | } |
76 | 77 | ||
77 | injectJSUnsafe(...files) { | 78 | injectJSUnsafe(...files) { |
78 | Promise.all(files.map(async (file) => { | 79 | Promise.all( |
79 | if (await exists(file)) { | 80 | files.map(file => { |
80 | return readFileSync(file, 'utf8'); | 81 | if (existsSync(file)) { |
81 | } | 82 | return readFileSync(file, 'utf8'); |
82 | debug('Script not found', file); | 83 | } |
83 | return null; | 84 | debug('Script not found', file); |
84 | })).then(async (scripts) => { | 85 | return null; |
85 | const scriptsFound = scripts.filter((script) => script !== null); | 86 | }), |
87 | ).then(scripts => { | ||
88 | const scriptsFound = scripts.filter(script => script !== null); | ||
86 | if (scriptsFound.length > 0) { | 89 | if (scriptsFound.length > 0) { |
87 | debug('Inject scripts to main world', scriptsFound); | 90 | debug('Inject scripts to main world', scriptsFound); |
88 | ipcRenderer.sendToHost('inject-js-unsafe', ...scriptsFound); | 91 | ipcRenderer.sendToHost('inject-js-unsafe', ...scriptsFound); |