Make Background a native feature
- Background replaces the Background Slideshow plugin and the background image of Appearance. It shows a folder as a slideshow, or one image. - It is on by default. Its module loads at launch only when a folder or an image is chosen. - Rust keeps the one folder in background-folder.json. The interface never sends a path. Eight background_* commands replace the six deprecated backgrounds_* commands. - The first start moves the slideshow folder and settings, and keeps the saved image as the image source. - One blur worker with a cache, fewer folder reads, and a decode before each fade. The hub writes only the changed properties. - Remove the deprecated folder methods of api.backgrounds. set, get, and subscribe stay for the Project Management plugin. - Show the view buttons in the workbench test without text, after UI-056. - Update the tests, the measurement tool, the docs, and UI-057.
This commit is contained in:
@@ -4,6 +4,7 @@ import assert from "node:assert/strict";
|
||||
import { FEATURES, featureEntry, featureOfOwner } from "../../../src/lib/features/catalog.ts";
|
||||
import { storedSwitches, switchesFrom } from "../../../src/lib/features/state.ts";
|
||||
import { legacySwitch, migrateFeatures, type LegacyPlugin } from "../../../src/lib/features/migration.ts";
|
||||
import type { BackgroundMigrationHost, BackgroundSettings } from "../../../src/lib/features/backgroundSettings.ts";
|
||||
import { featureErrors, featureRequested, loadFeature } from "../../../src/lib/features/loader.ts";
|
||||
import { FeatureSession } from "../../../src/lib/features/session.ts";
|
||||
import type { FeatureContext, FeatureInstance, FeatureModule } from "../../../src/lib/features/types.ts";
|
||||
@@ -18,15 +19,22 @@ test("each feature keeps the ID of its old plugin package as its owner ID", () =
|
||||
assert.deepEqual(git.views.map(view => [view.id, view.placement]), [["source-control", "sidebar"], ["diff", "editor"], ["graph", "editor"]]);
|
||||
assert.equal(git.views[0].title(), "Source control");
|
||||
assert.deepEqual(git.commands.map(command => [command.id, command.view]), [["graph", "graph"]]);
|
||||
const background = featureEntry("background");
|
||||
assert.equal(background.owner, "runestone.bg-slideshow");
|
||||
assert.equal(featureOfOwner("runestone.bg-slideshow")?.id, "background");
|
||||
assert.deepEqual(background.views, []);
|
||||
assert.deepEqual(background.commands.map(command => [command.id, command.view, command.title()]), [["next", undefined, "Next background image"], ["pause", undefined, "Pause background"]]);
|
||||
assert.equal(background.defaultOn, true);
|
||||
assert.equal(background.followsPackage, false);
|
||||
});
|
||||
|
||||
test("switches keep known booleans only, and missing keys take the default", () => {
|
||||
assert.deepEqual(storedSwitches({ git: false, terminal: true, other: "yes" }), { git: false });
|
||||
assert.deepEqual(storedSwitches(null), {});
|
||||
assert.deepEqual(storedSwitches(["git"]), {});
|
||||
assert.deepEqual(switchesFrom(undefined), { git: true });
|
||||
assert.deepEqual(switchesFrom({ git: false }), { git: false });
|
||||
assert.deepEqual(switchesFrom({ git: "false" }), { git: true });
|
||||
assert.deepEqual(switchesFrom(undefined), { git: true, background: true });
|
||||
assert.deepEqual(switchesFrom({ git: false, background: false }), { git: false, background: false });
|
||||
assert.deepEqual(switchesFrom({ git: "false" }), { git: true, background: true });
|
||||
});
|
||||
|
||||
test("an installed package gives its state, and without a package the default applies", () => {
|
||||
@@ -36,8 +44,19 @@ test("an installed package gives its state, and without a package the default ap
|
||||
assert.equal(legacySwitch(git, legacy(false, false)), true);
|
||||
assert.equal(legacySwitch(git, legacy(true, false)), false);
|
||||
assert.equal(legacySwitch(git, legacy(true, true)), true);
|
||||
// Background is on for every user, also after an update with a disabled Background Slideshow package.
|
||||
const background = featureEntry("background");
|
||||
for (const [installed, enabled] of [[false, false], [true, false], [true, true]]) {
|
||||
assert.equal(legacySwitch(background, { id: "runestone.bg-slideshow", installed, enabled, settings: null }), true);
|
||||
}
|
||||
assert.equal(legacySwitch(background, undefined), true);
|
||||
});
|
||||
|
||||
/** A background host with a section already present: the migration of the section does not run. */
|
||||
function presentBackground(): BackgroundMigrationHost {
|
||||
return { missing: () => false, hasImage: () => false, migrateFolder: async () => { throw new Error("not asked"); }, write: async () => { throw new Error("not asked"); } };
|
||||
}
|
||||
|
||||
test("the migration asks only for features without a switch, and keeps other keys", async () => {
|
||||
const writes: unknown[] = [];
|
||||
const asked: string[][] = [];
|
||||
@@ -46,20 +65,39 @@ test("the migration asks only for features without a switch, and keeps other key
|
||||
write: async (value: unknown) => { writes.push(value); },
|
||||
legacy: async (ids: string[]) => { asked.push(ids); return packages; },
|
||||
});
|
||||
assert.deepEqual(await migrateFeatures(host({ future: 1 }, [{ id: "runestone.git", installed: true, enabled: false, settings: null }])), ["git"]);
|
||||
assert.deepEqual(await migrateFeatures(host({ future: 1, background: false }, [{ id: "runestone.git", installed: true, enabled: false, settings: null }]), presentBackground()), ["git"]);
|
||||
assert.deepEqual(asked, [["runestone.git"]]);
|
||||
assert.deepEqual(writes, [{ future: 1, git: false }]);
|
||||
assert.deepEqual(await migrateFeatures(host({ git: true }, [])), []);
|
||||
assert.deepEqual(writes, [{ future: 1, background: false, git: false }]);
|
||||
assert.deepEqual(await migrateFeatures(host({ git: true, background: true }, []), presentBackground()), []);
|
||||
assert.equal(asked.length, 1, "A stored switch needs no package read.");
|
||||
assert.equal(writes.length, 1);
|
||||
});
|
||||
|
||||
test("a missing background section asks for the slideshow package and makes the section", async () => {
|
||||
const asked: string[][] = [];
|
||||
const switches: unknown[] = [];
|
||||
const sections: BackgroundSettings[] = [];
|
||||
const background: BackgroundMigrationHost = { missing: () => true, hasImage: () => true, migrateFolder: async () => true, write: async value => { sections.push(value); } };
|
||||
const host = { read: () => ({ git: true, background: false }), write: async (value: unknown) => { switches.push(value); }, legacy: async (ids: string[]) => { asked.push(ids); return []; } };
|
||||
assert.deepEqual(await migrateFeatures(host, background), []);
|
||||
assert.deepEqual(asked, [["runestone.bg-slideshow"]]);
|
||||
assert.deepEqual(switches, [], "Stored switches stay.");
|
||||
assert.equal(sections.length, 1);
|
||||
assert.equal(sections[0].source, "image");
|
||||
// Both migrations together ask once for both packages.
|
||||
asked.length = 0;
|
||||
await migrateFeatures({ ...host, read: () => undefined }, background);
|
||||
assert.deepEqual(asked, [["runestone.git", "runestone.bg-slideshow"]]);
|
||||
assert.deepEqual(switches, [{ git: true, background: true }]);
|
||||
});
|
||||
|
||||
test("a failed package read writes nothing, so the next start tries again", async () => {
|
||||
const writes: unknown[] = [];
|
||||
const error = console.error;
|
||||
console.error = () => {};
|
||||
try {
|
||||
const result = await migrateFeatures({ read: () => undefined, write: async value => { writes.push(value); }, legacy: async () => { throw new Error("no host"); } });
|
||||
const background: BackgroundMigrationHost = { missing: () => true, hasImage: () => true, migrateFolder: async () => true, write: async value => { writes.push(value); } };
|
||||
const result = await migrateFeatures({ read: () => undefined, write: async value => { writes.push(value); }, legacy: async () => { throw new Error("no host"); } }, background);
|
||||
assert.deepEqual(result, []);
|
||||
assert.deepEqual(writes, []);
|
||||
} finally { console.error = error; }
|
||||
@@ -97,9 +135,29 @@ test("a feature session shows its views and commands without loading the feature
|
||||
await session.launch("source-control");
|
||||
assert.deepEqual(opened, ["graph", "source-control"]);
|
||||
assert.equal(loads, 0, "Commands and navigation do not load the feature.");
|
||||
assert.equal(session.started, false);
|
||||
await session.stop();
|
||||
});
|
||||
|
||||
test("an action command loads the feature and runs it, and start loads it without a view", async () => {
|
||||
const runs: string[] = [];
|
||||
let starts = 0;
|
||||
const instance: FeatureInstance = { mount: () => () => {}, run: command => { runs.push(command); }, dispose() { runs.push("dispose"); } };
|
||||
const session = new FeatureSession(featureEntry("background"), fakeContext(), async () => ({ start: () => { starts++; return instance; } }));
|
||||
assert.deepEqual([...session.commands.keys()], ["next", "pause"]);
|
||||
assert.equal(session.commands.get("pause")?.title, "Pause background");
|
||||
assert.equal(session.started, false);
|
||||
await session.run("next");
|
||||
assert.equal(session.started, true);
|
||||
await session.start();
|
||||
await session.run("pause");
|
||||
assert.equal(starts, 1, "One instance runs the commands and the start.");
|
||||
await session.stop();
|
||||
assert.deepEqual(runs, ["next", "pause", "dispose"]);
|
||||
await assert.rejects(session.run("missing"), /This command is unavailable/);
|
||||
await assert.rejects(session.start(), /This feature is off/);
|
||||
});
|
||||
|
||||
test("the first mount starts one instance, and stop disposes it", async () => {
|
||||
const events: string[] = [];
|
||||
let starts = 0;
|
||||
|
||||
Reference in New Issue
Block a user