From 581618610eb35895c8df3cc14e998d84f7543e46 Mon Sep 17 00:00:00 2001 From: llama Date: Tue, 14 Oct 2025 09:20:23 +0800 Subject: [PATCH] modify helper files to support launcher --- ts/lib/generated/post.ts | 8 ++++++-- ts/lib/tslib/i18n/utils.ts | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ts/lib/generated/post.ts b/ts/lib/generated/post.ts index 90e372520..d3f44cd09 100644 --- a/ts/lib/generated/post.ts +++ b/ts/lib/generated/post.ts @@ -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( method: string, input: { toBinary(): Uint8Array; getType(): { typeName: string } }, outputType: { fromBinary(arr: Uint8Array): T }, options: PostProtoOptions = {}, ): Promise { + 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); } diff --git a/ts/lib/tslib/i18n/utils.ts b/ts/lib/tslib/i18n/utils.ts index d13e6c2c3..df1650949 100644 --- a/ts/lib/tslib/i18n/utils.ts +++ b/ts/lib/tslib/i18n/utils.ts @@ -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 { - const resources = await i18nResources(args); +export async function setupI18n(args: { modules: ModuleName[] }, launcher = false): Promise { + const fn = launcher ? launcherI18nResources : i18nResources; + const resources = await fn(args); const json = JSON.parse(new TextDecoder().decode(resources.json)); const newBundles: FluentBundle[] = [];