diff --git a/src/services/workspaces/getWorkspaceMenuTemplate.ts b/src/services/workspaces/getWorkspaceMenuTemplate.ts index 774d6e8c..a7d75670 100644 --- a/src/services/workspaces/getWorkspaceMenuTemplate.ts +++ b/src/services/workspaces/getWorkspaceMenuTemplate.ts @@ -23,7 +23,10 @@ interface IWorkspaceMenuRequiredServices { wikiGitWorkspace: Pick; window: Pick; workspace: Pick; - workspaceView: Pick; + workspaceView: Pick< + IWorkspaceViewService, + 'wakeUpWorkspaceView' | 'hibernateWorkspaceView' | 'setActiveWorkspaceView' | 'restartWorkspaceViewService' | 'realignActiveWorkspace' + >; } export async function openWorkspaceTagTiddler(workspace: IWorkspace, service: IWorkspaceMenuRequiredServices): Promise { @@ -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); + }, }, ]; diff --git a/src/services/workspacesView/index.ts b/src/services/workspacesView/index.ts index b738e416..eb6ecb52 100644 --- a/src/services/workspacesView/index.ts +++ b/src/services/workspacesView/index.ts @@ -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 { + public async realignActiveWorkspace(id?: string): Promise { // 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 { - const activeWorkspace = await this.workspaceService.getActiveWorkspace(); - logger.debug(`realignActiveWorkspaceView() activeWorkspace.id: ${activeWorkspace?.id ?? 'undefined'}`); + private async realignActiveWorkspaceView(id?: string): Promise { + 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'); } diff --git a/src/services/workspacesView/interface.ts b/src/services/workspacesView/interface.ts index 43cc7cf6..8241ea2e 100644 --- a/src/services/workspacesView/interface.ts +++ b/src/services/workspacesView/interface.ts @@ -35,7 +35,7 @@ export interface IWorkspaceViewService { loadURL(url: string, workspaceID?: string): Promise; openUrlInWorkspace(url: string, workspaceID: string): Promise; printTiddler(tiddlerName?: string | undefined): Promise; - realignActiveWorkspace(): Promise; + realignActiveWorkspace(id?: string): Promise; /** * Remove workspace metadata and its view (if it is started and have a browser view) */