aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview/lib
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-04-23 01:59:21 +0200
committerLibravatar GitHub <noreply@github.com>2022-04-22 23:59:21 +0000
commitd02644f7c41150709795e57bfd40351b4da35a7b (patch)
tree2403fb76bd5fae1703f8b55172ffce9e0a5d2bce /src/webview/lib
parentComplete tray icons redesign for all platforms (#28) (diff)
downloadferdium-app-d02644f7c41150709795e57bfd40351b4da35a7b.tar.gz
ferdium-app-d02644f7c41150709795e57bfd40351b4da35a7b.tar.zst
ferdium-app-d02644f7c41150709795e57bfd40351b4da35a7b.zip
Preload safe debug shim (#29)
In https://github.com/ferdium/ferdium-app/pull/23 we removed usages of the debug package due to an electron bug. This patch aims to restore some debug functionality by introducing a shim. The shim detect whether if it is being introduced in a preload script where the electron but would be triggered, and falls back to a simple replacement for debug. However, in the main and renderer processes, where a preload script is not being used, we still get full debug functionality. In this way, a module can be used both in a preload script and outside of it, while still preserving debug functionality whenever possible. Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'src/webview/lib')
-rw-r--r--src/webview/lib/RecipeWebview.ts11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/webview/lib/RecipeWebview.ts b/src/webview/lib/RecipeWebview.ts
index cf70164ef..e7a39579b 100644
--- a/src/webview/lib/RecipeWebview.ts
+++ b/src/webview/lib/RecipeWebview.ts
@@ -2,8 +2,7 @@ import { ipcRenderer } from 'electron';
2import { BrowserWindow } from '@electron/remote'; 2import { BrowserWindow } from '@electron/remote';
3import { pathExistsSync, readFileSync, existsSync } from 'fs-extra'; 3import { pathExistsSync, readFileSync, existsSync } from 'fs-extra';
4 4
5// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed 5const debug = require('../../preload-safe-debug')('Ferdium:Plugin:RecipeWebview');
6// const debug = require('debug')('Ferdium:Plugin:RecipeWebview');
7 6
8class RecipeWebview { 7class RecipeWebview {
9 badgeHandler: any; 8 badgeHandler: any;
@@ -28,7 +27,7 @@ class RecipeWebview {
28 ipcRenderer.on('poll', () => { 27 ipcRenderer.on('poll', () => {
29 this.loopFunc(); 28 this.loopFunc();
30 29
31 console.log('Poll event'); 30 debug('Poll event');
32 31
33 // This event is for checking if the service recipe is still actively 32 // This event is for checking if the service recipe is still actively
34 // communicating with the client 33 // communicating with the client
@@ -110,7 +109,7 @@ class RecipeWebview {
110 109
111 if (head) { 110 if (head) {
112 head.append(styles); 111 head.append(styles);
113 console.log('Append styles', styles); 112 debug('Append styles', styles);
114 } 113 }
115 } 114 }
116 }); 115 });
@@ -122,13 +121,13 @@ class RecipeWebview {
122 if (existsSync(file)) { 121 if (existsSync(file)) {
123 return readFileSync(file, 'utf8'); 122 return readFileSync(file, 'utf8');
124 } 123 }
125 console.log('Script not found', file); 124 debug('Script not found', file);
126 return null; 125 return null;
127 }), 126 }),
128 ).then(scripts => { 127 ).then(scripts => {
129 const scriptsFound = scripts.filter(script => script !== null); 128 const scriptsFound = scripts.filter(script => script !== null);
130 if (scriptsFound.length > 0) { 129 if (scriptsFound.length > 0) {
131 console.log('Inject scripts to main world', scriptsFound); 130 debug('Inject scripts to main world', scriptsFound);
132 ipcRenderer.sendToHost('inject-js-unsafe', ...scriptsFound); 131 ipcRenderer.sendToHost('inject-js-unsafe', ...scriptsFound);
133 } 132 }
134 }); 133 });