Skip to content

Commit

Permalink
feat: add system commands
Browse files Browse the repository at this point in the history
  • Loading branch information
HuakunShen committed Nov 4, 2024
1 parent 9c250b9 commit 54b7cc5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions apps/desktop/src/lib/cmds/system.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { getSystemCommands } from "@kksh/api/commands"
import type { SysCommand } from "@kksh/api/models"

export const systemCommands: SysCommand[] = getSystemCommands()
5 changes: 4 additions & 1 deletion apps/desktop/src/lib/components/main/CommandPalette.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
passing everything through props will be very complicated and hard to maintain.
-->
<script lang="ts">
import { systemCommands } from "@/cmds/system"
import { devStoreExts, installedStoreExts } from "@/stores"
import type { ExtPackageJsonExtra } from "@kksh/api/models"
import { isExtPathInDev } from "@kksh/extension/utils"
Expand All @@ -12,7 +13,8 @@ passing everything through props will be very complicated and hard to maintain.
BuiltinCmds,
CustomCommandInput,
ExtCmdsGroup,
GlobalCommandPaletteFooter
GlobalCommandPaletteFooter,
SystemCmds
} from "@kksh/ui/main"
import type { BuiltinCmd, CommandLaunchers } from "@kksh/ui/types"
import { cn } from "@kksh/ui/utils"
Expand Down Expand Up @@ -48,6 +50,7 @@ passing everything through props will be very complicated and hard to maintain.
<Command.List class="max-h-screen grow">
<Command.Empty data-tauri-drag-region>No results found.</Command.Empty>
<BuiltinCmds {builtinCmds} />
<SystemCmds {systemCommands} />
{#if $appConfig.extensionPath && $devStoreExts.length > 0}
<ExtCmdsGroup
extensions={$devStoreExts}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/commands/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export const rawSystemCommands = [
}
]

export async function getSystemCommands(): Promise<SysCommand[]> {
export function getSystemCommands(): SysCommand[] {
return rawSystemCommands
.filter(async (cmd) => cmd.platforms.includes(platform())) // Filter out system commands that are not supported on the current platform
.map((cmd) => ({
Expand Down
26 changes: 26 additions & 0 deletions packages/ui/src/components/main/SystemCmds.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script lang="ts">
import { IconEnum, SysCommand } from "@kksh/api/models"
import { Command } from "@kksh/svelte5"
import { IconMultiplexer } from "@kksh/ui"
import { DraggableCommandGroup } from "@kksh/ui/custom"
const { systemCommands }: { systemCommands: SysCommand[] } = $props()
</script>

<DraggableCommandGroup heading="System Commands">
{#each systemCommands as cmd}
<Command.Item
class="flex justify-between"
onSelect={() => {
cmd.function()
}}
>
<span class="flex gap-2">
{#if cmd.icon}
<IconMultiplexer icon={cmd.icon} class="!h-5 !w-5 shrink-0" />
{/if}
<span>{cmd.name}</span>
</span>
</Command.Item>
{/each}
</DraggableCommandGroup>
1 change: 1 addition & 0 deletions packages/ui/src/components/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export { default as BuiltinCmds } from "./BuiltinCmds.svelte"
export { default as CustomCommandInput } from "./CustomCommandInput.svelte"
export { default as GlobalCommandPaletteFooter } from "./GlobalCommandPaletteFooter.svelte"
export { default as ExtCmdsGroup } from "./ExtCmdsGroup.svelte"
export { default as SystemCmds } from "./SystemCmds.svelte"
export * from "./types"

0 comments on commit 54b7cc5

Please sign in to comment.