2020-08-27 13:46:34 +02:00
|
|
|
// Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
|
2022-02-03 05:52:11 +01:00
|
|
|
import { registerPackage } from "./runtime-require";
|
2021-08-30 14:41:40 +02:00
|
|
|
|
2021-01-26 01:25:22 +01:00
|
|
|
declare global {
|
|
|
|
interface Window {
|
|
|
|
bridgeCommand<T>(command: string, callback?: (value: T) => void): void;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-26 04:49:44 +02:00
|
|
|
/** HTML <a> tag pointing to a bridge command. */
|
2020-08-27 13:46:34 +02:00
|
|
|
export function bridgeLink(command: string, label: string): string {
|
|
|
|
return `<a href="javascript:bridgeCommand('${command}')">${label}</a>`;
|
|
|
|
}
|
2021-01-26 01:25:22 +01:00
|
|
|
|
|
|
|
export function bridgeCommand<T>(command: string, callback?: (value: T) => void): void {
|
|
|
|
window.bridgeCommand<T>(command, callback);
|
|
|
|
}
|
2021-08-30 14:41:40 +02:00
|
|
|
|
|
|
|
registerPackage("anki/bridgecommand", {
|
|
|
|
bridgeCommand,
|
|
|
|
});
|