diff --git a/electron/js/menu.js b/electron/js/menu.js index adde799d3f..dbcb1d2ce7 100644 --- a/electron/js/menu.js +++ b/electron/js/menu.js @@ -23,6 +23,7 @@ class MenuManager { const UpdateManager = require('./update.js'); config.debug = config.debug || {}; + config.flagsMw = config.flagsMw || {}; const menuParam = [ { @@ -167,14 +168,21 @@ class MenuManager { const flags = { ui: Util.translate('electronMenuFlagInterface'), - ho: Util.translate('electronMenuFlagHidden'), - mw: Util.translate('electronMenuFlagMiddleware'), - th: Util.translate('electronMenuFlagThreads'), - fi: Util.translate('electronMenuFlagFiles'), - an: Util.translate('electronMenuFlagAnalytics'), - js: Util.translate('electronMenuFlagJson'), + hiddenObject: Util.translate('electronMenuFlagHidden'), + analytics: Util.translate('electronMenuFlagAnalytics'), }; + + const flagsMw = { + request: Util.translate('electronMenuFlagMwRequest'), + event: Util.translate('electronMenuFlagMwEvent'), + thread: Util.translate('electronMenuFlagMwThread'), + file: Util.translate('electronMenuFlagMwFile'), + time: Util.translate('electronMenuFlagMwTime'), + json: Util.translate('electronMenuFlagMwJson'), + }; + const flagMenu = []; + const flagMwMenu = []; for (const i in flags) { flagMenu.push({ @@ -190,6 +198,22 @@ class MenuManager { }); }; + for (const i in flagsMw) { + flagMwMenu.push({ + label: flagsMw[i], type: 'checkbox', checked: config.flagsMw[i], + click: () => { + config.flagsMw[i] = !config.flagsMw[i]; + Api.setConfig(this.win, config); + } + }); + }; + + flagMenu.push(Separator); + flagMenu.push({ + label: Util.translate('electronMenuFlagMw'), + submenu: flagMwMenu, + }); + menuParam.push({ label: Util.translate('electronMenuDebug'), submenu: [ diff --git a/src/json/text.json b/src/json/text.json index 5f247c525f..0791f4c450 100644 --- a/src/json/text.json +++ b/src/json/text.json @@ -207,16 +207,19 @@ "electronMenuPrivacy": "Privacy Policy", "electronMenuFlagInterface": "Interface", "electronMenuFlagHidden": "Hidden objects", - "electronMenuFlagMiddleware": "Middleware", - "electronMenuFlagThreads": "Threads", - "electronMenuFlagFiles": "Files", - "electronMenuFlagAnalytics": "Analytics", - "electronMenuFlagJson": "JSON", "electronMenuFlags": "Flags", "electronMenuDevTools": "Dev Tools", "electronMenuVersion": "Version", "electronMenuOpen": "Open Anytype", "electronMenuLanguage": "Interface Language", + "electronMenuFlagAnalytics": "Analytics", + "electronMenuFlagMw": "Middleware", + "electronMenuFlagMwRequest": "Request/Response", + "electronMenuFlagMwEvent": "Common events", + "electronMenuFlagMwThread": "Sync events", + "electronMenuFlagMwFile": "File events", + "electronMenuFlagMwJson": "JSON logs", + "electronMenuFlagMwTime": "Time", "month1": "January", "month2": "February", diff --git a/src/ts/component/menu/block/add.tsx b/src/ts/component/menu/block/add.tsx index 0c380769ad..caf7c3f356 100644 --- a/src/ts/component/menu/block/add.tsx +++ b/src/ts/component/menu/block/add.tsx @@ -278,7 +278,7 @@ const MenuBlockAdd = observer(class MenuBlockAdd extends React.Component map(it => dbStore.getRelationById(it)). filter(it => it && it.relationKey && !relationKeys.includes(it.relationKey)); - const ret = relations.concat(typeRelations).filter(it => !config.debug.ho && it.isHidden ? false : it.isInstalled).sort(UtilData.sortByName); + const ret = relations.concat(typeRelations).filter(it => !config.debug.hiddenObject && it.isHidden ? false : it.isInstalled).sort(UtilData.sortByName); ret.unshift({ id: 'add', name: translate('menuBlockAddNewRelation'), isRelationAdd: true }); diff --git a/src/ts/component/menu/block/relation/view.tsx b/src/ts/component/menu/block/relation/view.tsx index e57f773da5..7c5c95a127 100644 --- a/src/ts/component/menu/block/relation/view.tsx +++ b/src/ts/component/menu/block/relation/view.tsx @@ -171,7 +171,7 @@ const MenuBlockRelationView = observer(class MenuBlockRelationView extends React return false; }; - return !config.debug.ho ? !it.isHidden : true; + return !config.debug.hiddenObject ? !it.isHidden : true; }); const sections = [ diff --git a/src/ts/component/menu/dataview/object/values.tsx b/src/ts/component/menu/dataview/object/values.tsx index 63516ed8b5..5e01e52d34 100644 --- a/src/ts/component/menu/dataview/object/values.tsx +++ b/src/ts/component/menu/dataview/object/values.tsx @@ -203,7 +203,7 @@ const MenuObjectValues = observer(class MenuObjectValues extends React.Component value = value.filter(it => it && !it._empty_ && !it.isArchived && !it.isDeleted); - if (!config.debug.ho) { + if (!config.debug.hiddenObject) { value = value.filter(it => !it.isHidden); }; diff --git a/src/ts/component/page/main/navigation.tsx b/src/ts/component/page/main/navigation.tsx index 1d498f7806..23fd77e7bd 100644 --- a/src/ts/component/page/main/navigation.tsx +++ b/src/ts/component/page/main/navigation.tsx @@ -442,7 +442,7 @@ const PageMainNavigation = observer(class PageMainNavigation extends React.Compo }; let ret = !it.isDeleted; - if (!config.debug.ho) { + if (!config.debug.hiddenObject) { ret = ret && !it.isHidden; }; return ret; diff --git a/src/ts/component/page/main/type.tsx b/src/ts/component/page/main/type.tsx index 15aaf380fb..4b7a9dd876 100644 --- a/src/ts/component/page/main/type.tsx +++ b/src/ts/component/page/main/type.tsx @@ -84,7 +84,7 @@ const PageMainType = observer(class PageMainType extends React.Component { + if (!debugEvent) { + return; + }; + console.log(`%cEvent.${type}`, 'font-weight: bold; color: #ad139b;', rootId); if (!type) { console.error('Event not found for valueCase', valueCase); @@ -182,7 +188,7 @@ class Dispatcher { if (data && data.toObject) { const d = UtilCommon.objectClear(data.toObject()); - console.log(config.debug.js ? JSON.stringify(d, null, 3) : d); + console.log(debugJson ? JSON.stringify(d, null, 3) : d); }; }; @@ -1190,7 +1196,9 @@ class Dispatcher { type = type.replace(/^command_/, ''); const { config } = commonStore; - const debug = config.debug.mw; + const debugTime = config.flagsMw.time; + const debugRequest = config.flagsMw.request; + const debugJson = config.flagsMw.json; const ct = UtilCommon.toCamelCase(type); const t0 = performance.now(); @@ -1203,10 +1211,10 @@ class Dispatcher { let t2 = 0; let d = null; - if (debug && !SKIP_IDS.includes(type)) { + if (debugRequest && !SKIP_IDS.includes(type)) { console.log(`%cRequest.${type}`, 'font-weight: bold; color: blue;'); d = UtilCommon.objectClear(data.toObject()); - console.log(config.debug.js ? JSON.stringify(d, null, 3) : d); + console.log(debugJson ? JSON.stringify(d, null, 3) : d); }; try { @@ -1245,10 +1253,10 @@ class Dispatcher { message.error.description = UtilCommon.translateError(type, message.error); }; - if (debug && !SKIP_IDS.includes(type)) { - console.log(`%cCallback.${type}`, 'font-weight: bold; color: green;'); + if (debugRequest && !SKIP_IDS.includes(type)) { + console.log(`%cResponse.${type}`, 'font-weight: bold; color: green;'); d = UtilCommon.objectClear(response.toObject()); - console.log(config.debug.js ? JSON.stringify(d, null, 3) : d); + console.log(debugJson ? JSON.stringify(d, null, 3) : d); }; if (message.event) { @@ -1267,7 +1275,7 @@ class Dispatcher { const renderTime = Math.ceil(t2 - t1); const totalTime = middleTime + renderTime; - if (debug && !SKIP_IDS.includes(type)) { + if (debugTime && !SKIP_IDS.includes(type)) { const times = [ 'Middle:', middleTime + 'ms', 'Render:', renderTime + 'ms', @@ -1284,8 +1292,8 @@ class Dispatcher { checkLog (type: string) { const { config } = commonStore; const debugCommon = config.debug.mw; - const debugThread = config.debug.th; - const debugFile = config.debug.fi; + const debugThread = config.flagsMw.thread; + const debugFile = config.flagsMw.file; let check = false; if (debugCommon && ![ 'threadStatus', 'fileLocalUsage', 'fileSpaceUsage' ].includes(type)) { diff --git a/src/ts/lib/dataview.ts b/src/ts/lib/dataview.ts index 0368e2e9bc..b32348efa7 100644 --- a/src/ts/lib/dataview.ts +++ b/src/ts/lib/dataview.ts @@ -17,7 +17,7 @@ class Dataview { let relations = UtilCommon.objectCopy(dbStore.getObjectRelations(rootId, blockId)).filter(it => it); let o = 0; - if (!config.debug.ho) { + if (!config.debug.hiddenObject) { relations = relations.filter(it => (it.relationKey == 'name') || !it.isHidden); }; diff --git a/src/ts/lib/util/data.ts b/src/ts/lib/util/data.ts index f21f387183..25795ae489 100644 --- a/src/ts/lib/util/data.ts +++ b/src/ts/lib/util/data.ts @@ -501,7 +501,7 @@ class UtilData { items = items.filter(it => it); - if (!config.debug.ho) { + if (!config.debug.hiddenObject) { items = items.filter(it => !it.isHidden); }; @@ -762,7 +762,7 @@ class UtilData { filters.push({ operator: I.FilterOperator.And, relationKey: 'spaceId', condition: I.FilterCondition.In, value: [ space ] }); }; - if (ignoreHidden && !config.debug.ho) { + if (ignoreHidden && !config.debug.hiddenObject) { filters.push({ operator: I.FilterOperator.And, relationKey: 'isHidden', condition: I.FilterCondition.NotEqual, value: true }); filters.push({ operator: I.FilterOperator.And, relationKey: 'isHiddenDiscovery', condition: I.FilterCondition.NotEqual, value: true }); }; @@ -849,7 +849,7 @@ class UtilData { filters.push({ operator: I.FilterOperator.And, relationKey: 'spaceId', condition: I.FilterCondition.In, value: [ space ] }); }; - if (ignoreHidden && !config.debug.ho) { + if (ignoreHidden && !config.debug.hiddenObject) { filters.push({ operator: I.FilterOperator.And, relationKey: 'isHidden', condition: I.FilterCondition.NotEqual, value: true }); filters.push({ operator: I.FilterOperator.And, relationKey: 'isHiddenDiscovery', condition: I.FilterCondition.NotEqual, value: true }); }; diff --git a/src/ts/store/common.ts b/src/ts/store/common.ts index 8466dae237..e827c9e19d 100644 --- a/src/ts/store/common.ts +++ b/src/ts/store/common.ts @@ -129,7 +129,11 @@ class CommonStore { get config(): any { const config = window.AnytypeGlobalConfig || this.configObj || {}; - return { ...config, debug: config.debug || {} }; + + config.debug = config.debug || {}; + config.flagsMw = config.flagsMw || {}; + + return config; }; get progress(): I.Progress {