From 76b91ff8ad482e8bd093f0d34342866fa236a0d0 Mon Sep 17 00:00:00 2001 From: tiddlygit-test Date: Fri, 10 Dec 2021 00:20:02 +0800 Subject: [PATCH] feat: add more logs --- src/services/workspaces/index.ts | 14 ++++++++++---- src/services/workspaces/interface.ts | 4 ++-- src/services/workspacesView/index.ts | 10 +++++++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/services/workspaces/index.ts b/src/services/workspaces/index.ts index 7533e199..4e14c4f6 100644 --- a/src/services/workspaces/index.ts +++ b/src/services/workspaces/index.ts @@ -24,6 +24,7 @@ import { lazyInject } from '@services/container'; import type { IWorkspaceService, IWorkspace, IWorkspaceMetaData, INewWorkspaceConfig } from './interface'; import i18n from '@services/libs/i18n'; import { defaultServerIP } from '@/constants/urls'; +import { logger } from '@services/libs/log'; const debouncedSetSettingFile = debounce(async (id: string, workspace: IWorkspace) => await settings.set(`workspaces.${id}`, { ...workspace }), 500); @@ -193,20 +194,25 @@ export class Workspace implements IWorkspaceService { return this.workspaces$.pipe(map((workspaces) => workspaces[id])); } - public async set(id: string, workspace: IWorkspace): Promise { + public async set(id: string, workspace: IWorkspace, immediate?: boolean): Promise { this.workspaces[id] = this.sanitizeWorkspace(workspace); await this.reactBeforeWorkspaceChanged(workspace); - await debouncedSetSettingFile(id, workspace); + if (immediate === true) { + await settings.set(`workspaces.${id}`, { ...workspace }); + } else { + await debouncedSetSettingFile(id, workspace); + } await this.updateWorkspaceSubject(); await this.updateWorkspaceMenuItems(); } - public async update(id: string, workspaceSetting: Partial): Promise { + public async update(id: string, workspaceSetting: Partial, immediate?: boolean): Promise { const workspace = await this.get(id); if (workspace === undefined) { + logger.error(`Could not update workspace ${id} because it does not exist`); return; } - await this.set(id, { ...workspace, ...workspaceSetting }); + await this.set(id, { ...workspace, ...workspaceSetting }, immediate); } public async setWorkspaces(newWorkspaces: Record): Promise { diff --git a/src/services/workspaces/interface.ts b/src/services/workspaces/interface.ts index f8f671ae..cbf716d8 100644 --- a/src/services/workspaces/interface.ts +++ b/src/services/workspaces/interface.ts @@ -133,11 +133,11 @@ export interface IWorkspaceService { getWorkspacesAsList(): Promise; remove(id: string): Promise; removeWorkspacePicture(id: string): Promise; - set(id: string, workspace: IWorkspace): Promise; + set(id: string, workspace: IWorkspace, immediate?: boolean): Promise; setActiveWorkspace(id: string): Promise; setWorkspacePicture(id: string, sourcePicturePath: string): Promise; setWorkspaces(newWorkspaces: Record): Promise; - update(id: string, workspaceSetting: Partial): Promise; + update(id: string, workspaceSetting: Partial, immediate?: boolean): Promise; updateMetaData: (id: string, options: Partial) => Promise; workspaces$: BehaviorSubject>; } diff --git a/src/services/workspacesView/index.ts b/src/services/workspacesView/index.ts index c890555d..ce0ed40c 100644 --- a/src/services/workspacesView/index.ts +++ b/src/services/workspacesView/index.ts @@ -146,9 +146,13 @@ export class WorkspaceView implements IWorkspaceViewService { const view = this.viewService.getView(workspaceID, WindowNames.main); if (view !== undefined) { const currentUrl = view.webContents.getURL(); - await this.workspaceService.update(workspaceID, { - lastUrl: currentUrl, - }); + await this.workspaceService.update( + workspaceID, + { + lastUrl: currentUrl, + }, + true, + ); } else { logger.warn(`Can't update lastUrl for workspace ${workspaceID}, view is not found`); }