Add bridgeCommand helper function

This commit is contained in:
Henrik Giesel 2021-01-26 01:25:22 +01:00
parent 5a987d77b2
commit 5abd7ae6f3
2 changed files with 11 additions and 0 deletions

View File

@ -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;

View File

@ -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<T>(command: string, callback?: (value: T) => void): void;
}
}
/// HTML <a> tag pointing to a bridge command.
export function bridgeLink(command: string, label: string): string {
return `<a href="javascript:bridgeCommand('${command}')">${label}</a>`;
}
export function bridgeCommand<T>(command: string, callback?: (value: T) => void): void {
window.bridgeCommand<T>(command, callback);
}