diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-04-23 01:59:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-22 23:59:21 +0000 |
commit | d02644f7c41150709795e57bfd40351b4da35a7b (patch) | |
tree | 2403fb76bd5fae1703f8b55172ffce9e0a5d2bce /src/features/workspaces/api.ts | |
parent | Complete tray icons redesign for all platforms (#28) (diff) | |
download | ferdium-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/features/workspaces/api.ts')
-rw-r--r-- | src/features/workspaces/api.ts | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/features/workspaces/api.ts b/src/features/workspaces/api.ts index 582433527..fb752c565 100644 --- a/src/features/workspaces/api.ts +++ b/src/features/workspaces/api.ts | |||
@@ -4,15 +4,14 @@ import Request from '../../stores/lib/Request'; | |||
4 | import Workspace from './models/Workspace'; | 4 | import Workspace from './models/Workspace'; |
5 | import apiBase from '../../api/apiBase'; | 5 | import apiBase from '../../api/apiBase'; |
6 | 6 | ||
7 | // TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed | 7 | const debug = require('../../preload-safe-debug')('Ferdium:feature:workspaces:api'); |
8 | // const debug = require('debug')('Ferdium:feature:workspaces:api'); | ||
9 | 8 | ||
10 | export const workspaceApi = { | 9 | export const workspaceApi = { |
11 | getUserWorkspaces: async () => { | 10 | getUserWorkspaces: async () => { |
12 | const url = `${apiBase()}/workspace`; | 11 | const url = `${apiBase()}/workspace`; |
13 | console.log('getUserWorkspaces GET', url); | 12 | debug('getUserWorkspaces GET', url); |
14 | const result = await sendAuthRequest(url, { method: 'GET' }); | 13 | const result = await sendAuthRequest(url, { method: 'GET' }); |
15 | console.log('getUserWorkspaces RESULT', result); | 14 | debug('getUserWorkspaces RESULT', result); |
16 | if (!result.ok) { | 15 | if (!result.ok) { |
17 | throw new Error("Couldn't getUserWorkspaces"); | 16 | throw new Error("Couldn't getUserWorkspaces"); |
18 | } | 17 | } |
@@ -26,9 +25,9 @@ export const workspaceApi = { | |||
26 | method: 'POST', | 25 | method: 'POST', |
27 | body: JSON.stringify({ name }), | 26 | body: JSON.stringify({ name }), |
28 | }; | 27 | }; |
29 | console.log('createWorkspace POST', url, options); | 28 | debug('createWorkspace POST', url, options); |
30 | const result = await sendAuthRequest(url, options); | 29 | const result = await sendAuthRequest(url, options); |
31 | console.log('createWorkspace RESULT', result); | 30 | debug('createWorkspace RESULT', result); |
32 | if (!result.ok) { | 31 | if (!result.ok) { |
33 | throw new Error("Couldn't createWorkspace"); | 32 | throw new Error("Couldn't createWorkspace"); |
34 | } | 33 | } |
@@ -37,9 +36,9 @@ export const workspaceApi = { | |||
37 | 36 | ||
38 | deleteWorkspace: async workspace => { | 37 | deleteWorkspace: async workspace => { |
39 | const url = `${apiBase()}/workspace/${workspace.id}`; | 38 | const url = `${apiBase()}/workspace/${workspace.id}`; |
40 | console.log('deleteWorkspace DELETE', url); | 39 | debug('deleteWorkspace DELETE', url); |
41 | const result = await sendAuthRequest(url, { method: 'DELETE' }); | 40 | const result = await sendAuthRequest(url, { method: 'DELETE' }); |
42 | console.log('deleteWorkspace RESULT', result); | 41 | debug('deleteWorkspace RESULT', result); |
43 | if (!result.ok) { | 42 | if (!result.ok) { |
44 | throw new Error("Couldn't deleteWorkspace"); | 43 | throw new Error("Couldn't deleteWorkspace"); |
45 | } | 44 | } |
@@ -52,9 +51,9 @@ export const workspaceApi = { | |||
52 | method: 'PUT', | 51 | method: 'PUT', |
53 | body: JSON.stringify(pick(workspace, ['name', 'services'])), | 52 | body: JSON.stringify(pick(workspace, ['name', 'services'])), |
54 | }; | 53 | }; |
55 | console.log('updateWorkspace UPDATE', url, options); | 54 | debug('updateWorkspace UPDATE', url, options); |
56 | const result = await sendAuthRequest(url, options); | 55 | const result = await sendAuthRequest(url, options); |
57 | console.log('updateWorkspace RESULT', result); | 56 | debug('updateWorkspace RESULT', result); |
58 | if (!result.ok) { | 57 | if (!result.ok) { |
59 | throw new Error("Couldn't updateWorkspace"); | 58 | throw new Error("Couldn't updateWorkspace"); |
60 | } | 59 | } |