aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/workspaces
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/features/workspaces
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/features/workspaces')
-rw-r--r--src/features/workspaces/api.ts19
-rw-r--r--src/features/workspaces/store.js9
2 files changed, 13 insertions, 15 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';
4import Workspace from './models/Workspace'; 4import Workspace from './models/Workspace';
5import apiBase from '../../api/apiBase'; 5import 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 7const debug = require('../../preload-safe-debug')('Ferdium:feature:workspaces:api');
8// const debug = require('debug')('Ferdium:feature:workspaces:api');
9 8
10export const workspaceApi = { 9export 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 }
diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js
index d2ccfeccf..20d32df67 100644
--- a/src/features/workspaces/store.js
+++ b/src/features/workspaces/store.js
@@ -15,8 +15,7 @@ import { createActionBindings } from '../utils/ActionBinding';
15 15
16import { KEEP_WS_LOADED_USID } from '../../config'; 16import { KEEP_WS_LOADED_USID } from '../../config';
17 17
18// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed 18const debug = require('../../preload-safe-debug')('Ferdium:feature:workspaces:store');
19// const debug = require('debug')('Ferdium:feature:workspaces:store');
20 19
21export default class WorkspacesStore extends FeatureStore { 20export default class WorkspacesStore extends FeatureStore {
22 @observable isFeatureActive = false; 21 @observable isFeatureActive = false;
@@ -70,7 +69,7 @@ export default class WorkspacesStore extends FeatureStore {
70 // ========== PUBLIC API ========= // 69 // ========== PUBLIC API ========= //
71 70
72 @action start(stores, actions) { 71 @action start(stores, actions) {
73 console.log('WorkspacesStore::start'); 72 debug('WorkspacesStore::start');
74 this.stores = stores; 73 this.stores = stores;
75 this.actions = actions; 74 this.actions = actions;
76 75
@@ -116,7 +115,7 @@ export default class WorkspacesStore extends FeatureStore {
116 115
117 @action stop() { 116 @action stop() {
118 super.stop(); 117 super.stop();
119 console.log('WorkspacesStore::stop'); 118 debug('WorkspacesStore::stop');
120 this.reset(); 119 this.reset();
121 this.isFeatureActive = false; 120 this.isFeatureActive = false;
122 } 121 }
@@ -274,7 +273,7 @@ export default class WorkspacesStore extends FeatureStore {
274 }; 273 };
275 274
276 _activateLastUsedWorkspaceReaction = () => { 275 _activateLastUsedWorkspaceReaction = () => {
277 console.log('_activateLastUsedWorkspaceReaction'); 276 debug('_activateLastUsedWorkspaceReaction');
278 if (!this.activeWorkspace && this.userHasWorkspaces) { 277 if (!this.activeWorkspace && this.userHasWorkspaces) {
279 const { lastActiveWorkspace } = this.settings; 278 const { lastActiveWorkspace } = this.settings;
280 if (lastActiveWorkspace) { 279 if (lastActiveWorkspace) {