mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-15 15:10:31 -08:00
refactor: use getTiddlerText on WikiOperations instead of service.getTiddlerText
This commit is contained in:
parent
4b09485cea
commit
360157290b
6 changed files with 13 additions and 32 deletions
|
|
@ -56,7 +56,6 @@ export enum WikiChannel {
|
|||
deleteTiddler = 'wiki-delete-tiddler',
|
||||
generalNotification = 'wiki-notification-tiddly-git',
|
||||
getTiddlerText = 'wiki-get-tiddler-text',
|
||||
getTiddlerTextDone = 'wiki-get-tiddler-text-done',
|
||||
/**
|
||||
* `$tw.wiki.getTiddlersAsJson('[all[]]')`
|
||||
*
|
||||
|
|
|
|||
|
|
@ -92,10 +92,10 @@ export class Git implements IGitService {
|
|||
* similar to "linonetwo/wiki", string after "https://com/"
|
||||
*/
|
||||
const githubRepoName = `${userName}/${repoName}`;
|
||||
if (await this.wikiService.getTiddlerText(workspace, '$:/GitHub/Repo') !== githubRepoName) {
|
||||
if (await this.wikiService.wikiOperationInServer(WikiChannel.getTiddlerText, workspace.id, ['$:/GitHub/Repo']) !== githubRepoName) {
|
||||
await this.wikiService.wikiOperationInBrowser(WikiChannel.addTiddler, workspace.id, ['$:/GitHub/Repo', githubRepoName]);
|
||||
}
|
||||
if (await this.wikiService.getTiddlerText(workspace, '$:/GitHub/Branch') !== branch) {
|
||||
if (await this.wikiService.wikiOperationInServer(WikiChannel.getTiddlerText, workspace.id, ['$:/GitHub/Branch']) !== branch) {
|
||||
await this.wikiService.wikiOperationInBrowser(WikiChannel.addTiddler, workspace.id, ['$:/GitHub/Branch', branch]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
/* eslint-disable @typescript-eslint/no-misused-promises */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/no-dynamic-delete */
|
||||
import { dialog, ipcMain, shell } from 'electron';
|
||||
import { dialog, shell } from 'electron';
|
||||
import { backOff } from 'exponential-backoff';
|
||||
import { copy, createSymlink, exists, mkdir, mkdirp, mkdirs, pathExists, readFile, remove, unlink } from 'fs-extra';
|
||||
import { injectable } from 'inversify';
|
||||
|
|
@ -577,29 +577,6 @@ export class Wiki implements IWikiService {
|
|||
return this.justStartedWiki[id] ?? false;
|
||||
}
|
||||
|
||||
public async getTiddlerText(workspace: IWorkspace, title: string): Promise<string | undefined> {
|
||||
const textResult: string = await new Promise((resolve) => {
|
||||
/**
|
||||
* Use nonce to prevent data racing
|
||||
*/
|
||||
const nonce = Math.random();
|
||||
const listener = (_event: Electron.IpcMainEvent, nonceReceived: number, value: string): void => {
|
||||
if (nonce === nonceReceived) {
|
||||
ipcMain.removeListener(WikiChannel.getTiddlerTextDone, listener);
|
||||
resolve(value);
|
||||
}
|
||||
};
|
||||
ipcMain.on(WikiChannel.getTiddlerTextDone, listener);
|
||||
const browserView = this.viewService.getView(workspace.id, WindowNames.main);
|
||||
if (!browserView?.webContents) {
|
||||
logger.error(`browserView is undefined in getTiddlerText ${workspace.id} when running title ${title}`);
|
||||
return;
|
||||
}
|
||||
browserView.webContents.send(WikiChannel.getTiddlerText, nonce, title);
|
||||
});
|
||||
return textResult;
|
||||
}
|
||||
|
||||
public async wikiStartup(workspace: IWorkspace): Promise<void> {
|
||||
const { id, isSubWiki, name, mainWikiID, wikiFolderLocation } = workspace;
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ export interface IWikiService {
|
|||
* @param title tiddler title to open
|
||||
*/
|
||||
getTiddlerFilePath(title: string, workspaceID?: string): Promise<string | undefined>;
|
||||
getTiddlerText(workspace: IWorkspace, title: string): Promise<string | undefined>;
|
||||
getWikiChangeObserver$(workspaceID: string): Observable<IChangedTiddlers>;
|
||||
getWikiErrorLogs(workspaceID: string, wikiName: string): Promise<{ content: string; filePath: string }>;
|
||||
/**
|
||||
|
|
@ -112,7 +111,6 @@ export const WikiServiceIPCDescriptor = {
|
|||
ensureWikiExist: ProxyPropertyType.Function,
|
||||
extractWikiHTML: ProxyPropertyType.Function,
|
||||
getSubWikiPluginContent: ProxyPropertyType.Function,
|
||||
getTiddlerText: ProxyPropertyType.Function,
|
||||
getWikiErrorLogs: ProxyPropertyType.Function,
|
||||
linkWiki: ProxyPropertyType.Function,
|
||||
getTiddlerFilePath: ProxyPropertyType.Function,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,11 @@ import { wikiOperationScripts } from '@services/wiki/wikiOperations/executor/scr
|
|||
import { ipcRenderer, webFrame } from 'electron';
|
||||
import type { ITiddlerFields } from 'tiddlywiki';
|
||||
|
||||
// use scripts from wikiOperationScripts
|
||||
/**
|
||||
* Use scripts from wikiOperationScripts.
|
||||
*
|
||||
* Also need to modify `src/services/wiki/wikiOperations/sender/sendWikiOperationsToBrowser.ts`
|
||||
*/
|
||||
export const wikiOperations = {
|
||||
[WikiChannel.setState]: async (stateKey: string, content: string) => {
|
||||
await executeTWJavaScriptWhenIdle(
|
||||
|
|
@ -25,7 +29,7 @@ export const wikiOperations = {
|
|||
},
|
||||
[WikiChannel.getTiddlerText]: async (nonceReceived: number, title: string) => {
|
||||
const tiddlerText: string = await (executeTWJavaScriptWhenIdle(wikiOperationScripts[WikiChannel.getTiddlerText](title)));
|
||||
ipcRenderer.send(WikiChannel.getTiddlerTextDone, nonceReceived, tiddlerText);
|
||||
ipcRenderer.send(WikiChannel.getTiddlerText, nonceReceived, tiddlerText);
|
||||
},
|
||||
[WikiChannel.runFilter]: async (nonceReceived: number, filter: string) => {
|
||||
const filterResult: string[] = await (executeTWJavaScriptWhenIdle(wikiOperationScripts[WikiChannel.runFilter](filter)));
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import type { ITiddlerFields } from 'tiddlywiki';
|
|||
const sendNoWait = sendToMainWindowNoWait;
|
||||
const sendAndWait = sendToMainWindowAndAwait;
|
||||
/**
|
||||
* Handle sending message to trigger operations defined in `src/preload/wikiOperation.ts`
|
||||
* Handle sending message to trigger operations defined in `src/services/wiki/wikiOperations/executor/wikiOperationInBrowser.ts`
|
||||
*/
|
||||
export const getSendWikiOperationsToBrowser = (workspaceID: string) =>
|
||||
({
|
||||
|
|
@ -57,6 +57,9 @@ export const getSendWikiOperationsToBrowser = (workspaceID: string) =>
|
|||
[WikiChannel.setTiddlerText]: async (title: string, value: string, options?: { timeout?: number }): Promise<void> => {
|
||||
await sendAndWait(WikiChannel.setTiddlerText, workspaceID, [title, value], options);
|
||||
},
|
||||
[WikiChannel.getTiddlerText]: async (title: string): Promise<void> => {
|
||||
return await sendAndWait(WikiChannel.getTiddlerText, workspaceID, [title]);
|
||||
},
|
||||
[WikiChannel.renderWikiText]: async (content: string): Promise<string | undefined> => {
|
||||
return await sendAndWait(WikiChannel.renderWikiText, workspaceID, [content]);
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue