feat: allow restart wiki to reload wiki that had error

This commit is contained in:
tiddlygit-test 2021-12-26 03:04:09 +08:00
parent 5c4b1e50d3
commit cffb559fdf
3 changed files with 21 additions and 12 deletions

View file

@ -23,7 +23,10 @@ interface IWorkspaceMenuRequiredServices {
wikiGitWorkspace: Pick<IWikiGitWorkspaceService, 'removeWorkspace'>;
window: Pick<IWindowService, 'open'>;
workspace: Pick<IWorkspaceService, 'getActiveWorkspace'>;
workspaceView: Pick<IWorkspaceViewService, 'wakeUpWorkspaceView' | 'hibernateWorkspaceView' | 'setActiveWorkspaceView' | 'restartWorkspaceViewService'>;
workspaceView: Pick<
IWorkspaceViewService,
'wakeUpWorkspaceView' | 'hibernateWorkspaceView' | 'setActiveWorkspaceView' | 'restartWorkspaceViewService' | 'realignActiveWorkspace'
>;
}
export async function openWorkspaceTagTiddler(workspace: IWorkspace, service: IWorkspaceMenuRequiredServices): Promise<void> {
@ -90,7 +93,10 @@ export async function getWorkspaceMenuTemplate(
},
{
label: t('ContextMenu.RestartService'),
click: async () => await service.workspaceView.restartWorkspaceViewService(id),
click: async () => {
await service.workspaceView.restartWorkspaceViewService(id);
await service.workspaceView.realignActiveWorkspace(id);
},
},
];

View file

@ -1,3 +1,4 @@
/* eslint-disable unicorn/no-null */
/* eslint-disable @typescript-eslint/require-await */
/* eslint-disable unicorn/consistent-destructuring */
import { app, session, dialog } from 'electron';
@ -330,7 +331,9 @@ export class WorkspaceView implements IWorkspaceViewService {
if (workspaceToRestart !== undefined) {
logger.info(`Restarting workspace ${workspaceToRestart.id}`);
await this.updateLastUrl(workspaceToRestart.id);
await this.wikiService.restartWiki(workspaceToRestart);
await this.workspaceService.updateMetaData(workspaceToRestart.id, { didFailLoadErrorMessage: null, isLoading: false });
await this.wikiService.stopWiki(workspaceToRestart.wikiFolderLocation);
await this.initializeWorkspaceView(workspaceToRestart, { syncImmediately: false });
await this.viewService.reloadViewsWebContents(workspaceToRestart.id);
await this.wikiService.wikiOperation(WikiChannel.generalNotification, [i18n.t('ContextMenu.RestartServiceComplete')]);
} else {
@ -384,11 +387,11 @@ export class WorkspaceView implements IWorkspaceViewService {
/**
* Seems this is for relocating BrowserView in the electron window
*/
public async realignActiveWorkspace(): Promise<void> {
public async realignActiveWorkspace(id?: string): Promise<void> {
// this function only call browserView.setBounds
// do not attempt to recall browserView.webContents.focus()
// as it breaks page focus (cursor, scroll bar not visible)
await this.realignActiveWorkspaceView();
await this.realignActiveWorkspaceView(id);
try {
await this.menuService.buildMenu();
} catch (error) {
@ -397,17 +400,17 @@ export class WorkspaceView implements IWorkspaceViewService {
}
}
private async realignActiveWorkspaceView(): Promise<void> {
const activeWorkspace = await this.workspaceService.getActiveWorkspace();
logger.debug(`realignActiveWorkspaceView() activeWorkspace.id: ${activeWorkspace?.id ?? 'undefined'}`);
private async realignActiveWorkspaceView(id?: string): Promise<void> {
const workspaceToRealign = id !== undefined ? await this.workspaceService.get(id) : await this.workspaceService.getActiveWorkspace();
logger.debug(`realignActiveWorkspaceView() activeWorkspace.id: ${workspaceToRealign?.id ?? 'undefined'}`);
const mainWindow = this.windowService.get(WindowNames.main);
const menuBarWindow = this.windowService.get(WindowNames.menuBar);
if (activeWorkspace !== undefined) {
if (workspaceToRealign !== undefined) {
if (mainWindow === undefined && menuBarWindow === undefined) {
logger.warn('realignActiveWorkspaceView: no active window');
}
mainWindow !== undefined && void this.viewService.realignActiveView(mainWindow, activeWorkspace.id);
menuBarWindow !== undefined && void this.viewService.realignActiveView(menuBarWindow, activeWorkspace.id);
mainWindow !== undefined && void this.viewService.realignActiveView(mainWindow, workspaceToRealign.id);
menuBarWindow !== undefined && void this.viewService.realignActiveView(menuBarWindow, workspaceToRealign.id);
} else {
logger.warn('realignActiveWorkspaceView: no active workspace');
}

View file

@ -35,7 +35,7 @@ export interface IWorkspaceViewService {
loadURL(url: string, workspaceID?: string): Promise<void>;
openUrlInWorkspace(url: string, workspaceID: string): Promise<void>;
printTiddler(tiddlerName?: string | undefined): Promise<void>;
realignActiveWorkspace(): Promise<void>;
realignActiveWorkspace(id?: string): Promise<void>;
/**
* Remove workspace metadata and its view (if it is started and have a browser view)
*/