Close secondary workspace windows after the last tab

This commit is contained in:
Knotty Wyvern
2026-10-21 15:06:55 -07:00
parent b742d274f1
commit f741389418
4 changed files with 75 additions and 6 deletions
+47 -4
View File
@@ -42,12 +42,13 @@ await context.addInitScript(({ pluginCode }) => {
const callbacks = new Map(), listeners = new Map();
let sequence = 0, enabled = true;
const manifest = { schemaVersion: 1, id: "test.tabs", name: "Tab fixtures", author: "Tests", description: "Test editor tabs.", version: "1.0.0", apiVersion: 1, entry: "main.js", access: "full-app" };
const emit = (event, payload) => {
for (const id of listeners.get(event) || []) callbacks.get(id)?.({ event, id, payload });
const emit = async (event, payload) => {
await Promise.all((listeners.get(event) || []).map(id => callbacks.get(id)?.({ event, id, payload })));
};
window.tabTest = { mounts: {}, disposals: {}, answer: "Cancel", prompts: 0, files };
window.tabTest = { mounts: {}, disposals: {}, answer: "Cancel", prompts: 0, closeRequests: 0, destroys: 0, files };
const label = location.search.includes("secondary") ? "workspace-2" : "main";
window.__TAURI_INTERNALS__ = {
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
metadata: { currentWindow: { label }, currentWebview: { label } },
transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; },
unregisterCallback: id => callbacks.delete(id),
invoke: async (command, args = {}) => {
@@ -59,6 +60,12 @@ await context.addInitScript(({ pluginCode }) => {
}
if (command === "plugin:event|unlisten") { callbacks.delete(args.eventId); return; }
if (command === "plugin:window|is_maximized") return false;
if (command === "plugin:window|close") {
window.tabTest.closeRequests++;
await emit("tauri://close-requested");
return;
}
if (command === "plugin:window|destroy") { window.tabTest.destroys++; return; }
if (command.startsWith("plugin:window|")) return;
if (command === "plugins_snapshot") return { root, plugins: [{ manifest, hash: "test", enabled, path: root, error: null, removal: false }] };
if (command === "plugins_load") return pluginCode;
@@ -304,6 +311,42 @@ try {
assert.deepEqual(await order(), ["New tab"]);
assert.deepEqual(errors, []);
console.log("PASS: plugin tabs reorder and close without an open workspace");
for (const close of ["button", "middle", "shortcut", "all", "plugin", "dirty"]) {
await page.goto(`${url}?secondary`);
await tab("New tab").waitFor();
if (close === "plugin") {
await openView("Overview");
await page.getByRole("button", { name: "Close New tab", exact: true }).click();
assert.equal(await page.evaluate(() => window.tabTest.closeRequests), 0);
await page.getByRole("button", { name: "Close Overview", exact: true }).click();
} else if (close === "dirty") {
await openFile("a.md");
await page.locator(".cm-content").fill("Keep these unsaved edits");
await page.keyboard.press("Control+w");
await page.waitForFunction(() => window.tabTest.prompts === 1);
assert.equal(await page.evaluate(() => window.tabTest.destroys), 0);
assert.match(await page.locator(".cm-content").innerText(), /Keep these unsaved edits/);
await mkdir(".audit", { recursive: true });
await page.screenshot({ path: ".audit/secondary-last-tab-cancel.png" });
await page.evaluate(() => window.tabTest.answer = "Ok");
await page.keyboard.press("Control+w");
} else if (close === "button") {
await page.getByRole("button", { name: "Close New tab", exact: true }).click();
} else if (close === "middle") {
await tab("New tab").click({ button: "middle" });
} else if (close === "shortcut") {
await page.keyboard.press("Control+w");
} else {
await openFile("a.md");
await openFile("b.md");
await menu("b.md");
await page.getByRole("menuitem", { name: "Close all", exact: true }).click();
}
await page.waitForFunction(() => window.tabTest.destroys === 1);
assert.equal(await page.evaluate(() => window.tabTest.closeRequests), close === "dirty" ? 2 : 1);
}
assert.deepEqual(errors, []);
console.log("PASS: secondary windows close through the window guard for the last empty, document, or plugin tab; Cancel preserves unsaved edits");
} catch (error) {
await mkdir(".audit", { recursive: true });
await page.screenshot({ path: ".audit/plugin-tab-order-failure.png" });