diff --git a/assets/Extensions/TerminalLauncher/command-prompt.png b/assets/Core/Terminal/command-prompt.png similarity index 100% rename from assets/Extensions/TerminalLauncher/command-prompt.png rename to assets/Core/Terminal/command-prompt.png diff --git a/assets/Extensions/TerminalLauncher/iterm.png b/assets/Core/Terminal/iterm.png similarity index 100% rename from assets/Extensions/TerminalLauncher/iterm.png rename to assets/Core/Terminal/iterm.png diff --git a/assets/Extensions/TerminalLauncher/powershell-core.svg b/assets/Core/Terminal/powershell-core.svg similarity index 100% rename from assets/Extensions/TerminalLauncher/powershell-core.svg rename to assets/Core/Terminal/powershell-core.svg diff --git a/assets/Extensions/TerminalLauncher/powershell.png b/assets/Core/Terminal/powershell.png similarity index 100% rename from assets/Extensions/TerminalLauncher/powershell.png rename to assets/Core/Terminal/powershell.png diff --git a/assets/Extensions/TerminalLauncher/terminal.png b/assets/Core/Terminal/terminal.png similarity index 100% rename from assets/Extensions/TerminalLauncher/terminal.png rename to assets/Core/Terminal/terminal.png diff --git a/assets/Extensions/TerminalLauncher/windows-terminal.png b/assets/Core/Terminal/windows-terminal.png similarity index 100% rename from assets/Extensions/TerminalLauncher/windows-terminal.png rename to assets/Core/Terminal/windows-terminal.png diff --git a/assets/Extensions/TerminalLauncher/wsl.png b/assets/Core/Terminal/wsl.png similarity index 100% rename from assets/Extensions/TerminalLauncher/wsl.png rename to assets/Core/Terminal/wsl.png diff --git a/src/common/Core/ContextBridge.ts b/src/common/Core/ContextBridge.ts index 349216bd7..ef4aed8b9 100644 --- a/src/common/Core/ContextBridge.ts +++ b/src/common/Core/ContextBridge.ts @@ -4,6 +4,7 @@ import type { ExtensionInfo } from "./ExtensionInfo"; import type { OperatingSystem } from "./OperatingSystem"; import type { SearchResultItem } from "./SearchResultItem"; import type { SearchResultItemAction } from "./SearchResultItemAction"; +import { Terminal } from "./Terminal"; import type { Resources, Translations } from "./Translator"; /** @@ -23,6 +24,7 @@ export type ContextBridge = { fileExists: (filePath: string) => boolean; getAboutUeli: () => AboutUeli; getAvailableExtensions: () => ExtensionInfo[]; + getAvailableTerminals: () => Terminal[]; getEnabledExtensions: () => ExtensionInfo[]; getExtension: (extensionId: string) => ExtensionInfo; getExtensionResources: () => { extensionId: string; resources: Resources }[]; diff --git a/src/common/Core/Terminal/Terminal.ts b/src/common/Core/Terminal/Terminal.ts new file mode 100644 index 000000000..3c17fcda5 --- /dev/null +++ b/src/common/Core/Terminal/Terminal.ts @@ -0,0 +1,5 @@ +export type Terminal = { + id: string; + name: string; + assetFilePath: string; +}; diff --git a/src/common/Core/Terminal/index.ts b/src/common/Core/Terminal/index.ts new file mode 100644 index 000000000..8dbf826ed --- /dev/null +++ b/src/common/Core/Terminal/index.ts @@ -0,0 +1 @@ +export * from "./Terminal"; diff --git a/src/main/Core/Terminal/TerminalModule.ts b/src/main/Core/Terminal/TerminalModule.ts index af94a90bf..3d402b556 100644 --- a/src/main/Core/Terminal/TerminalModule.ts +++ b/src/main/Core/Terminal/TerminalModule.ts @@ -1,10 +1,14 @@ import type { Dependencies } from "@Core/Dependencies"; import type { DependencyRegistry } from "@Core/DependencyRegistry"; +import type { Terminal } from "@common/Core/Terminal"; import { TerminalRegistry } from "./TerminalRegistry"; import { CommandPrompt, Iterm, MacOsTerminal, Powershell, PowershellCore, Wsl } from "./Terminals"; export class TerminalModule { public static bootstrap(dependencyRegistry: DependencyRegistry) { + const ipcMain = dependencyRegistry.get("IpcMain"); + const assetPathResolver = dependencyRegistry.get("AssetPathResolver"); + const terminalRegistry = new TerminalRegistry(dependencyRegistry.get("OperatingSystem"), { Linux: () => [], macOS: () => [ @@ -20,5 +24,17 @@ export class TerminalModule { }); dependencyRegistry.register("TerminalRegistry", terminalRegistry); + + ipcMain.on( + "getAvailableTerminals", + (event) => + (event.returnValue = terminalRegistry.getAll().map( + ({ terminalId, getAssetFileName, getTerminalName }): Terminal => ({ + id: terminalId, + name: getTerminalName(), + assetFilePath: assetPathResolver.getModuleAssetPath("Terminal", getAssetFileName()), + }), + )), + ); } } diff --git a/src/main/Extensions/TerminalLauncher/TerminalLauncherExtension.ts b/src/main/Extensions/TerminalLauncher/TerminalLauncherExtension.ts index e8a75639c..c87ad8299 100644 --- a/src/main/Extensions/TerminalLauncher/TerminalLauncherExtension.ts +++ b/src/main/Extensions/TerminalLauncher/TerminalLauncherExtension.ts @@ -52,7 +52,7 @@ export class TerminalLauncherExtension implements Extension { public getImage(): Image { return { - url: `file://${this.assetPathResolver.getExtensionAssetPath(this.id, "windows-terminal.png")}`, + url: `file://${this.assetPathResolver.getModuleAssetPath("Terminal", "windows-terminal.png")}`, }; } @@ -117,8 +117,8 @@ export class TerminalLauncherExtension implements Extension { } public getAssetFilePath(terminalId: string): string { - return this.assetPathResolver.getExtensionAssetPath( - this.id, + return this.assetPathResolver.getModuleAssetPath( + "Terminal", this.terminalRegistry.getById(terminalId).getAssetFileName(), ); } diff --git a/src/main/Extensions/Workflow/WorkflowExtension.ts b/src/main/Extensions/Workflow/WorkflowExtension.ts index 7ddf8606b..25104ff9b 100644 --- a/src/main/Extensions/Workflow/WorkflowExtension.ts +++ b/src/main/Extensions/Workflow/WorkflowExtension.ts @@ -90,6 +90,7 @@ export class WorkflowExtension implements Extension { type: "Type", "type.OpenFile": "Open file", "type.OpenUrl": "Open URL", + "type.OpenTerminal": "Open terminal", "type.ExecuteCommand": "Execute command", newAction: "New Action", actionName: "Action name", @@ -121,6 +122,7 @@ export class WorkflowExtension implements Extension { type: "Typ", "type.OpenFile": "Datei öffnen", "type.OpenUrl": "URL öffnen", + "type.OpenTerminal": "Terminal öffnen", "type.ExecuteCommand": "Befehl ausführen", newAction: "Neue Aktion", actionName: "Name der Aktion", diff --git a/src/preload/index.ts b/src/preload/index.ts index dc2bcd2d2..f4fa794e4 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -16,6 +16,7 @@ const contextBridgeImplementation: ContextBridge = { fileExists: (filePath: string) => ipcRenderer.sendSync("fileExists", { filePath }), getAboutUeli: () => ipcRenderer.sendSync("getAboutUeli"), getAvailableExtensions: () => ipcRenderer.sendSync("getAvailableExtensions"), + getAvailableTerminals: () => ipcRenderer.sendSync("getAvailableTerminals"), getEnabledExtensions: () => ipcRenderer.sendSync("getEnabledExtensions"), getExtension: (extensionId) => ipcRenderer.sendSync("getExtension", { extensionId }), getExtensionResources: () => ipcRenderer.sendSync("getExtensionResources"), diff --git a/src/renderer/Extensions/TerminalLauncher/TerminalLauncherSettings.tsx b/src/renderer/Extensions/TerminalLauncher/TerminalLauncherSettings.tsx index a20f98f1b..4675435c4 100644 --- a/src/renderer/Extensions/TerminalLauncher/TerminalLauncherSettings.tsx +++ b/src/renderer/Extensions/TerminalLauncher/TerminalLauncherSettings.tsx @@ -1,7 +1,6 @@ import { useContextBridge, useExtensionSetting } from "@Core/Hooks"; import { Section } from "@Core/Settings/Section"; import { SectionList } from "@Core/Settings/SectionList"; -import type { OperatingSystem } from "@common/Core"; import { Dropdown, Field, Input, Option } from "@fluentui/react-components"; import { useTranslation } from "react-i18next"; @@ -12,12 +11,6 @@ export const TerminalLauncherSettings = () => { const extensionId = "TerminalLauncher"; const ns = "extension[TerminalLauncher]"; - const options: Record = { - macOS: ["Terminal", "iTerm"], - Windows: ["Command Prompt", "Powershell", "Powershell Core", "WSL"], - Linux: [], - }; - const { value: prefix, updateValue: setPrefix } = useExtensionSetting({ extensionId, key: "prefix" }); const { value: terminalIds, updateValue: setTerminalIds } = useExtensionSetting({ @@ -25,6 +18,8 @@ export const TerminalLauncherSettings = () => { key: "terminalIds", }); + const availableTerminals = contextBridge.getAvailableTerminals(); + return (
@@ -41,14 +36,10 @@ export const TerminalLauncherSettings = () => { multiselect onOptionSelect={(_, { selectedOptions }) => setTerminalIds(selectedOptions)} > - {options[contextBridge.getOperatingSystem()].map((option) => ( - ))} diff --git a/src/renderer/Extensions/Workflow/NewActionOpenTerminal.tsx b/src/renderer/Extensions/Workflow/NewActionOpenTerminal.tsx index ce49be7bd..c852da20b 100644 --- a/src/renderer/Extensions/Workflow/NewActionOpenTerminal.tsx +++ b/src/renderer/Extensions/Workflow/NewActionOpenTerminal.tsx @@ -1,15 +1,9 @@ import { useContextBridge } from "@Core/Hooks"; -import { OperatingSystem } from "@common/Core"; import type { OpenTerminalActionArgs } from "@common/Extensions/Workflow"; import { Dropdown, Field, Input, Option } from "@fluentui/react-components"; import type { NewActionTypeProps } from "./NewActionTypeProps"; export const NewActionOpenTerminal = ({ args, setArgs }: NewActionTypeProps) => { - console.log({ - m: "render", - args, - }); - const { contextBridge } = useContextBridge(); const { terminalId, command } = args as OpenTerminalActionArgs; @@ -18,31 +12,34 @@ export const NewActionOpenTerminal = ({ args, setArgs }: NewActionTypeProps) => const setCommand = (newCommand: string) => setArgs({ terminalId, command: newCommand }); - const terminalIds: Record = { - Linux: [], - macOS: ["Terminal", "iTerm"], - Windows: ["Command Prompt", "PowerShell", "Windows Terminal"], - }; + const defaultTerminalId = contextBridge.getAvailableTerminals()[0]?.id; return ( <> optionValue && setTerminalId(optionValue)} disabled={!terminalId} + size="small" > - {terminalIds[contextBridge.getOperatingSystem()].map((terminalId) => ( - ))} - setCommand(value)} placeholder="Enter a command" /> + setCommand(value)} + placeholder="Enter a command" + size="small" + /> );