diff options
Diffstat (limited to 'src/webview')
-rw-r--r-- | src/webview/darkmode.js | 10 | ||||
-rw-r--r-- | src/webview/lib/RecipeWebview.js | 8 | ||||
-rw-r--r-- | src/webview/recipe.js | 20 |
3 files changed, 18 insertions, 20 deletions
diff --git a/src/webview/darkmode.js b/src/webview/darkmode.js index ab629435c..7435d6404 100644 --- a/src/webview/darkmode.js +++ b/src/webview/darkmode.js | |||
@@ -1,7 +1,7 @@ | |||
1 | /* eslint no-bitwise: ["error", { "int32Hint": true }] */ | 1 | /* eslint no-bitwise: ["error", { "int32Hint": true }] */ |
2 | 2 | ||
3 | import path from 'path'; | 3 | import { join } from 'path'; |
4 | import fs from 'fs-extra'; | 4 | import { pathExistsSync, readFileSync } from 'fs-extra'; |
5 | 5 | ||
6 | const debug = require('debug')('Ferdi:DarkMode'); | 6 | const debug = require('debug')('Ferdi:DarkMode'); |
7 | 7 | ||
@@ -10,9 +10,9 @@ const chars = [...'abcdefghijklmnopqrstuvwxyz']; | |||
10 | const ID = [...Array(20)].map(() => chars[Math.random() * chars.length | 0]).join``; | 10 | const ID = [...Array(20)].map(() => chars[Math.random() * chars.length | 0]).join``; |
11 | 11 | ||
12 | export function injectDarkModeStyle(recipePath) { | 12 | export function injectDarkModeStyle(recipePath) { |
13 | const darkModeStyle = path.join(recipePath, 'darkmode.css'); | 13 | const darkModeStyle = join(recipePath, 'darkmode.css'); |
14 | if (fs.pathExistsSync(darkModeStyle)) { | 14 | if (pathExistsSync(darkModeStyle)) { |
15 | const data = fs.readFileSync(darkModeStyle); | 15 | const data = readFileSync(darkModeStyle); |
16 | const styles = document.createElement('style'); | 16 | const styles = document.createElement('style'); |
17 | styles.id = ID; | 17 | styles.id = ID; |
18 | styles.innerHTML = data.toString(); | 18 | styles.innerHTML = data.toString(); |
diff --git a/src/webview/lib/RecipeWebview.js b/src/webview/lib/RecipeWebview.js index 305e79882..96caa125e 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, readFile } from 'fs-extra'; | 2 | import { exists, pathExistsSync, readFileSync } from 'fs-extra'; |
3 | 3 | ||
4 | const debug = require('debug')('Ferdi:Plugin:RecipeWebview'); | 4 | const debug = require('debug')('Ferdi:Plugin:RecipeWebview'); |
5 | 5 | ||
@@ -55,9 +55,8 @@ class RecipeWebview { | |||
55 | injectCSS(...files) { | 55 | injectCSS(...files) { |
56 | files.forEach(async (file) => { | 56 | files.forEach(async (file) => { |
57 | if (pathExistsSync(file)) { | 57 | if (pathExistsSync(file)) { |
58 | const data = await readFile(file, 'utf8'); | ||
59 | const styles = document.createElement('style'); | 58 | const styles = document.createElement('style'); |
60 | styles.innerHTML = data; | 59 | styles.innerHTML = readFileSync(file, 'utf8'); |
61 | 60 | ||
62 | document.querySelector('head').appendChild(styles); | 61 | document.querySelector('head').appendChild(styles); |
63 | 62 | ||
@@ -69,8 +68,7 @@ class RecipeWebview { | |||
69 | injectJSUnsafe(...files) { | 68 | injectJSUnsafe(...files) { |
70 | Promise.all(files.map(async (file) => { | 69 | Promise.all(files.map(async (file) => { |
71 | if (await exists(file)) { | 70 | if (await exists(file)) { |
72 | const data = await readFile(file, 'utf8'); | 71 | return readFileSync(file, 'utf8'); |
73 | return data; | ||
74 | } | 72 | } |
75 | debug('Script not found', file); | 73 | debug('Script not found', file); |
76 | return null; | 74 | return null; |
diff --git a/src/webview/recipe.js b/src/webview/recipe.js index 598c3eb9a..a45c34002 100644 --- a/src/webview/recipe.js +++ b/src/webview/recipe.js | |||
@@ -1,8 +1,8 @@ | |||
1 | /* eslint-disable import/first */ | 1 | /* eslint-disable import/first */ |
2 | import { contextBridge, ipcRenderer } from 'electron'; | 2 | import { contextBridge, ipcRenderer } from 'electron'; |
3 | import path from 'path'; | 3 | import { join } from 'path'; |
4 | import { autorun, computed, observable } from 'mobx'; | 4 | import { autorun, computed, observable } from 'mobx'; |
5 | import fs from 'fs-extra'; | 5 | import { pathExistsSync, readFileSync } from 'fs-extra'; |
6 | import { debounce } from 'lodash'; | 6 | import { debounce } from 'lodash'; |
7 | 7 | ||
8 | // For some services darkreader tries to use the chrome extension message API | 8 | // For some services darkreader tries to use the chrome extension message API |
@@ -189,7 +189,7 @@ class RecipeController { | |||
189 | 189 | ||
190 | loadRecipeModule(event, config, recipe) { | 190 | loadRecipeModule(event, config, recipe) { |
191 | debug('loadRecipeModule'); | 191 | debug('loadRecipeModule'); |
192 | const modulePath = path.join(recipe.path, 'webview.js'); | 192 | const modulePath = join(recipe.path, 'webview.js'); |
193 | debug('module path', modulePath); | 193 | debug('module path', modulePath); |
194 | // Delete module from cache | 194 | // Delete module from cache |
195 | delete require.cache[require.resolve(modulePath)]; | 195 | delete require.cache[require.resolve(modulePath)]; |
@@ -214,15 +214,15 @@ class RecipeController { | |||
214 | const styles = document.createElement('style'); | 214 | const styles = document.createElement('style'); |
215 | styles.innerHTML = screenShareCss; | 215 | styles.innerHTML = screenShareCss; |
216 | 216 | ||
217 | const userCss = path.join(recipe.path, 'user.css'); | 217 | const userCss = join(recipe.path, 'user.css'); |
218 | if (fs.existsSync(userCss)) { | 218 | if (pathExistsSync(userCss)) { |
219 | const data = await fs.readFile(userCss); | 219 | const data = readFileSync(userCss); |
220 | styles.innerHTML += data.toString(); | 220 | styles.innerHTML += data.toString(); |
221 | } | 221 | } |
222 | document.querySelector('head').appendChild(styles); | 222 | document.querySelector('head').appendChild(styles); |
223 | 223 | ||
224 | const userJs = path.join(recipe.path, 'user.js'); | 224 | const userJs = join(recipe.path, 'user.js'); |
225 | if (fs.existsSync(userJs)) { | 225 | if (pathExistsSync(userJs)) { |
226 | const loadUserJs = () => { | 226 | const loadUserJs = () => { |
227 | // eslint-disable-next-line | 227 | // eslint-disable-next-line |
228 | const userJsModule = require(userJs); | 228 | const userJsModule = require(userJs); |
@@ -308,11 +308,11 @@ class RecipeController { | |||
308 | debug('Enable dark mode'); | 308 | debug('Enable dark mode'); |
309 | 309 | ||
310 | // Check if recipe has a darkmode.css | 310 | // Check if recipe has a darkmode.css |
311 | const darkModeStyle = path.join( | 311 | const darkModeStyle = join( |
312 | this.settings.service.recipe.path, | 312 | this.settings.service.recipe.path, |
313 | 'darkmode.css', | 313 | 'darkmode.css', |
314 | ); | 314 | ); |
315 | const darkModeExists = fs.pathExistsSync(darkModeStyle); | 315 | const darkModeExists = pathExistsSync(darkModeStyle); |
316 | 316 | ||
317 | debug('darkmode.css exists? ', darkModeExists ? 'Yes' : 'No'); | 317 | debug('darkmode.css exists? ', darkModeExists ? 'Yes' : 'No'); |
318 | 318 | ||