UI: always offer Restart now and Restart VM to apply when engine is on

This commit is contained in:
Precious Okwu authored and Precious Okwu committed 2026-11-26 11:04:28 +01:00
1 parent 99c76f0ea7
commit 175f04ad5a
4 files changed
+43 -13

No files matched your search

+3 -2
View File
@@ -321,9 +321,10 @@ pub fn resources(body: Option<Value>) {
}
let saved = body.map(|b| save(&b));
let ev = event();
let running = ev["awake"] == true || !crate::serve::is_stopped();
match saved {
// While Kiri's engine runs, the toast offers to restart WSL now.
Some(Ok(())) => emit(json!({"type": "notice", "kind": "ok", "text": tr("Saved in .wslconfig. WSL uses these from its next start"), "act": if ev["awake"] == true { "restartvm" } else { "" }}).to_string()),
// While Kiri's engine is on, the toast offers to restart WSL now.
Some(Ok(())) => emit(json!({"type": "notice", "kind": "ok", "text": tr("Saved in .wslconfig. WSL uses these from its next start"), "act": if running { "restartvm" } else { "" }}).to_string()),
Some(Err(e)) => emit(notice("error", &trf("Could not save .wslconfig: {error}", &[("error", &e)]))),
None => {}
}
+10 -6
View File
@@ -4718,8 +4718,9 @@ function dockerSockRows() {
function vmNetRow() {
const v = ui.vmnet;
if (!v || v.supported === false) return "";
const nat = v.shared_nat !== false;
const pending = v.awake && v.running_shared_nat != null && v.running_shared_nat !== nat;
const nat = v.shared_nat !== false, on = v.awake || engineShown().on;
if (v.awake && v.running_shared_nat === nat) ui.vmNetSaved = false;
const pending = on && ((v.awake && v.running_shared_nat != null && v.running_shared_nat !== nat) || (!v.awake && ui.vmNetSaved));
const desc = nat
? tr("macOS NAT: fastest. Switch to Host relay if Cloudflare WARP or a corporate firewall blocks container HTTPS. Applies on VM restart.")
: tr("Host relay: connections leave from Kiri on macOS instead of Virtualization.framework NAT. Applies on VM restart.");
@@ -4809,7 +4810,9 @@ function resourcesPane() {
const hasSwap = r.swap_mib != null;
const maxSwap = r.max_swap_mib ?? 16384;
const swapVal = hasSwap ? Math.min(d.swap_mib ?? r.swap_mib, maxSwap) : 0;
const pending = r.awake && (r.running_cpus !== r.cpus || Math.abs(r.running_memory_mib - r.memory_mib) > 64 || (hasDisk && r.running_disk_gb != null && r.running_disk_gb !== r.disk_gb) || (hasSwap && r.running_swap_mib != null && r.running_swap_mib !== r.swap_mib));
const diff = r.running_cpus !== r.cpus || Math.abs(r.running_memory_mib - r.memory_mib) > 64 || (hasDisk && r.running_disk_gb != null && r.running_disk_gb !== r.disk_gb) || (hasSwap && r.running_swap_mib != null && r.running_swap_mib !== r.swap_mib);
if (r.awake && !diff) ui.resSaved = false;
const pending = (r.awake || engineShown().on) && (diff || (!r.awake && ui.resSaved));
return `<div class="pane"><h3>${tr("Resources")}</h3>
<div class="pref"><span class="t">${tr("CPUs")}</span><span class="d">${LINUX ? tr("Shared with Linux: containers only use them while busy.") : tr("Shared with {os}: the VM only uses them while containers are busy.", { os: OS })}</span>
<div class="range"><input type="range" id="res-cpus" min="1" max="${r.max_cpus}" step="1" value="${d.cpus}" aria-label="${tr("CPUs")}" style="--fill:${rangeFill(d.cpus, 1, r.max_cpus)}"><span class="num" id="res-cpus-v">${cpuText(d.cpus)}</span></div></div>
@@ -7667,7 +7670,7 @@ function setVm(state, error) {
if (ui.view === "settings" && prefs.tab === "resources") render();
// Asleep, the VM holds no memory and the vm event says so (0 MB); off, there's nothing to read.
if (state === "stopped" || state === "stopping") ["vm-mem"].forEach((id) => ($(id).textContent = "—")), ($("vm-meter").style.width = "0");
if (state === "stopped") { ui.volSizesInFlight = 0; ui.volSizesLoading = false; ui.volSizesAt = 0; }
if (state === "stopped") { ui.volSizesInFlight = 0; ui.volSizesLoading = false; ui.volSizesAt = 0; ui.resSaved = false; ui.vmNetSaved = false; }
if (state === "running" && was !== "running") { ui.volSizesAt = 0; if (ui.view === "volumes") { requestVolumeSizes(); render(); } }
if (state === "stopped" || was === "stopped") render();
}
@@ -8838,7 +8841,7 @@ window.kiri = {
case "textsize": if (htHasFocus()) htStep(e.step); else stepTextSize(e.step); break;
case "term": htOn(e); break;
case "closekey": htCloseKey(); break;
case "vmrestarted": if (ui.restarting?.kind === "vm") stopRestartOverlay(); break;
case "vmrestarted": if (e.ok) { ui.resSaved = false; ui.vmNetSaved = false; } if (ui.restarting?.kind === "vm") stopRestartOverlay(); if (ui.view === "settings") render(); break;
case "enginerestarted": if (ui.restarting?.kind === "engine") stopRestartOverlay(); if (!e.error) engineToast(e); break;
case "view": if (empty[e.view] || e.view === "settings") show(e.view); break;
case "prefs": { const was = prefs.lang; Object.assign(prefs, e.prefs || {}); prefsIn = true; if (prefs.lang !== was) relang(); applyPrefs(); render(); paintEngine(); renderStatus(); break; }
@@ -9133,6 +9136,7 @@ $("content").addEventListener("click", (ev) => {
else if ((el = t("[data-vmnat]"))) {
const shared_nat = el.dataset.vmnat === "1";
if (ui.vmnet && !ui.vmnet.env && !!ui.vmnet.shared_nat !== shared_nat) {
if (engineShown().on) ui.vmNetSaved = true;
ui.vmnet = { ...ui.vmnet, shared_nat };
send("setvmnet", { value: { shared_nat } });
render();
@@ -9168,7 +9172,7 @@ $("content").addEventListener("click", (ev) => {
else if ((el = t("[data-regdel]"))) { const [k, i] = el.dataset.regdel.split(":"); ui.regDraft[k].splice(+i, 1); render(); }
else if ((el = t("[data-regsave]"))) { ui.regSaving = el.dataset.regsave; send("setregistryconfig", { value: { [REG_KEY[el.dataset.regsave]]: ui.regDraft[el.dataset.regsave] } }); }
else if ((el = t("[data-saverp]")) && ui.rports && !ui.rports.error) send("setrouterports", { value: { http: +(ui.rpDraft.http ?? ui.rports.http.port), https: +(ui.rpDraft.https ?? ui.rports.https.port) } });
else if ((el = t("[data-saveres]"))) send("setresources", { value: ui.resDraft });
else if ((el = t("[data-saveres]"))) { if (engineShown().on) ui.resSaved = true; send("setresources", { value: ui.resDraft }); render(); }
else if ((el = t("[data-watchbinds]"))) {
const on = el.dataset.watchbinds === "1";
if (!!(prefs.watchBindMounts ?? ui.res?.watch_bind_mounts) !== on) setPref("watchBindMounts", on);
+5 -4
View File
@@ -1021,9 +1021,10 @@ fn vm_net(save: Option<serde_json::Value>) {
let effective = env_override.or(configured).unwrap_or(true);
let info = client::get_background("/info").ok();
let awake = info.as_ref().is_some_and(|i| i["KiriVmAwake"] == true);
let running = info.as_ref().is_some_and(|i| awake || i["KiriStopped"] != true);
let running_shared_nat = awake.then(|| info.as_ref().and_then(|i| i["KiriVmUplink"]["mode"].as_str()).is_none_or(|m| m != "host-egress"));
match saved {
Some(Ok(())) => emit(serde_json::json!({"type": "notice", "kind": "ok", "text": tr("Outbound VM traffic setting saved. Restart the VM to apply."), "act": if awake { "restartvm" } else { "" }}).to_string()),
Some(Ok(())) => emit(serde_json::json!({"type": "notice", "kind": "ok", "text": tr("Outbound VM traffic setting saved. Restart the VM to apply."), "act": if running { "restartvm" } else { "" }}).to_string()),
Some(Err(e)) => emit(notice("error", &trf("Could not save VM networking setting: {error}", &[("error", &e)]))),
None => {}
}
@@ -1089,14 +1090,14 @@ fn resources(save: Option<serde_json::Value>) {
let saved = save.map(|body| client::request("POST", "/kiri/resources", Some(&body)));
let now = client::get("/kiri/resources");
match saved {
// While the VM runs, the toast offers to restart it now.
// While the engine is on (awake or resting), the toast offers to restart it now.
Some(Ok(r)) if r.ok() => {
let awake = now.as_ref().is_ok_and(|v| v["awake"] == true);
let running = now.as_ref().is_ok_and(|v| v["awake"] == true || !engine_stopped());
#[cfg(target_os = "linux")]
let text = tr("Saved. The engine uses these from its next start");
#[cfg(not(target_os = "linux"))]
let text = tr("Saved. The VM uses these from its next start");
emit(serde_json::json!({"type": "notice", "kind": "ok", "text": text, "act": if awake { "restartvm" } else { "" }}).to_string());
emit(serde_json::json!({"type": "notice", "kind": "ok", "text": text, "act": if running { "restartvm" } else { "" }}).to_string());
}
Some(Ok(r)) => emit(notice("error", &r.error())),
Some(Err(e)) => emit(notice("error", &e.to_string())),
+25 -1
View File
@@ -34,11 +34,35 @@ t("toast Restart now opens universal Restarting overlay with .rspin and syncs VM
eq(document.body.dataset.vm, "running", "restored to running");
});
t("no Restart now link while the VM is asleep", () => {
t("no Restart now link while the engine is off", () => {
kiri.on({ type: "notice", kind: "ok", text: "Saved. The VM uses these from its next start", act: "" });
if (document.querySelector("#toasts [data-trestart]")) throw new Error("link shown");
});
t("Saving resources or VM traffic while the VM is resting (engine on, awake false) still offers Restart VM to apply", () => {
kiri.on({ type: "state", state: "asleep" });
kiri.on({
type: "resources", cpus: 2, memory_mib: 12288, disk_gb: 64,
running_cpus: 2, running_memory_mib: 12288, running_disk_gb: 64,
awake: false, max_cpus: 12, max_memory_mib: 32768, min_disk_gb: 64, max_disk_gb: 1024, overridden: false,
});
prefs.tab = "resources";
show("settings");
const cpuSlider = document.getElementById("res-cpus");
cpuSlider.value = "4";
cpuSlider.dispatchEvent(new Event("input", { bubbles: true }));
document.getElementById("res-save").click();
kiri.on({
type: "resources", cpus: 4, memory_mib: 12288, disk_gb: 64,
running_cpus: 4, running_memory_mib: 12288, running_disk_gb: 64,
awake: false, max_cpus: 12, max_memory_mib: 32768, min_disk_gb: 64, max_disk_gb: 1024, overridden: false,
});
if (!document.getElementById("res-restart")) throw new Error("missing #res-restart after saving while VM is resting");
kiri.on({ type: "vmrestarted", ok: true });
if (document.getElementById("res-restart")) throw new Error("#res-restart stayed after vmrestarted");
kiri.on({ type: "state", state: "running" });
});
t("Resources Restart VM to apply and Network Restart VM to apply open Restarting overlay", () => {
kiri.on({
type: "resources", cpus: 4, memory_mib: 11264, disk_gb: 160,