🧩
Seanime Extensions
🧩
Seanime Extensions
  • Seanime
    • Getting started
    • Core APIs
    • Changelog
  • Content Providers
    • Write, test, share
    • Anime torrent provider
    • Manga provider
    • Online streaming provider
  • Plugins
    • Introduction
    • Write, test, share
    • APIs
      • Helpers
      • Store
      • Storage
      • Database
      • AniList
      • System
        • Permissions
        • OS
        • Filepath
        • Commands
        • Buffers, I/O
        • MIME
    • UI
      • Basics
      • User Interface
        • Tray
        • Toast
        • Screen
        • Command Palette
        • Action
        • DOM
      • Anime/Library
        • Anime
        • Playback
        • Continuity
        • Auto Downloader
        • Auto Scanner
        • Filler Manager
        • External Player Link
      • Downloading
        • Downloader
        • Torrent Client
      • Other
        • Manga
        • Discord
        • MPV
    • Hooks
    • Example
  • Frequently asked
    • Feature requests
Powered by GitBook
On this page
  • Create a command palette
  • Keyboard shortcut
  • Items
  1. Plugins
  2. UI
  3. User Interface

Command Palette

PreviousScreenNextAction

Last updated 21 days ago

Create a command palette

You can only create one command palette in your plugin.

// ...

const cmd = ctx.newCommandPalette({
    placeholder: "Search for something",
    // The command palette will open when the user presses 't'
    // You can choose to not have a keyboard shortcut
    keyboardShortcut: "t",
})

// Open the command palette when the tray icon is clicked
tray.onClick(() => {
    cmd.open()
})

Keyboard shortcut

You can set a keyboard shortcut for your command palette. Read this documentation to learn how to format it: .

Items

async function fetchTodos() {
    // Fetch the todos
    const res = await ctx.fetch("https://jsonplaceholder.typicode.com/todos")
    const todos = res.json<{ title: string }[]>()

    // Set the items
    // Calling `setItems` will automatically re-render the command palette
    cmd.setItems(todos.map((todo) => ({
        label: todo.title,
        value: todo.title, // This is used for filtering, should be unique!
        // Optional filtering for when the user writes something in the input
        filterType: "includes", // or "contains"
        onSelect: () => {
            ctx.toast.info(`Todo ${todo.title} selected`)
        },
    })))
}

// Default item
cmd.setItems([
    {
        label: "Fetch Todos",
        value: "fetch todos",
        onSelect: async () => {
            await fetchTodos()
        },
    },
])
https://craig.is/killing/mice