Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

3.2 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0

import { Button } from "@/components/ui/button";
import { useTauriUpdateController } from "@/hooks/tauri-update-context";
import { useT } from "@/i18n";
import type { ReactElement } from "react";
import { SettingsRow } from "./settings-row";

function formatDesktopVersion(version: string): string {
  return version.startsWith("v") ? version : `v${version}`;
}

export function DesktopUpdateControl(): ReactElement | null {
  const t = useT();
  const update = useTauriUpdateController();
  if (!update) return null;

  const checking = update.status === "checking";
  const inFlight =
    update.status === "updating-backend" ||
    update.status === "downloading" ||
    update.status === "installing";
  const busy = checking || inFlight;
  const available = update.info !== null && !checking;
  const checkFailed = update.checkError !== null && !available;

  let label: string;
  let description: string;
  if (checking) {
    label = t("settings.about.update.desktopChecking");
    description = t("settings.about.update.desktopCheckingDescription");
  } else if (available && update.info) {
    label = t("settings.about.update.desktopAvailable", {
      version: formatDesktopVersion(update.info.version),
    });
    description = update.isExternalServer
      ? t("settings.about.update.desktopExternalServer", {
          port: update.externalServerPort ?? "",
        })
      : update.updatePolicyMode === "manual_linux_package"
        ? t("settings.about.update.desktopManualInstall")
        : t("settings.about.update.desktopAvailableDescription");
  } else if (checkFailed) {
    label = t("settings.about.update.desktopCheckFailed");
    // Keep the raw reason: failures come from the network, HTTP, manifest or updater.
    description = update.checkError ?? label;
  } else if (update.hasChecked) {
    label = t("settings.about.update.desktopCurrent");
    description = t("settings.about.update.desktopCurrentDescription");
  } else {
    label = t("settings.about.update.desktopReady");
    description = t("settings.about.update.desktopReadyDescription");
  }

  const action = available
    ? update.updatePolicyMode === "manual_linux_package"
      ? t("settings.about.update.openReleasePage")
      : t("settings.about.update.updateNow")
    : checkFailed
      ? t("settings.about.update.retryCheck")
      : update.hasChecked
        ? t("settings.about.update.checkAgain")
        : t("settings.about.update.checkForUpdates");

  return (
    <SettingsRow
      label={label}
      description={<span aria-live="polite">{description}</span>}
    >
      {available && update.isExternalServer ? null : (
        <Button
          size="sm"
          variant={available ? "dark" : "outline"}
          disabled={busy}
          aria-busy={busy}
          onClick={() => {
            if (available) {
              void update.installUpdate();
            } else {
              void update.checkForUpdate();
            }
          }}
        >
          {checking ? t("settings.about.update.checking") : action}
        </Button>
      )}
    </SettingsRow>
  );
}