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 {
|
export interface PostProtoOptions {
|
||||||
/** True by default. Shows a dialog with the error message, then rethrows. */
|
/** True by default. Shows a dialog with the error message, then rethrows. */
|
||||||
alertOnError?: boolean;
|
alertOnError?: boolean;
|
||||||
|
customProtocol?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CUSTOM_PROTOCOL_URI = (navigator.platform.indexOf("Win") == -1) ? "anki://localhost" : "http://anki.localhost";
|
||||||
|
|
||||||
export async function postProto<T>(
|
export async function postProto<T>(
|
||||||
method: string,
|
method: string,
|
||||||
input: { toBinary(): Uint8Array; getType(): { typeName: string } },
|
input: { toBinary(): Uint8Array; getType(): { typeName: string } },
|
||||||
outputType: { fromBinary(arr: Uint8Array): T },
|
outputType: { fromBinary(arr: Uint8Array): T },
|
||||||
options: PostProtoOptions = {},
|
options: PostProtoOptions = {},
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
|
const { alertOnError = true, customProtocol = false } = options;
|
||||||
try {
|
try {
|
||||||
const inputBytes = input.toBinary();
|
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);
|
const outputBytes = await postProtoInner(path, inputBytes);
|
||||||
return outputType.fromBinary(outputBytes);
|
return outputType.fromBinary(outputBytes);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const { alertOnError = true } = options;
|
|
||||||
if (alertOnError && !(err instanceof Error && err.message === "500: Interrupted")) {
|
if (alertOnError && !(err instanceof Error && err.message === "500: Interrupted")) {
|
||||||
alert(err);
|
alert(err);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
import "intl-pluralrules";
|
import "intl-pluralrules";
|
||||||
|
|
||||||
import { i18nResources } from "@generated/backend";
|
import { i18nResources } from "@generated/backend";
|
||||||
|
import { i18nResources as launcherI18nResources } from "@generated/backend-launcher";
|
||||||
import type { ModuleName } from "@generated/ftl";
|
import type { ModuleName } from "@generated/ftl";
|
||||||
import { FluentBundle, FluentResource } from "@generated/ftl";
|
import { FluentBundle, FluentResource } from "@generated/ftl";
|
||||||
import { firstLanguage, setBundles } 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, "");
|
return s.replace(/[\u2068-\u2069]+/g, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setupI18n(args: { modules: ModuleName[] }): Promise<void> {
|
export async function setupI18n(args: { modules: ModuleName[] }, launcher = false): Promise<void> {
|
||||||
const resources = await i18nResources(args);
|
const fn = launcher ? launcherI18nResources : i18nResources;
|
||||||
|
const resources = await fn(args);
|
||||||
const json = JSON.parse(new TextDecoder().decode(resources.json));
|
const json = JSON.parse(new TextDecoder().decode(resources.json));
|
||||||
|
|
||||||
const newBundles: FluentBundle[] = [];
|
const newBundles: FluentBundle[] = [];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue