diff options
Diffstat (limited to 'src/webview/recipe.js')
-rw-r--r-- | src/webview/recipe.js | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/src/webview/recipe.js b/src/webview/recipe.js index a3ae4513f..d7032da3f 100644 --- a/src/webview/recipe.js +++ b/src/webview/recipe.js | |||
@@ -1,3 +1,4 @@ | |||
1 | /* eslint-disable global-require */ | ||
1 | /* eslint-disable import/first */ | 2 | /* eslint-disable import/first */ |
2 | import { contextBridge, desktopCapturer, ipcRenderer } from 'electron'; | 3 | import { contextBridge, desktopCapturer, ipcRenderer } from 'electron'; |
3 | import { BrowserWindow, getCurrentWebContents } from '@electron/remote'; | 4 | import { BrowserWindow, getCurrentWebContents } from '@electron/remote'; |
@@ -104,16 +105,13 @@ window.open = (url, frameName, features) => { | |||
104 | // then overwrite the corresponding field of the window object by injected JS. | 105 | // then overwrite the corresponding field of the window object by injected JS. |
105 | contextBridge.exposeInMainWorld('ferdi', { | 106 | contextBridge.exposeInMainWorld('ferdi', { |
106 | open: window.open, | 107 | open: window.open, |
107 | setBadge: (direct, indirect) => | 108 | setBadge: (direct, indirect) => badgeHandler.setBadge(direct, indirect), |
108 | badgeHandler.setBadge(direct, indirect), | 109 | safeParseInt: text => badgeHandler.safeParseInt(text), |
109 | safeParseInt: (text) => | ||
110 | badgeHandler.safeParseInt(text), | ||
111 | displayNotification: (title, options) => | 110 | displayNotification: (title, options) => |
112 | notificationsHandler.displayNotification(title, options), | 111 | notificationsHandler.displayNotification(title, options), |
113 | clearStorageData: (storageLocations) => | 112 | clearStorageData: storageLocations => |
114 | sessionHandler.clearStorageData(storageLocations), | 113 | sessionHandler.clearStorageData(storageLocations), |
115 | releaseServiceWorkers: () => | 114 | releaseServiceWorkers: () => sessionHandler.releaseServiceWorkers(), |
116 | sessionHandler.releaseServiceWorkers(), | ||
117 | getDisplayMediaSelector, | 115 | getDisplayMediaSelector, |
118 | getCurrentWebContents, | 116 | getCurrentWebContents, |
119 | BrowserWindow, | 117 | BrowserWindow, |
@@ -173,12 +171,12 @@ class RecipeController { | |||
173 | findInPage = null; | 171 | findInPage = null; |
174 | 172 | ||
175 | async initialize() { | 173 | async initialize() { |
176 | Object.keys(this.ipcEvents).forEach(channel => { | 174 | for (const channel of Object.keys(this.ipcEvents)) { |
177 | ipcRenderer.on(channel, (...args) => { | 175 | ipcRenderer.on(channel, (...args) => { |
178 | debug('Received IPC event for channel', channel, 'with', ...args); | 176 | debug('Received IPC event for channel', channel, 'with', ...args); |
179 | this[this.ipcEvents[channel]](...args); | 177 | this[this.ipcEvents[channel]](...args); |
180 | }); | 178 | }); |
181 | }); | 179 | } |
182 | 180 | ||
183 | debug('Send "hello" to host'); | 181 | debug('Send "hello" to host'); |
184 | setTimeout(() => ipcRenderer.sendToHost('hello'), 100); | 182 | setTimeout(() => ipcRenderer.sendToHost('hello'), 100); |
@@ -210,7 +208,7 @@ class RecipeController { | |||
210 | delete require.cache[require.resolve(modulePath)]; | 208 | delete require.cache[require.resolve(modulePath)]; |
211 | try { | 209 | try { |
212 | this.recipe = new RecipeWebview(badgeHandler, notificationsHandler); | 210 | this.recipe = new RecipeWebview(badgeHandler, notificationsHandler); |
213 | // eslint-disable-next-line | 211 | // eslint-disable-next-line import/no-dynamic-require |
214 | require(modulePath)(this.recipe, { ...config, recipe }); | 212 | require(modulePath)(this.recipe, { ...config, recipe }); |
215 | debug('Initialize Recipe', config, recipe); | 213 | debug('Initialize Recipe', config, recipe); |
216 | 214 | ||
@@ -218,8 +216,8 @@ class RecipeController { | |||
218 | 216 | ||
219 | // Make sure to update the WebView, otherwise the custom darkmode handler may not be used | 217 | // Make sure to update the WebView, otherwise the custom darkmode handler may not be used |
220 | this.update(); | 218 | this.update(); |
221 | } catch (err) { | 219 | } catch (error) { |
222 | console.error('Recipe initialization failed', err); | 220 | console.error('Recipe initialization failed', error); |
223 | } | 221 | } |
224 | 222 | ||
225 | this.loadUserFiles(recipe, config); | 223 | this.loadUserFiles(recipe, config); |
@@ -234,12 +232,12 @@ class RecipeController { | |||
234 | const data = readFileSync(userCss); | 232 | const data = readFileSync(userCss); |
235 | styles.innerHTML += data.toString(); | 233 | styles.innerHTML += data.toString(); |
236 | } | 234 | } |
237 | document.querySelector('head').appendChild(styles); | 235 | document.querySelector('head').append(styles); |
238 | 236 | ||
239 | const userJs = join(recipe.path, 'user.js'); | 237 | const userJs = join(recipe.path, 'user.js'); |
240 | if (pathExistsSync(userJs)) { | 238 | if (pathExistsSync(userJs)) { |
241 | const loadUserJs = () => { | 239 | const loadUserJs = () => { |
242 | // eslint-disable-next-line | 240 | // eslint-disable-next-line import/no-dynamic-require |
243 | const userJsModule = require(userJs); | 241 | const userJsModule = require(userJs); |
244 | 242 | ||
245 | if (typeof userJsModule === 'function') { | 243 | if (typeof userJsModule === 'function') { |
@@ -392,15 +390,14 @@ class RecipeController { | |||
392 | } | 390 | } |
393 | 391 | ||
394 | // Remove dark reader if (universal) dark mode was just disabled | 392 | // Remove dark reader if (universal) dark mode was just disabled |
395 | if (this.universalDarkModeInjected) { | 393 | if ( |
396 | if ( | 394 | this.universalDarkModeInjected && |
397 | !this.settings.app.darkMode || | 395 | (!this.settings.app.darkMode || |
398 | !this.settings.service.isDarkModeEnabled || | 396 | !this.settings.service.isDarkModeEnabled || |
399 | !this.settings.app.universalDarkMode | 397 | !this.settings.app.universalDarkMode) |
400 | ) { | 398 | ) { |
401 | disableDarkMode(); | 399 | disableDarkMode(); |
402 | this.universalDarkModeInjected = false; | 400 | this.universalDarkModeInjected = false; |
403 | } | ||
404 | } | 401 | } |
405 | } | 402 | } |
406 | 403 | ||