Skip to content

armgit / kokon

Public Imported from GitHub
0

Edit photos by describing the change, on your own GPU. A free, open-source alternative to Nano Banana and ChatGPT image editing: photos stay on your computer, no daily limit. One installer for Windows, Mac and Linux sets up the best open model (Qwen-Image 2.1). MCP server for AI agents.

UI: Settings asks before closing with unsaved changes; setup buttons always in view; setup file names

Gabriele Lozupone993ab241d56a
diff --git a/src/components/Settings.tsx b/src/components/Settings.tsx
index ae1f5d7..464b571 100644
--- a/src/components/Settings.tsx
+++ b/src/components/Settings.tsx
@@ -1,5 +1,5 @@
import { Activity, Copy, Cpu, Download, FolderOpen, HardDrive, Heart, Layers, MonitorSmartphone, RefreshCw, RotateCcw, Settings2, Trash2, X } from "lucide-react";
-import { useEffect, useState } from "react";
+import { useEffect, useRef, useState } from "react";
import { writeText } from "@tauri-apps/plugin-clipboard-manager";
import { api } from "../lib/api";
import { native } from "../lib/native";
@@ -340,9 +340,15 @@ export function Settings() {
const improveVae = () => switchFile(api.improveVae, setVaeProgress, "The new decoder is in use");
const newImageModel = () => switchFile(api.newImageModel, setDitProgress, "The Q4_K_M image model is in use");
- const close = () => setState({ overlay: null });
+ // Leaving with unsaved changes asks first (people forgot Save): `then` runs after Save or
+ // Discard, Cancel stays here.
+ const [leaving, setLeaving] = useState<(() => void) | null>(null);
+ const leave = (then: () => void) => (dirty ? setLeaving(() => then) : then());
+ const close = () => leave(() => setState({ overlay: null }));
+ const onEscape = useRef(close);
+ onEscape.current = () => (leaving ? setLeaving(null) : close());
useEffect(() => {
- const onKey = (e: KeyboardEvent) => e.key === "Escape" && close();
+ const onKey = (e: KeyboardEvent) => e.key === "Escape" && onEscape.current();
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, []);
@@ -371,15 +377,17 @@ export function Settings() {
}
};
- const save = async () => {
+ const save = async (): Promise<boolean> => {
try {
const r = await api.saveConfig(cfg);
setDirty(false);
api.setup().then((s: SetupReport) => setUpscaler(s.checks.find((c) => c.id === "upscaler") ?? null), () => {});
toastInfo(r.backend_restart_needed ? "Saved. The model reloads with the new settings on the next generation." : "Saved");
refreshStatus();
+ return true;
} catch (e) {
toastError(e);
+ return false;
}
};
@@ -471,19 +479,19 @@ export function Settings() {
)}
<div className="field-row">
<span>What's new in Kokon {WHATS_NEW_VERSION}</span>
- <button className="btn" onClick={() => setState({ overlay: "whats-new" })}>
+ <button className="btn" onClick={() => leave(() => setState({ overlay: "whats-new" }))}>
Show
</button>
</div>
<div className="field-row">
<span>Welcome screen: what Kokon is and how it keeps your work private</span>
- <button className="btn" onClick={() => setState({ overlay: "welcome" })}>
+ <button className="btn" onClick={() => leave(() => setState({ overlay: "welcome" }))}>
Show
</button>
</div>
<div className="field-row">
<span>Tour: a short walk through an example project (adds the examples again if you removed them)</span>
- <button className="btn" onClick={startTour}>
+ <button className="btn" onClick={() => leave(startTour)}>
Start
</button>
</div>
@@ -538,10 +546,7 @@ export function Settings() {
</div>
<button
className="btn primary"
- onClick={() => {
- if (dirty && !window.confirm("Discard the unsaved changes and open the model setup?")) return;
- setState({ overlay: null, needsSetup: true });
- }}
+ onClick={() => leave(() => setState({ overlay: null, needsSetup: true }))}
>
<Download size={15} /> Set up models…
</button>
@@ -849,6 +854,41 @@ export function Settings() {
</div>
)}
</div>
+ {leaving && (
+ <div className="modal-ask" role="alertdialog" aria-label="Unsaved changes">
+ <div className="modal-ask-box">
+ <strong>Save your changes?</strong>
+ <span className="muted">Some settings were changed and not saved.</span>
+ <div className="modal-ask-actions">
+ <button className="btn ghost" onClick={() => setLeaving(null)}>
+ Cancel
+ </button>
+ <button
+ className="btn"
+ onClick={() => {
+ const then = leaving;
+ setLeaving(null);
+ setDirty(false);
+ then();
+ }}
+ >
+ Discard
+ </button>
+ <button
+ className="btn primary"
+ autoFocus
+ onClick={async () => {
+ const then = leaving;
+ setLeaving(null);
+ if (await save()) then();
+ }}
+ >
+ Save
+ </button>
+ </div>
+ </div>
+ </div>
+ )}
</div>
</div>
);
diff --git a/src/components/Setup.tsx b/src/components/Setup.tsx
index 17b3666..b32afda 100644
--- a/src/components/Setup.tsx
+++ b/src/components/Setup.tsx
@@ -71,7 +71,8 @@ function FileList({ items }: { items: InstallItem[] }) {
return (
<div className="setup-files">
{items.map((it) => (
- <div className={`setup-file ${it.state}`} key={it.id}>
+ // Prefixed: bare state names are other components' classes (.pending is the job card, .failed its error).
+ <div className={`setup-file is-${it.state}`} key={it.id}>
<ItemIcon it={it} />
<span className="name">{it.label}</span>
<span className="state">{installItemShort(it)}</span>
diff --git a/src/styles.css b/src/styles.css
index 6f9cfde..02cd91d 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -480,7 +480,12 @@ input[type="range"] { width: 100%; accent-color: var(--text); }
.overlay-head h2 { font-size: 15px; font-weight: 600; margin: 0; }
.overlay-head .spacer { flex: 1; }
.modal-scrim { position: fixed; inset: 0; z-index: 50; background: rgba(13, 13, 12, 0.34); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); display: grid; place-items: center; animation: fade 0.25s ease-out both; }
-.modal { width: min(760px, 92vw); height: min(640px, 88vh); background: var(--bg); border-radius: 22px; animation: welcome-in 0.35s var(--ease) both; box-shadow: var(--shadow); display: flex; overflow: hidden; }
+.modal { width: min(760px, 92vw); height: min(640px, 88vh); background: var(--bg); border-radius: 22px; animation: welcome-in 0.35s var(--ease) both; box-shadow: var(--shadow); display: flex; overflow: hidden; position: relative; }
+/* Settings: leaving with unsaved changes (Settings.tsx). */
+.modal-ask { position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; padding: 16px; background: rgba(13, 13, 12, 0.28); animation: fade 0.15s ease-out both; }
+.modal-ask-box { width: min(360px, 100%); display: flex; flex-direction: column; gap: 8px; padding: 20px; background: var(--bg); border-radius: 16px; box-shadow: var(--shadow); font-size: 13px; }
+.modal-ask-box strong { font-size: 15px; font-weight: 600; }
+.modal-ask-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.modal-nav { width: 190px; padding: 14px 8px; background: var(--ground); display: flex; flex-direction: column; gap: 2px; }
.modal-nav button { text-align: left; padding: 8px 12px; border-radius: 11px; transition: background 0.15s, box-shadow 0.2s, color 0.15s; color: var(--text-2); display: flex; gap: 10px; align-items: center; }
.modal-nav button:hover:not(.on) { background: var(--surface); color: var(--text); }
@@ -586,9 +591,10 @@ pre.diag { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font
.setup-file:first-child { border-top: 0; }
.setup-file .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.setup-file .state { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
-.setup-file.present, .setup-file.done { color: var(--text-2); }
-.setup-file.failed .state { color: var(--text); font-weight: 600; }
-.setup-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
+.setup-file.is-present, .setup-file.is-done { color: var(--text-2); }
+.setup-file.is-failed .state { color: var(--text); font-weight: 600; }
+/* Always in view at the foot of the window (Start/Done was below the fold), the page scrolling under it. */
+.setup-actions { position: sticky; bottom: 0; z-index: 2; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0 -24px; padding: 12px 24px calc(12px + env(safe-area-inset-bottom)); background: var(--ground); border-top: 1px solid var(--border); }
.btn.big { height: 42px; padding: 0 20px; font-size: 14px; border-radius: 12px; }
.btn.ghost { background: transparent; color: var(--text-2); }
.setup-foot { margin: 0; line-height: 1.5; }
@@ -990,7 +996,7 @@ kbd { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 6px; display
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes toast-in { from { opacity: 0; filter: blur(6px); transform: translateY(10px) scale(0.98); } to { opacity: 1; filter: none; transform: none; } }
@media (prefers-reduced-motion: reduce) {
- .overlay, .modal-scrim, .modal, .upscaler-compare, .toast, .star-prompt, .card { animation: none; }
+ .overlay, .modal-scrim, .modal, .modal-ask, .upscaler-compare, .toast, .star-prompt, .card { animation: none; }
.card:hover { transform: none; }
}