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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
// 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 { isTauri } from "@/lib/api-base";
import { useEffect } from "react";
import { subscribeToTrainingActivity } from "../lib/training-activity";
import {
isTrainingStartPending,
useTrainingRuntimeStore,
} from "../stores/training-runtime-store";
let currentHandler: ((e: BeforeUnloadEvent) => void) | null = null;
// Desktop quit never fires beforeunload; Rust asks instead, from the tray and (outside macOS) the
// close button.
function publishTrainingActive(active: boolean): void {
if (!isTauri) return;
void import("@tauri-apps/api/core")
.then(({ invoke }) => invoke("set_training_active", { active }))
.catch(() => {});
}
/** Call once at the app root. */
export function useTrainingUnloadGuard() {
useEffect(() => {
const handler = (e: BeforeUnloadEvent) => {
if (!isTrainingStartPending(useTrainingRuntimeStore.getState())) {
return;
}
e.preventDefault();
e.returnValue = "";
};
currentHandler = handler;
window.addEventListener("beforeunload", handler);
return () => {
if (currentHandler === handler) {
currentHandler = null;
}
window.removeEventListener("beforeunload", handler);
};
}, []);
useEffect(() => {
return subscribeToTrainingActivity(publishTrainingActive);
}, []);
}
/** Call before intentionally ending the session so the browser does not prompt. */
export function removeTrainingUnloadGuard() {
if (currentHandler) {
window.removeEventListener("beforeunload", currentHandler);
currentHandler = null;
}
publishTrainingActive(false);
}