From 4502573519720408bc68b3e1857ca24757c48672 Mon Sep 17 00:00:00 2001 From: Dustin Brett Date: Sun, 14 Jul 2024 20:59:13 -0700 Subject: [PATCH] Don't allow launching dialogs from Run/Terminal --- components/apps/Terminal/functions.ts | 6 ++-- .../apps/Terminal/useCommandInterpreter.ts | 15 ++++++--- components/system/Dialogs/Run/index.tsx | 33 ++++++++++++------- contexts/process/directory.ts | 4 +++ contexts/process/types.ts | 1 + e2e/components/apps/Terminal.spec.ts | 6 +++- hooks/useUrlLoader.ts | 4 ++- 7 files changed, 47 insertions(+), 22 deletions(-) diff --git a/components/apps/Terminal/functions.ts b/components/apps/Terminal/functions.ts index 9ca7fce8..371ffab4 100644 --- a/components/apps/Terminal/functions.ts +++ b/components/apps/Terminal/functions.ts @@ -152,9 +152,9 @@ export const autoComplete = ( if (lowerCommand === "git") return Object.keys(gitCommands); if (directoryCommands.has(lowerCommand)) return directory; - const lowerProcesses = Object.keys(processDirectory).map((pid) => - pid.toLowerCase() - ); + const lowerProcesses = Object.entries(processDirectory) + .filter(([, { dialogProcess }]) => !dialogProcess) + .map(([pid]) => pid.toLowerCase()); if ( lowerProcesses.includes(lowerCommand) || diff --git a/components/apps/Terminal/useCommandInterpreter.ts b/components/apps/Terminal/useCommandInterpreter.ts index 6f6972f5..bc3a3a67 100644 --- a/components/apps/Terminal/useCommandInterpreter.ts +++ b/components/apps/Terminal/useCommandInterpreter.ts @@ -768,7 +768,11 @@ const useCommandInterpreter = ( output.push( `Uptime: ${getUptime(true)}`, - `Packages: ${Object.keys(processDirectory).length}` + `Packages: ${ + Object.entries(processDirectory).filter( + ([, { dialogProcess }]) => !dialogProcess + ).length + }` ); if (window.screen?.width && window.screen?.height) { @@ -1109,10 +1113,11 @@ const useCommandInterpreter = ( } default: if (baseCommand) { - const pid = - Object.keys(processDirectory).find( - (process) => process.toLowerCase() === lcBaseCommand - ) || resourceAliasMap[lcBaseCommand]; + const [pid] = Object.entries(processDirectory) + .filter(([, { dialogProcess }]) => !dialogProcess) + .find(([process]) => process.toLowerCase() === lcBaseCommand) || [ + resourceAliasMap[lcBaseCommand], + ]; if (pid) { const [file] = commandArgs; diff --git a/components/system/Dialogs/Run/index.tsx b/components/system/Dialogs/Run/index.tsx index 517679f1..7fdde694 100644 --- a/components/system/Dialogs/Run/index.tsx +++ b/components/system/Dialogs/Run/index.tsx @@ -115,7 +115,10 @@ const Run: FC = ({ id }) => { } } - if ((await lstat(resourcePath)).isDirectory()) { + if ( + resourcePid === "FileExplorer" && + (await lstat(resourcePath)).isDirectory() + ) { open("FileExplorer", { url: resourcePath }, ""); addRunHistoryEntry(); } else if ( @@ -123,10 +126,13 @@ const Run: FC = ({ id }) => { resourceUrl.length > 0 && resourcePath !== resource ) { - const pid = Object.keys(processDirectory).find( - (processName) => - processName.toLowerCase() === resourcePid.toLowerCase() - ); + const [pid] = + Object.entries(processDirectory) + .filter(([, { dialogProcess }]) => !dialogProcess) + .find( + ([processName]) => + processName.toLowerCase() === resourcePid.toLowerCase() + ) || []; if (pid) { const openUrl = @@ -163,13 +169,16 @@ const Run: FC = ({ id }) => { addRunHistoryEntry(); } } else { - const pid = Object.keys(processDirectory).find( - (processName) => - processName.toLowerCase() === - ( - resourceAliasMap[resourcePath.toLowerCase()] || resourcePath - ).toLowerCase() - ); + const [pid] = + Object.entries(processDirectory) + .filter(([, { dialogProcess }]) => !dialogProcess) + .find( + ([processName]) => + processName.toLowerCase() === + ( + resourceAliasMap[resourcePath.toLowerCase()] || resourcePath + ).toLowerCase() + ) || []; if (pid) { open(pid); diff --git a/contexts/process/directory.ts b/contexts/process/directory.ts index 88a0ab2f..021a7519 100644 --- a/contexts/process/directory.ts +++ b/contexts/process/directory.ts @@ -177,6 +177,7 @@ const directory: Processes = { height: 492, width: 392, }, + dialogProcess: true, hideTaskbarEntry: true, hideTitlebar: true, icon: "/System/Icons/unknown.webp", @@ -215,6 +216,7 @@ const directory: Processes = { height: 412, width: 361, }, + dialogProcess: true, hideMaximizeButton: true, hideMinimizeButton: true, icon: "", @@ -251,6 +253,7 @@ const directory: Processes = { height: 174, width: 397, }, + dialogProcess: true, hideMaximizeButton: true, hideMinimizeButton: true, icon: "/System/Icons/run.webp", @@ -327,6 +330,7 @@ const directory: Processes = { height: 163, width: 400, }, + dialogProcess: true, icon: "/System/Icons/copying.webp", title: "", }, diff --git a/contexts/process/types.ts b/contexts/process/types.ts index 983edecd..0fcca8b9 100644 --- a/contexts/process/types.ts +++ b/contexts/process/types.ts @@ -75,6 +75,7 @@ export type Process = ProcessArguments & Component: React.ComponentType; closing?: boolean; defaultSize?: Size; + dialogProcess?: boolean; hasWindow?: boolean; icon: string; maximized?: boolean; diff --git a/e2e/components/apps/Terminal.spec.ts b/e2e/components/apps/Terminal.spec.ts index c0dde3e5..da4d1f00 100644 --- a/e2e/components/apps/Terminal.spec.ts +++ b/e2e/components/apps/Terminal.spec.ts @@ -211,7 +211,11 @@ test.describe("has commands", () => { await sendToTerminal({ page }, "neofetch"); await terminalHasText( { page }, - `Packages: ${Object.keys(directory).length}` + `Packages: ${ + Object.entries(directory).filter( + ([, { dialogProcess }]) => !dialogProcess + ).length + }` ); }); diff --git a/hooks/useUrlLoader.ts b/hooks/useUrlLoader.ts index 6721795c..512f8c16 100644 --- a/hooks/useUrlLoader.ts +++ b/hooks/useUrlLoader.ts @@ -43,7 +43,9 @@ const useUrlLoader = (): void => { if (app) { const lcAppNames = Object.fromEntries( - Object.keys(processDirectory).map((name) => [name.toLowerCase(), name]) + Object.entries(processDirectory) + .filter(([, { dialogProcess }]) => !dialogProcess) + .map(([name]) => [name.toLowerCase(), name]) ); loadInitialApp(lcAppNames[app.toLowerCase()]);