feat(desktop): i18n for tauri side

This commit is contained in:
adamelmore
2026-01-27 15:00:17 -06:00
parent acf0df1e98
commit 51edf68606
8 changed files with 204 additions and 28 deletions

View File

@@ -4,41 +4,45 @@ import { ask, message } from "@tauri-apps/plugin-dialog"
import { invoke } from "@tauri-apps/api/core"
import { type as ostype } from "@tauri-apps/plugin-os"
import { initI18n, t } from "./i18n"
export const UPDATER_ENABLED = window.__OPENCODE__?.updaterEnabled ?? false
export async function runUpdater({ alertOnFail }: { alertOnFail: boolean }) {
await initI18n()
let update
try {
update = await check()
} catch {
if (alertOnFail) await message("Failed to check for updates", { title: "Update Check Failed" })
if (alertOnFail)
await message(t("desktop.updater.checkFailed.message"), { title: t("desktop.updater.checkFailed.title") })
return
}
if (!update) {
if (alertOnFail)
await message("You are already using the latest version of OpenCode", { title: "No Update Available" })
if (alertOnFail) await message(t("desktop.updater.none.message"), { title: t("desktop.updater.none.title") })
return
}
try {
await update.download()
} catch {
if (alertOnFail) await message("Failed to download update", { title: "Update Failed" })
if (alertOnFail)
await message(t("desktop.updater.downloadFailed.message"), { title: t("desktop.updater.downloadFailed.title") })
return
}
const shouldUpdate = await ask(
`Version ${update.version} of OpenCode has been downloaded, would you like to install it and relaunch?`,
{ title: "Update Downloaded" },
)
const shouldUpdate = await ask(t("desktop.updater.downloaded.prompt", { version: update.version }), {
title: t("desktop.updater.downloaded.title"),
})
if (!shouldUpdate) return
try {
if (ostype() === "windows") await invoke("kill_sidecar")
await update.install()
} catch {
await message("Failed to install update", { title: "Update Failed" })
await message(t("desktop.updater.installFailed.message"), { title: t("desktop.updater.installFailed.title") })
return
}