fix: click subworkspace should open that tiddler

This commit is contained in:
lin onetwo 2022-11-20 21:51:35 +08:00
parent dc12ac81bf
commit 623e6aa22d
6 changed files with 36 additions and 17 deletions

View file

@ -51,7 +51,7 @@ ipcRenderer.on(WikiChannel.addTiddler, async (event, title: string, text: string
`);
// wait for fs to be settle
setTimeout(() => {
ipcRenderer.invoke(WikiChannel.addTiddlerDone);
void ipcRenderer.invoke(WikiChannel.addTiddlerDone);
}, 1000);
});
// get tiddler text

View file

@ -303,7 +303,7 @@ export class View implements IViewService {
}
// fix some case that local ip can't be load
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const urlToReplace = (rememberLastPageVisited && workspace.lastUrl) || workspace.homeUrl;
const urlToReplace = rememberLastPageVisited ? workspace.lastUrl ?? workspace.homeUrl : workspace.homeUrl;
const portReplacedUrl = replaceUrlPortWithSettingPort(urlToReplace, workspace.port);
const hostReplacedUrl = await getLocalHostUrlWithActualIP(portReplacedUrl);
logger.debug(`Load initialUrl: ${hostReplacedUrl} for windowName ${windowName} for workspace ${workspace.name}`, {

View file

@ -9,6 +9,9 @@ import { WindowNames } from '@services/windows/WindowProperties';
* BrowserView related things, the BrowserView is the webview like frame that renders our wiki website.
*/
export interface IViewService {
/**
* Add a new browserView and load the url
*/
addView: (workspace: IWorkspace, windowName: WindowNames) => Promise<void>;
addViewForAllBrowserViews(workspace: IWorkspace): Promise<void>;
/**
@ -34,6 +37,12 @@ export interface IViewService {
reloadViewsWebContentsIfDidFailLoad: () => Promise<void>;
removeAllViewOfWorkspace: (workspaceID: string) => void;
removeView: (workspaceID: string, windowName: WindowNames) => void;
/**
* Bring an already created view to the front. If it happened to not created, will call `addView()` to create one.
* @param workspaceID id, can only be main workspace id, because only main workspace will have view created.
* @param windowName you can control main window or menubar window to have this view.
* @returns
*/
setActiveView: (workspaceID: string, windowName: WindowNames) => Promise<void>;
setActiveViewForAllBrowserViews(workspaceID: string): Promise<void>;
setViewsAudioPref: (_shouldMuteAudio?: boolean) => void;

View file

@ -5,6 +5,11 @@ import { IViewService } from '@services/view/interface';
import { IWindowService } from '@services/windows/interface';
import { WindowNames } from '@services/windows/WindowProperties';
function sendToMainWindow(type: WikiChannel, workspaceID: string, message: string): void {
const viewService = container.get<IViewService>(serviceIdentifier.View);
const browserView = viewService.getView(workspaceID, WindowNames.main);
browserView?.webContents?.send?.(type, message);
}
/**
* Handle sending message to trigger operations defined in `src/preload/wikiOperation.ts`
*/
@ -14,20 +19,9 @@ export const wikiOperations = {
const createWorkspaceWindow = windowService.get(WindowNames.addWorkspace);
createWorkspaceWindow?.webContents?.send(WikiChannel.createProgress, message);
},
[WikiChannel.syncProgress]: (workspaceID: string, message: string): void => {
const viewService = container.get<IViewService>(serviceIdentifier.View);
const browserView = viewService.getView(workspaceID, WindowNames.main);
if (browserView !== undefined) {
browserView.webContents.send(WikiChannel.syncProgress, message);
}
},
[WikiChannel.generalNotification]: (workspaceID: string, message: string): void => {
const viewService = container.get<IViewService>(serviceIdentifier.View);
const browserView = viewService.getView(workspaceID, WindowNames.main);
if (browserView !== undefined) {
browserView.webContents.send(WikiChannel.generalNotification, message);
}
},
[WikiChannel.syncProgress]: (workspaceID: string, message: string): void => sendToMainWindow(WikiChannel.syncProgress, workspaceID, message),
[WikiChannel.generalNotification]: (workspaceID: string, message: string): void => sendToMainWindow(WikiChannel.generalNotification, workspaceID, message),
[WikiChannel.openTiddler]: (workspaceID: string, tiddlerName: string): void => sendToMainWindow(WikiChannel.openTiddler, workspaceID, tiddlerName),
// TODO: add more operations here from `src/preload/wikiOperation.ts`
};
export type IWikiOperations = typeof wikiOperations;

View file

@ -287,7 +287,19 @@ export class WorkspaceView implements IWorkspaceViewService {
if (newWorkspace === undefined) {
throw new Error(`Workspace id ${nextWorkspaceID} does not exist. When setActiveWorkspaceView().`);
}
logger.debug(`Set active workspace oldActiveWorkspace.id: ${oldActiveWorkspace?.id ?? 'undefined'} nextWorkspaceID: ${nextWorkspaceID}`);
logger.debug(
`Set active workspace oldActiveWorkspace.id: ${oldActiveWorkspace?.id ?? 'undefined'} nextWorkspaceID: ${nextWorkspaceID} newWorkspace.isSubWiki ${String(
newWorkspace.isSubWiki,
)}`,
);
if (newWorkspace.isSubWiki && typeof newWorkspace.mainWikiID === 'string') {
logger.debug(`${nextWorkspaceID} is a subwiki, set its main wiki ${newWorkspace.mainWikiID} to active instead.`);
await this.setActiveWorkspaceView(newWorkspace.mainWikiID);
if (typeof newWorkspace.tagName === 'string') {
this.wikiService.wikiOperation(WikiChannel.openTiddler, newWorkspace.mainWikiID, newWorkspace.tagName);
}
return;
}
// later process will use the current active workspace
await this.workspaceService.setActiveWorkspace(nextWorkspaceID, oldActiveWorkspace?.id);
const asyncTasks: Array<Promise<unknown>> = [];

View file

@ -46,6 +46,10 @@ export interface IWorkspaceViewService {
*/
removeWorkspaceView(workspaceID: string): Promise<void>;
restartWorkspaceViewService(workspaceID?: string | undefined): Promise<void>;
/**
* If is main workspace, set workspace to active and load the url.
* If is sub workspace, just load url with #tag for its main workspace.
*/
setActiveWorkspaceView(workspaceID: string): Promise<void>;
setWorkspaceView(workspaceID: string, workspaceOptions: IWorkspace): Promise<void>;
setWorkspaceViews(workspaces: Record<string, IWorkspace>): Promise<void>;