feat: add more logs

This commit is contained in:
tiddlygit-test 2021-12-10 00:20:02 +08:00
parent cbb2266163
commit 76b91ff8ad
3 changed files with 19 additions and 9 deletions

View file

@ -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<void> {
public async set(id: string, workspace: IWorkspace, immediate?: boolean): Promise<void> {
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<IWorkspace>): Promise<void> {
public async update(id: string, workspaceSetting: Partial<IWorkspace>, immediate?: boolean): Promise<void> {
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<string, IWorkspace>): Promise<void> {

View file

@ -133,11 +133,11 @@ export interface IWorkspaceService {
getWorkspacesAsList(): Promise<IWorkspace[]>;
remove(id: string): Promise<void>;
removeWorkspacePicture(id: string): Promise<void>;
set(id: string, workspace: IWorkspace): Promise<void>;
set(id: string, workspace: IWorkspace, immediate?: boolean): Promise<void>;
setActiveWorkspace(id: string): Promise<void>;
setWorkspacePicture(id: string, sourcePicturePath: string): Promise<void>;
setWorkspaces(newWorkspaces: Record<string, IWorkspace>): Promise<void>;
update(id: string, workspaceSetting: Partial<IWorkspace>): Promise<void>;
update(id: string, workspaceSetting: Partial<IWorkspace>, immediate?: boolean): Promise<void>;
updateMetaData: (id: string, options: Partial<IWorkspaceMetaData>) => Promise<void>;
workspaces$: BehaviorSubject<Record<string, IWorkspace>>;
}

View file

@ -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`);
}