From 113298e1e6af49e5d8a367383f144f7767bf2f2c Mon Sep 17 00:00:00 2001 From: linonetwo Date: Wed, 24 May 2023 14:00:15 +0800 Subject: [PATCH] feat: show lastNodeJSArgv in workspace settings --- localization/locales/en/translation.json | 3 ++- localization/locales/zh_CN/translation.json | 3 ++- src/pages/AddWorkspace/useForm.ts | 1 + src/pages/EditWorkspace/blog.tsx | 20 ++++++++++++++++++-- src/services/view/setupViewSession.ts | 2 +- src/services/wiki/index.ts | 1 + src/services/wiki/interface.ts | 1 + src/services/wiki/wikiWorker.ts | 19 +++++++++++-------- src/services/workspaces/index.ts | 1 + src/services/workspaces/interface.ts | 4 ++++ 10 files changed, 42 insertions(+), 13 deletions(-) diff --git a/localization/locales/en/translation.json b/localization/locales/en/translation.json index d7453db2..4f3c5c22 100644 --- a/localization/locales/en/translation.json +++ b/localization/locales/en/translation.json @@ -197,7 +197,8 @@ "ExcludedPluginsDescription": "When starting the wiki as a blog in read-only mode, you may want to not load some editing-related plugins to reduce the size of the first-loaded web page, such as $:/plugins/tiddlywiki/codemirror, etc. After all, the loaded blog does not need these editing functions.", "HTTPSCertPath": "Cert file path", "HTTPSKeyPath": "Key file path", - "HTTPSKeyPathDescription": "The location of the private key file with the suffix .key." + "HTTPSKeyPathDescription": "The location of the private key file with the suffix .key.", + "LastNodeJSArgv": "Command line arguments from the latest startup" }, "Dialog": { "CantFindWorkspaceFolderRemoveWorkspace": "Cannot find the workspace folder that was still there before! \nThe folders that should have existed here may have been removed, or there is no wiki in this folder! \nDo you want to remove the workspace?", diff --git a/localization/locales/zh_CN/translation.json b/localization/locales/zh_CN/translation.json index 58b3c5e6..74372522 100644 --- a/localization/locales/zh_CN/translation.json +++ b/localization/locales/zh_CN/translation.json @@ -231,7 +231,8 @@ "ExcludedPlugins": "需忽略的插件", "AddExcludedPlugins": "输入希望忽略的插件名", "AddExcludedPluginsDescription": "可搜索当前Wiki中已安装的插件,或输入任意插件名。", - "ExcludedPluginsDescription": "在只读模式启动Wiki作为博客时,你可能希望不加载一些编辑相关的插件以减小初次加载的网页大小,例如 $:/plugins/tiddlywiki/codemirror 等,毕竟加载的博客不需要这些编辑功能。" + "ExcludedPluginsDescription": "在只读模式启动Wiki作为博客时,你可能希望不加载一些编辑相关的插件以减小初次加载的网页大小,例如 $:/plugins/tiddlywiki/codemirror 等,毕竟加载的博客不需要这些编辑功能。", + "LastNodeJSArgv": "最近一次启动的命令行参数" }, "Scripting": { "ExecutingScript": "正在执行脚本" diff --git a/src/pages/AddWorkspace/useForm.ts b/src/pages/AddWorkspace/useForm.ts index 097d8fb1..4dce41de 100644 --- a/src/pages/AddWorkspace/useForm.ts +++ b/src/pages/AddWorkspace/useForm.ts @@ -181,5 +181,6 @@ export async function workspaceConfigFromForm(form: INewWikiRequiredFormData, is tokenAuth: true, userName: userNameIsEmpty ? DEFAULT_USER_NAME : undefined, excludedPlugins: [], + lastNodeJSArgv: [], }; } diff --git a/src/pages/EditWorkspace/blog.tsx b/src/pages/EditWorkspace/blog.tsx index da928b5d..b712e029 100644 --- a/src/pages/EditWorkspace/blog.tsx +++ b/src/pages/EditWorkspace/blog.tsx @@ -63,6 +63,7 @@ export function BlogOptions(props: IBlogOptionsProps) { readOnlyMode, rootTiddler, tokenAuth, + lastNodeJSArgv, } = (workspace ?? {}) as unknown as IWorkspace; const alreadyEnableSomeBlogOptions = readOnlyMode; @@ -101,6 +102,14 @@ export function BlogOptions(props: IBlogOptionsProps) { }} /> + {Array.isArray(lastNodeJSArgv) && ( + <> + + + + + + )} @@ -291,8 +300,15 @@ function ExcludedPluginsAutocomplete(props: { workspace: IWorkspace; workspaceSe )} ChipProps={{ onDelete: (event) => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, unicorn/prefer-dom-node-text-content - const value = ((event.target)?.parentNode as HTMLDivElement).innerText; + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment + let node = (event.target).parentNode; + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + if (node.tagName !== 'DIV') { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + node = node.parentNode; + } + // eslint-disable-next-line unicorn/prefer-dom-node-text-content + const value = (node as HTMLDivElement).innerText; workspaceSetter({ ...workspace, excludedPlugins: excludedPlugins.filter(item => item !== value) }, true); }, }} diff --git a/src/services/view/setupViewSession.ts b/src/services/view/setupViewSession.ts index 1799c11f..57fe1a84 100644 --- a/src/services/view/setupViewSession.ts +++ b/src/services/view/setupViewSession.ts @@ -31,7 +31,7 @@ export function setupViewSession(workspace: IWorkspace, preferences: IPreference } sessionOfView.webRequest.onBeforeSendHeaders((details, callback) => { assignFakeUserAgent(details); - if (workspace.readOnlyMode) { + if (workspace.tokenAuth) { assignAdminAuthToken(workspace.id, details, authService, viewContext); } callback({ cancel: false, requestHeaders: details.requestHeaders }); diff --git a/src/services/wiki/index.ts b/src/services/wiki/index.ts index 75b1cc64..1ae6d2bd 100644 --- a/src/services/wiki/index.ts +++ b/src/services/wiki/index.ts @@ -160,6 +160,7 @@ export class Wiki implements IWikiService { // subscribe to the Observable that startNodeJSWiki returns, handle messages send by our code worker.startNodeJSWiki(workerData).subscribe(async (message) => { if (message.type === 'control') { + await this.workspaceService.update(workspaceID, { lastNodeJSArgv: message.argv }, true); switch (message.actions) { case WikiControlActions.booted: { setTimeout(async () => { diff --git a/src/services/wiki/interface.ts b/src/services/wiki/interface.ts index 0381eed2..1b64cc04 100644 --- a/src/services/wiki/interface.ts +++ b/src/services/wiki/interface.ts @@ -120,6 +120,7 @@ export enum WikiControlActions { } export interface IWikiControlMessage { actions: WikiControlActions; + argv: string[]; message?: string; /** where this bug rise, helps debug */ source?: string; diff --git a/src/services/wiki/wikiWorker.ts b/src/services/wiki/wikiWorker.ts index 2540cfd3..8a3f3adf 100644 --- a/src/services/wiki/wikiWorker.ts +++ b/src/services/wiki/wikiWorker.ts @@ -59,13 +59,14 @@ function startNodeJSWiki({ userName: string; }): Observable { return new Observable((observer) => { - observer.next({ type: 'control', actions: WikiControlActions.start }); + let fullBootArgv: string[] = []; + observer.next({ type: 'control', actions: WikiControlActions.start, argv: fullBootArgv }); intercept( (newStdOut: string) => { observer.next({ type: 'stdout', message: newStdOut }); }, (newStdError: string) => { - observer.next({ type: 'control', source: 'intercept', actions: WikiControlActions.error, message: newStdError }); + observer.next({ type: 'control', source: 'intercept', actions: WikiControlActions.error, message: newStdError, argv: fullBootArgv }); }, ); @@ -101,7 +102,7 @@ function startNodeJSWiki({ if (adminTokenIsProvided(adminToken)) { tokenAuthenticateArguments = [`authenticated-user-header=${getTidGiAuthHeaderWithToken(adminToken)}`, `readers=${userName}`, `writers=${userName}`]; } else { - observer.next({ type: 'control', actions: WikiControlActions.error, message: 'tokenAuth is true, but adminToken is empty, this can be a bug.' }); + observer.next({ type: 'control', actions: WikiControlActions.error, message: 'tokenAuth is true, but adminToken is empty, this can be a bug.', argv: fullBootArgv }); } } // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions @@ -126,7 +127,7 @@ function startNodeJSWiki({ ] : []; - wikiInstance.boot.argv = [ + fullBootArgv = [ ...builtInPluginArguments, homePath, '--listen', @@ -137,12 +138,13 @@ function startNodeJSWiki({ ...readonlyArguments, ...tokenAuthenticateArguments, ...excludePluginsArguments, - `debug-level=${isDev ? 'full' : 'none'}`, + // `debug-level=${isDev ? 'full' : 'none'}`, ]; + wikiInstance.boot.argv = [...fullBootArgv]; wikiInstance.hooks.addHook('th-server-command-post-start', function(listenCommand, server) { server.on('error', function(error: Error) { - observer.next({ type: 'control', actions: WikiControlActions.error, message: error.message }); + observer.next({ type: 'control', actions: WikiControlActions.error, message: error.message, argv: fullBootArgv }); }); server.on('listening', function() { observer.next({ @@ -150,15 +152,16 @@ function startNodeJSWiki({ actions: WikiControlActions.booted, message: `Tiddlywiki booted at http://${tiddlyWikiHost}:${tiddlyWikiPort} (webview uri ip may be different, being nativeService.getLocalHostUrlWithActualInfo(appUrl, workspace.id)) with args ${ - wikiInstance === undefined ? '(wikiInstance is undefined)' : wikiInstance.boot.argv.join(' ') + wikiInstance === undefined ? '(wikiInstance is undefined)' : fullBootArgv.join(' ') }`, + argv: fullBootArgv, }); }); }); wikiInstance.boot.startup({ bootPath: TIDDLYWIKI_PACKAGE_FOLDER }); } catch (error) { const message = `Tiddlywiki booted failed with error ${(error as Error).message} ${(error as Error).stack ?? ''}`; - observer.next({ type: 'control', source: 'try catch', actions: WikiControlActions.error, message }); + observer.next({ type: 'control', source: 'try catch', actions: WikiControlActions.error, message, argv: fullBootArgv }); } }); } diff --git a/src/services/workspaces/index.ts b/src/services/workspaces/index.ts index 42145d59..c05d552f 100644 --- a/src/services/workspaces/index.ts +++ b/src/services/workspaces/index.ts @@ -468,6 +468,7 @@ export class Workspace implements IWorkspaceService { homeUrl: `http://${defaultServerIP}:${newWorkspaceConfig.port}`, id: newID, lastUrl: null, + lastNodeJSArgv: [], order: max + 1, picturePath: null, subWikiFolderName: 'subwiki', diff --git a/src/services/workspaces/interface.ts b/src/services/workspaces/interface.ts index 6b833532..29f3011e 100644 --- a/src/services/workspaces/interface.ts +++ b/src/services/workspaces/interface.ts @@ -53,6 +53,10 @@ export interface IWorkspace { * Is this workspace a subwiki that link to a main wiki, and doesn't have its own webview? */ isSubWiki: boolean; + /** + * Nodejs start argument cli, used to start tiddlywiki server in terminal + */ + lastNodeJSArgv?: string[]; /** * Last visited url, used for rememberLastPageVisited in preferences */