Use non-native alert and confirm dialogs

This commit is contained in:
Shantur Rathore
2025-11-21 19:28:53 +00:00
parent b1987008c7
commit 631b5002e7
8 changed files with 239 additions and 14 deletions

View File

@@ -1,5 +1,6 @@
import type { Command } from "./commands"
import type { Command as SDKCommand } from "@opencode-ai/sdk"
import { showAlertDialog } from "../stores/alerts"
import { activeSessionId, executeCustomCommand } from "../stores/sessions"
export function commandRequiresArguments(template?: string): boolean {
@@ -33,7 +34,10 @@ export function buildCustomCommandEntries(instanceId: string, commands: SDKComma
action: async () => {
const sessionId = activeSessionId().get(instanceId)
if (!sessionId || sessionId === "info") {
alert("Select a session before running a custom command.")
showAlertDialog("Select a session before running a custom command.", {
title: "Session required",
variant: "warning",
})
return
}
const args = promptForCommandArguments(cmd)
@@ -44,7 +48,10 @@ export function buildCustomCommandEntries(instanceId: string, commands: SDKComma
await executeCustomCommand(instanceId, sessionId, cmd.name, args)
} catch (error) {
console.error("Failed to run custom command:", error)
alert("Failed to run custom command. Check the console for details.")
showAlertDialog("Failed to run custom command. Check the console for details.", {
title: "Command failed",
variant: "error",
})
}
},
}))

View File

@@ -11,6 +11,7 @@ import {
setActiveSession,
} from "../../stores/sessions"
import { setSessionCompactionState } from "../../stores/session-compaction"
import { showAlertDialog } from "../../stores/alerts"
import type { Instance } from "../../types/instance"
export interface UseCommandsOptions {
@@ -207,7 +208,10 @@ export function useCommands(options: UseCommandsOptions) {
setSessionCompactionState(instance.id, sessionId, false)
console.error("Failed to compact session:", error)
const message = error instanceof Error ? error.message : "Failed to compact session"
alert(`Compact failed: ${message}`)
showAlertDialog(`Compact failed: ${message}`, {
title: "Compact failed",
variant: "error",
})
}
},
})
@@ -256,7 +260,10 @@ export function useCommands(options: UseCommandsOptions) {
}
if (!messageID) {
alert("Nothing to undo")
showAlertDialog("Nothing to undo", {
title: "No actions to undo",
variant: "info",
})
return
}
@@ -282,7 +289,10 @@ export function useCommands(options: UseCommandsOptions) {
}
} catch (error) {
console.error("Failed to revert message:", error)
alert("Failed to revert message")
showAlertDialog("Failed to revert message", {
title: "Undo failed",
variant: "error",
})
}
},
})