Skip to content

Commit

Permalink
Pass CommandContext object to commands which contains plugin and entr…
Browse files Browse the repository at this point in the history
…ypoint preferences
  • Loading branch information
Exidex committed Jan 19, 2025
1 parent 4478f4a commit 6f7732c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
8 changes: 7 additions & 1 deletion dev_plugin/src/command-a.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
export default function Command() {
import { CommandContext } from "@project-gauntlet/api/helpers";

export default function Command({ pluginPreferences, entrypointPreferences }: CommandContext) {
const env = Deno.env.get("LD_LIBRARY_PATH");

console.log("LD_LIBRARY_PATH:", env);
console.log("pluginPreferences:");
console.dir(pluginPreferences);
console.log("entrypointPreferences:");
console.dir(entrypointPreferences);

const command = new Deno.Command("echo", {
args: ["test"],
Expand Down
5 changes: 5 additions & 0 deletions js/api/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export type GeneratorContext<P = object, E = object> = {
entrypointPreferences: E,
};

export type CommandContext<P = object, E = object> = {
pluginPreferences: P,
entrypointPreferences: E,
};

export const Clipboard: Clipboard = {
read: async function (): Promise<{ "text/plain"?: string | undefined; "image/png"?: ArrayBuffer | undefined; }> {
const data = await clipboard_read();
Expand Down
17 changes: 14 additions & 3 deletions js/core/src/core.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { runEntrypointGenerators, runGeneratedEntrypoint, runGeneratedEntrypoint
import { reloadSearchIndex } from "./search-index";
import { closeView, handleEvent, handlePluginViewKeyboardEvent, renderInlineView, renderView } from "./render";
import {
entrypoint_preferences_required, op_entrypoint_names,
entrypoint_preferences_required,
get_entrypoint_preferences,
get_plugin_preferences,
op_entrypoint_names,
op_inline_view_entrypoint_id,
op_log_trace,
op_plugin_get_pending_event,
Expand Down Expand Up @@ -97,8 +100,16 @@ export async function runPluginLoop() {
break;
}

const command: () => Promise<void> | void = (await import(`gauntlet:entrypoint?${pluginEvent.entrypointId}`)).default;
command()
type CommandContext<P = object, E = object> = {
pluginPreferences: P,
entrypointPreferences: E,
};

const pluginPreferences = get_plugin_preferences();
const entrypointPreferences = get_entrypoint_preferences(pluginEvent.entrypointId);

const command: (context: CommandContext) => Promise<void> | void = (await import(`gauntlet:entrypoint?${pluginEvent.entrypointId}`)).default;
command({ pluginPreferences, entrypointPreferences })
} catch (e) {
console.error("Error occurred when running a command", pluginEvent.entrypointId, e)
}
Expand Down

0 comments on commit 6f7732c

Please sign in to comment.