diff options
author | 2021-08-08 00:01:37 +0000 | |
---|---|---|
committer | 2021-08-08 05:31:37 +0530 | |
commit | 97d51a7763b14c92ee71ff9a012311dd9498d803 (patch) | |
tree | bd36005031ecb1148f27aa541e7a92a5e3aa4c0c /src/webview/recipe.js | |
parent | 5.6.1-nightly.17 [skip ci] (diff) | |
download | ferdium-app-97d51a7763b14c92ee71ff9a012311dd9498d803.tar.gz ferdium-app-97d51a7763b14c92ee71ff9a012311dd9498d803.tar.zst ferdium-app-97d51a7763b14c92ee71ff9a012311dd9498d803.zip |
refactor: path-references refactoring and using 'import' instead of 'require' (#1752)
* refactor references to 'userData' and 'appData' directories to move hardcoding into single location
* convert to es6 for lower memory usage as per https://codesource.io/the-difference-between-import-and-require-in-javascript/
Diffstat (limited to 'src/webview/recipe.js')
-rw-r--r-- | src/webview/recipe.js | 20 |
1 files changed, 10 insertions, 10 deletions
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 | ||