mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2026-03-05 05:20:59 -08:00
fix: call between services
This commit is contained in:
parent
762e1bb596
commit
2dc125b5ff
7 changed files with 43 additions and 37 deletions
|
|
@ -8,6 +8,9 @@ import { ModifiedFileList } from './inspect';
|
|||
* It can be retrieved and changed using Electron APIs
|
||||
*/
|
||||
export interface IGitService {
|
||||
/**
|
||||
* Call commitAndSync every period of time. This cannot be used as promise, as said in https://github.com/lodash/lodash/issues/4700
|
||||
*/
|
||||
debounceCommitAndSync: (wikiFolderPath: string, githubRepoUrl: string, userInfo: IUserInfo) => Promise<void> | undefined;
|
||||
updateGitInfoTiddler(githubRepoName: string): Promise<void>;
|
||||
getModifiedFileList(wikiFolderPath: string): Promise<ModifiedFileList[]>;
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ container.bind<IWindowService>(serviceIdentifier.Window).to(Window).inSingletonS
|
|||
container.bind<IWorkspaceService>(serviceIdentifier.Workspace).to(Workspace).inSingletonScope();
|
||||
container.bind<IWorkspaceViewService>(serviceIdentifier.WorkspaceView).to(WorkspaceView).inSingletonScope();
|
||||
|
||||
// TODO: delay service init, call init() manually
|
||||
const authService = container.get<IAuthenticationService>(serviceIdentifier.Authentication);
|
||||
const contextService = container.get<IContextService>(serviceIdentifier.Context);
|
||||
const gitService = container.get<IGitService>(serviceIdentifier.Git);
|
||||
|
|
|
|||
|
|
@ -394,9 +394,10 @@ export class View implements IViewService {
|
|||
void session.fromPartition(`persist:${id}`).clearStorageData();
|
||||
// FIXME: Property 'destroy' does not exist on type 'BrowserView'.ts(2339) , might related to https://github.com/electron/electron/pull/25411 which previously cause crush when I quit the app
|
||||
// maybe use https://github.com/electron/electron/issues/10096
|
||||
// if (view !== undefined) {
|
||||
// view.destroy();
|
||||
// }
|
||||
if (view !== undefined) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||
(view as any).destroy();
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||
delete this.views[id];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -299,8 +299,7 @@ export class Wiki {
|
|||
} catch {
|
||||
throw new Error(i18n.t('AddWorkspace.CantCreateFolderHere', { newWikiPath }));
|
||||
}
|
||||
// TODO: call git service
|
||||
// await clone(githubWikiUrl, path.join(parentFolderLocation, wikiFolderName), userInfo);
|
||||
await this.gitService.clone(githubWikiUrl, path.join(parentFolderLocation, wikiFolderName), userInfo);
|
||||
}
|
||||
|
||||
public async cloneSubWiki(
|
||||
|
|
@ -324,8 +323,7 @@ export class Wiki {
|
|||
} catch {
|
||||
throw new Error(i18n.t('AddWorkspace.CantCreateFolderHere', { newWikiPath }));
|
||||
}
|
||||
// TODO: call git service
|
||||
// await clone(githubWikiUrl, path.join(parentFolderLocation, wikiFolderName), userInfo);
|
||||
await this.gitService.clone(githubWikiUrl, path.join(parentFolderLocation, wikiFolderName), userInfo);
|
||||
this.logProgress(i18n.t('AddWorkspace.StartLinkingSubWikiToMainWiki'));
|
||||
await this.linkWiki(mainWikiPath, wikiFolderName, path.join(parentFolderLocation, wikiFolderName));
|
||||
if (typeof tagName === 'string' && tagName.length > 0) {
|
||||
|
|
@ -370,7 +368,7 @@ export class Wiki {
|
|||
}
|
||||
// if we are creating a sub-wiki, restart the main wiki to load content from private wiki
|
||||
if (!this.justStartedWiki[mainWikiToLink]) {
|
||||
// TODO: change to get by mainWikiPath
|
||||
// TODO: change getByName to getByMainWikiPath, get by mainWikiPath
|
||||
const mainWorkspace = this.workspaceService.getByName(mainWikiToLink);
|
||||
if (mainWorkspace === undefined) {
|
||||
throw new Error(`mainWorkspace is undefined in wikiStartup() for mainWikiPath ${mainWikiToLink}`);
|
||||
|
|
@ -444,8 +442,8 @@ export class Wiki {
|
|||
}
|
||||
logger.info(`${fileName} changed`);
|
||||
lock = true;
|
||||
// TODO: handle this promise
|
||||
void this.gitService.debounceCommitAndSync(wikiRepoPath, githubRepoUrl, userInfo)!.then(() => {
|
||||
// TODO: handle this promise, it might be undefined, need some test
|
||||
void this.gitService.debounceCommitAndSync(wikiRepoPath, githubRepoUrl, userInfo)?.then(() => {
|
||||
lock = false;
|
||||
});
|
||||
}, 1000);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import path from 'path';
|
||||
import { dialog } from 'electron';
|
||||
import { injectable, inject } from 'inversify';
|
||||
import { injectable } from 'inversify';
|
||||
|
||||
import serviceIdentifier from '@services/serviceIdentifier';
|
||||
import type { IWikiService } from '@services/wiki/interface';
|
||||
|
|
@ -10,22 +10,23 @@ import type { IWorkspaceViewService } from '@services/workspacesView/interface';
|
|||
import type { IWindowService } from '@services/windows/interface';
|
||||
import { WindowNames } from '@services/windows/WindowProperties';
|
||||
import type { IAuthenticationService } from '@services/auth/interface';
|
||||
import { lazyInject } from '@services/container'
|
||||
|
||||
import { logger } from '@services/libs/log';
|
||||
import i18n from '@services/libs/i18n';
|
||||
import { IUserInfo } from '@services/types';
|
||||
import { IWikiGitWorkspaceService } from './interface';
|
||||
import { IMenuService } from '@services/menu/interface';
|
||||
|
||||
@injectable()
|
||||
export class WikiGitWorkspace implements IWikiGitWorkspaceService {
|
||||
constructor(
|
||||
@inject(serviceIdentifier.Wiki) private readonly wikiService: IWikiService,
|
||||
@inject(serviceIdentifier.Git) private readonly gitService: IGitService,
|
||||
@inject(serviceIdentifier.Workspace) private readonly workspaceService: IWorkspaceService,
|
||||
@inject(serviceIdentifier.Window) private readonly windowService: IWindowService,
|
||||
@inject(serviceIdentifier.WorkspaceView) private readonly workspaceViewService: IWorkspaceViewService,
|
||||
@inject(serviceIdentifier.Authentication) private readonly authService: IAuthenticationService,
|
||||
) {}
|
||||
@lazyInject(serviceIdentifier.Wiki) private readonly wikiService!: IWikiService;
|
||||
@lazyInject(serviceIdentifier.Git) private readonly gitService!: IGitService;
|
||||
@lazyInject(serviceIdentifier.Workspace) private readonly workspaceService!: IWorkspaceService;
|
||||
@lazyInject(serviceIdentifier.Window) private readonly windowService!: IWindowService;
|
||||
@lazyInject(serviceIdentifier.WorkspaceView) private readonly workspaceViewService!: IWorkspaceViewService;
|
||||
@lazyInject(serviceIdentifier.Authentication) private readonly authService!: IAuthenticationService;
|
||||
@lazyInject(serviceIdentifier.MenuService) private readonly menuService!: IMenuService;
|
||||
|
||||
public initWikiGitTransaction = async (wikiFolderPath: string, githubRepoUrl: string, userInfo: IUserInfo, isMainWiki: boolean): Promise<void> => {
|
||||
try {
|
||||
|
|
@ -56,8 +57,7 @@ export class WikiGitWorkspace implements IWikiGitWorkspaceService {
|
|||
await this.wikiService.stopWiki(workspace.name).catch((error: any) => logger.error((error as Error).message, error));
|
||||
await this.wikiService.removeWiki(workspace.name, workspace.isSubWiki ? workspace.mainWikiToLink : undefined, response === 0);
|
||||
await this.workspaceViewService.removeWorkspaceView(id);
|
||||
// TODO: createMenu();
|
||||
// createMenu();
|
||||
this.menuService.buildMenu();
|
||||
// restart the main wiki to load content from private wiki
|
||||
const mainWikiPath = workspace.mainWikiToLink;
|
||||
const mainWorkspace = this.workspaceService.getByName(mainWikiPath);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { BrowserWindow, ipcMain, dialog, app, App, remote, clipboard, BrowserWin
|
|||
import isDevelopment from 'electron-is-dev';
|
||||
import { injectable } from 'inversify';
|
||||
import getDecorators from 'inversify-inject-decorators';
|
||||
import { Menubar } from 'menubar';
|
||||
import windowStateKeeper, { State as windowStateKeeperState } from 'electron-window-state';
|
||||
|
||||
import { IBrowserViewMetaData, WindowNames, windowDimension, WindowMeta, CodeInjectionType } from '@services/windows/WindowProperties';
|
||||
|
|
@ -27,6 +28,7 @@ const { lazyInject } = getDecorators(container);
|
|||
export class Window implements IWindowService {
|
||||
private windows = {} as Partial<Record<WindowNames, BrowserWindow | undefined>>;
|
||||
private windowMeta = {} as Partial<WindowMeta>;
|
||||
private mainWindowMenuBar?: Menubar;
|
||||
|
||||
@lazyInject(serviceIdentifier.Preference) private readonly preferenceService!: IPreferenceService;
|
||||
@lazyInject(serviceIdentifier.Workspace) private readonly workspaceService!: IWorkspaceService;
|
||||
|
|
@ -114,17 +116,21 @@ export class Window implements IWindowService {
|
|||
// update window meta
|
||||
this.setWindowMeta(windowName, meta);
|
||||
const existedWindowMeta = this.getWindowMeta(windowName);
|
||||
const attachToMenubar: boolean = this.preferenceService.get('attachToMenubar');
|
||||
|
||||
if (existedWindow !== undefined) {
|
||||
// TODO: handle this menubar logic
|
||||
// if (attachToMenubar) {
|
||||
// if (menuBar == undefined) {
|
||||
// createAsync();
|
||||
// } else {
|
||||
// menuBar.on('ready', () => {
|
||||
// menuBar.showWindow();
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
if (attachToMenubar) {
|
||||
if (this.mainWindowMenuBar !== undefined) {
|
||||
this.mainWindowMenuBar.on('ready', () => {
|
||||
if (this.mainWindowMenuBar !== undefined) {
|
||||
void this.mainWindowMenuBar.showWindow();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// create window with menubar
|
||||
}
|
||||
}
|
||||
if (recreate === true || (typeof recreate === 'function' && existedWindowMeta !== undefined && recreate(existedWindowMeta))) {
|
||||
existedWindow.close();
|
||||
} else {
|
||||
|
|
@ -132,13 +138,12 @@ export class Window implements IWindowService {
|
|||
}
|
||||
}
|
||||
|
||||
const attachToMenubar: boolean = this.preferenceService.get('attachToMenubar');
|
||||
let mainWindowConfig: Partial<BrowserWindowConstructorOptions> = {};
|
||||
let mainWindowState: windowStateKeeperState | undefined;
|
||||
const isMainWindow = windowName === WindowNames.main;
|
||||
if (isMainWindow) {
|
||||
if (attachToMenubar) {
|
||||
await handleAttachToMenuBar();
|
||||
this.mainWindowMenuBar = await handleAttachToMenuBar();
|
||||
}
|
||||
|
||||
mainWindowState = windowStateKeeper({
|
||||
|
|
|
|||
|
|
@ -333,10 +333,10 @@ export class Workspace implements IWorkspaceService {
|
|||
} else {
|
||||
throw new Error(`Try to remote workspace, but id ${id} is not existed`);
|
||||
}
|
||||
// TODO: call wiki service
|
||||
// const { name } = workspaces[id];
|
||||
// stopWiki(name);
|
||||
// stopWatchWiki(name);
|
||||
// call wiki service
|
||||
const { name } = this.workspaces[id];
|
||||
await this.wikiService.stopWiki(name);
|
||||
await this.wikiService.stopWatchWiki(name);
|
||||
this.updateWorkspaceMenuItems();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue