mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 12:47:11 -05:00
modify helper files to support launcher
This commit is contained in:
parent
8f6b1497e0
commit
581618610e
2 changed files with 10 additions and 4 deletions
|
|
@ -4,21 +4,25 @@
|
|||
export interface PostProtoOptions {
|
||||
/** True by default. Shows a dialog with the error message, then rethrows. */
|
||||
alertOnError?: boolean;
|
||||
customProtocol?: boolean;
|
||||
}
|
||||
|
||||
const CUSTOM_PROTOCOL_URI = (navigator.platform.indexOf("Win") == -1) ? "anki://localhost" : "http://anki.localhost";
|
||||
|
||||
export async function postProto<T>(
|
||||
method: string,
|
||||
input: { toBinary(): Uint8Array; getType(): { typeName: string } },
|
||||
outputType: { fromBinary(arr: Uint8Array): T },
|
||||
options: PostProtoOptions = {},
|
||||
): Promise<T> {
|
||||
const { alertOnError = true, customProtocol = false } = options;
|
||||
try {
|
||||
const inputBytes = input.toBinary();
|
||||
const path = `/_anki/${method}`;
|
||||
const backendUrl = customProtocol ? CUSTOM_PROTOCOL_URI : "/_anki";
|
||||
const path = `${backendUrl}/${method}`;
|
||||
const outputBytes = await postProtoInner(path, inputBytes);
|
||||
return outputType.fromBinary(outputBytes);
|
||||
} catch (err) {
|
||||
const { alertOnError = true } = options;
|
||||
if (alertOnError && !(err instanceof Error && err.message === "500: Interrupted")) {
|
||||
alert(err);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
import "intl-pluralrules";
|
||||
|
||||
import { i18nResources } from "@generated/backend";
|
||||
import { i18nResources as launcherI18nResources } from "@generated/backend-launcher";
|
||||
import type { ModuleName } from "@generated/ftl";
|
||||
import { FluentBundle, FluentResource } from "@generated/ftl";
|
||||
import { firstLanguage, setBundles } from "@generated/ftl";
|
||||
|
|
@ -77,8 +78,9 @@ export function withoutUnicodeIsolation(s: string): string {
|
|||
return s.replace(/[\u2068-\u2069]+/g, "");
|
||||
}
|
||||
|
||||
export async function setupI18n(args: { modules: ModuleName[] }): Promise<void> {
|
||||
const resources = await i18nResources(args);
|
||||
export async function setupI18n(args: { modules: ModuleName[] }, launcher = false): Promise<void> {
|
||||
const fn = launcher ? launcherI18nResources : i18nResources;
|
||||
const resources = await fn(args);
|
||||
const json = JSON.parse(new TextDecoder().decode(resources.json));
|
||||
|
||||
const newBundles: FluentBundle[] = [];
|
||||
|
|
|
|||
Loading…
Reference in a new issue