feat: show lastNodeJSArgv in workspace settings

This commit is contained in:
linonetwo 2023-05-24 14:00:15 +08:00
parent dd1cbaf77d
commit 113298e1e6
10 changed files with 42 additions and 13 deletions

View file

@ -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?",

View file

@ -231,7 +231,8 @@
"ExcludedPlugins": "需忽略的插件",
"AddExcludedPlugins": "输入希望忽略的插件名",
"AddExcludedPluginsDescription": "可搜索当前Wiki中已安装的插件或输入任意插件名。",
"ExcludedPluginsDescription": "在只读模式启动Wiki作为博客时你可能希望不加载一些编辑相关的插件以减小初次加载的网页大小例如 $:/plugins/tiddlywiki/codemirror 等,毕竟加载的博客不需要这些编辑功能。"
"ExcludedPluginsDescription": "在只读模式启动Wiki作为博客时你可能希望不加载一些编辑相关的插件以减小初次加载的网页大小例如 $:/plugins/tiddlywiki/codemirror 等,毕竟加载的博客不需要这些编辑功能。",
"LastNodeJSArgv": "最近一次启动的命令行参数"
},
"Scripting": {
"ExecutingScript": "正在执行脚本"

View file

@ -181,5 +181,6 @@ export async function workspaceConfigFromForm(form: INewWikiRequiredFormData, is
tokenAuth: true,
userName: userNameIsEmpty ? DEFAULT_USER_NAME : undefined,
excludedPlugins: [],
lastNodeJSArgv: [],
};
}

View file

@ -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) {
}}
/>
</ListItem>
{Array.isArray(lastNodeJSArgv) && (
<>
<Divider />
<ListItem disableGutters>
<ListItemText primary={t('EditWorkspace.LastNodeJSArgv')} secondary={`tiddlywiki ${lastNodeJSArgv.join(' ')}`} />
</ListItem>
</>
)}
<Divider />
<ListItem disableGutters>
<ListItemText primary={t('EditWorkspace.ReadOnlyMode')} secondary={t('EditWorkspace.ReadOnlyModeDescription')} />
@ -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);
},
}}

View file

@ -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 });

View file

@ -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 () => {

View file

@ -120,6 +120,7 @@ export enum WikiControlActions {
}
export interface IWikiControlMessage {
actions: WikiControlActions;
argv: string[];
message?: string;
/** where this bug rise, helps debug */
source?: string;

View file

@ -59,13 +59,14 @@ function startNodeJSWiki({
userName: string;
}): Observable<IWikiMessage> {
return new Observable<IWikiMessage>((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 });
}
});
}

View file

@ -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',

View file

@ -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
*/