From 5abd7ae6f3fdb7d9736a0f2993617df0a086670d Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Tue, 26 Jan 2021 01:25:22 +0100 Subject: [PATCH] Add bridgeCommand helper function --- ts/graphs/GraphsPage.svelte | 1 + ts/lib/bridgecommand.ts | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/ts/graphs/GraphsPage.svelte b/ts/graphs/GraphsPage.svelte index f26aae9fa..2597a09f0 100644 --- a/ts/graphs/GraphsPage.svelte +++ b/ts/graphs/GraphsPage.svelte @@ -8,6 +8,7 @@ import type pb from "anki/backend_proto"; import { getGraphData, RevlogRange, daysToRevlogRange } from "./graph-helpers"; import { getPreferences } from "./preferences"; + import { bridgeCommand } from "anki/bridgecommand"; export let i18n: I18n; export let nightMode: boolean; diff --git a/ts/lib/bridgecommand.ts b/ts/lib/bridgecommand.ts index b7a0f721b..927e7dd03 100644 --- a/ts/lib/bridgecommand.ts +++ b/ts/lib/bridgecommand.ts @@ -1,7 +1,17 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +declare global { + interface Window { + bridgeCommand(command: string, callback?: (value: T) => void): void; + } +} + /// HTML tag pointing to a bridge command. export function bridgeLink(command: string, label: string): string { return `${label}`; } + +export function bridgeCommand(command: string, callback?: (value: T) => void): void { + window.bridgeCommand(command, callback); +}