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:
@@ -1,7 +1,8 @@
|
||||
// Workarea backgrounds in both themes: splash, writer, reader, split, Source, narrow layouts, fades, reduced motion, and removal.
|
||||
// The saved image shows through the Background feature (src/lib/features/background/). The test also sets its own frames.
|
||||
import assert from 'node:assert/strict';
|
||||
import { writeFile } from 'node:fs/promises';
|
||||
import { chooseView, mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
import { chooseView, mockTauri, openPage, outputDir, runSmoke, showSavedImage, smokeUrl } from '../_harness/index.mjs';
|
||||
|
||||
const viewport = { width: 1280, height: 820 };
|
||||
|
||||
@@ -43,6 +44,7 @@ await runSmoke('appearance/backgroundFrames', async ({ browser }) => {
|
||||
const urls = [make('#bd486c', '#438f67'), make('#286f9b', '#725ea2')].map(url => URL.createObjectURL(blob(url)));
|
||||
window.backgroundTest = { hub: backgroundHub, owner: Symbol(), urls, saved, theme };
|
||||
}, theme);
|
||||
await showSavedImage(page);
|
||||
const background = page.locator('.workarea-background');
|
||||
const style = (locator, property, pseudo) => locator.evaluate((node, [property, pseudo]) => getComputedStyle(node, pseudo)[property], [property, pseudo]);
|
||||
async function openWelcome() {
|
||||
@@ -120,12 +122,14 @@ await runSmoke('appearance/backgroundFrames', async ({ browser }) => {
|
||||
await page.screenshot({ path: `${output}/${theme}-splash-narrow.png` });
|
||||
await page.emulateMedia({ reducedMotion: 'reduce' });
|
||||
await page.evaluate(() => { const { hub, owner, urls } = window.backgroundTest; hub.set(owner, 'app', { url: urls[0], overlay: 0.2, position: 'center', size: 'cover', previous: { url: urls[1], overlay: 0.2, position: 'center', size: 'cover' }, transitionMs: 2000 }); });
|
||||
assert.equal(await background.evaluate(node => node.getAnimations().length), 0);
|
||||
assert.equal(await background.evaluate(node => node.getAnimations({ subtree: true }).length), 0);
|
||||
await page.evaluate(() => { const { hub, owner, urls } = window.backgroundTest; hub.removeOwner(owner); urls.forEach(URL.revokeObjectURL); });
|
||||
assert.equal(await page.evaluate(() => document.body.style.getPropertyValue('--rs-background-previous-image')), '');
|
||||
// The frame of Background (the saved image) shows again, without a fade.
|
||||
assert.equal(await page.evaluate(() => document.body.style.getPropertyValue('--rs-background-previous-image')), 'none');
|
||||
assert.match(await style(background, 'backgroundImage'), /blob:/);
|
||||
await page.evaluate(async () => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode: window.backgroundTest.theme }); });
|
||||
assert.equal(await style(background, 'backgroundImage'), 'none');
|
||||
await page.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage === 'none');
|
||||
assert.equal(await page.evaluate(() => document.body.style.getPropertyValue('--rs-background-image')), '', 'Without an image, the body has no background properties');
|
||||
await openWelcome();
|
||||
await page.locator('.editor > .body').waitFor();
|
||||
assert.equal(await style(page.locator('.editor > .body'), 'backgroundColor'), await style(page.locator('.shell'), 'backgroundColor'));
|
||||
|
||||
@@ -4,7 +4,9 @@ import { writeFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
|
||||
// The image is painted on .workarea-background, not on the empty tab (src/lib/layout/Workbench.svelte:1258, 1543).
|
||||
// The image is painted on .workarea-background, not on the empty tab (src/lib/theme/background.css).
|
||||
// Background (src/lib/features/background/) loads after the first render, so each check waits for the image.
|
||||
const waitForImage = page => page.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage.includes('blob:'));
|
||||
|
||||
await runSmoke('appearance/backgroundImages', async ({ browser }) => {
|
||||
const output = await outputDir('appearance/backgroundImages');
|
||||
@@ -50,7 +52,7 @@ await runSmoke('appearance/backgroundImages', async ({ browser }) => {
|
||||
await main.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage.includes('blob:'));
|
||||
let url = await background();
|
||||
assert.equal(await decoded(main, url), 700, 'The actual new-tab image decodes');
|
||||
await main.reload(); await main.locator('.empty').waitFor();
|
||||
await main.reload(); await main.locator('.empty').waitFor(); await waitForImage(main);
|
||||
url = await background(); assert.equal(await decoded(main, url), 700, 'The saved image survives reload');
|
||||
|
||||
const pixel = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jM1sAAAAASUVORK5CYII=', 'base64');
|
||||
@@ -60,8 +62,7 @@ await runSmoke('appearance/backgroundImages', async ({ browser }) => {
|
||||
await main.waitForFunction(old => /url\("(blob:[^"]+)"\)/.exec(getComputedStyle(document.querySelector('.workarea-background')).backgroundImage)?.[1] !== old, url);
|
||||
url = await background(); assert.equal(await decoded(main, url), 1, '50 MiB image decodes');
|
||||
assert.ok(await settings.evaluate(() => JSON.stringify(window.__TEST__.settings('appearance')).length < 500), 'Image bytes stay outside the settings file');
|
||||
await main.reload(); await main.locator('.empty').waitFor();
|
||||
await main.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage.includes('blob:'));
|
||||
await main.reload(); await main.locator('.empty').waitFor(); await waitForImage(main);
|
||||
url = await background(); assert.equal(await decoded(main, url), 1, '50 MiB image survives reload');
|
||||
|
||||
const acceptedId = await savedImageId();
|
||||
|
||||
@@ -4,7 +4,8 @@ import { writeFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
|
||||
// The image is painted on .workarea-background, not on the empty tab (src/lib/layout/Workbench.svelte:1258, 1543).
|
||||
// The image is painted on .workarea-background, not on the empty tab (src/lib/theme/background.css).
|
||||
// The controls are in Appearance → Background (src/lib/features/background/BackgroundSettings.svelte).
|
||||
await runSmoke('appearance/backgroundLayout', async ({ browser }) => {
|
||||
const output = await outputDir('appearance/backgroundLayout');
|
||||
const context = await browser.newContext({ viewport: { width: 1100, height: 780 } });
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// The empty tab background image: set it in Settings, keep it after a reload, remove it, and leave Reset background disabled.
|
||||
// The empty tab background image: set it in Settings, keep it after a reload, and remove it. The source stays Image.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
@@ -24,13 +24,14 @@ await runSmoke(name, async ({ browser }) => {
|
||||
await settings.goto(smokeUrl + "/?settingsWindow=true");
|
||||
await settings.getByRole("button", { name: "Appearance", exact: true }).click();
|
||||
const png = Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jM1sAAAAASUVORK5CYII=", "base64");
|
||||
// The image now lives on the work area layer behind the empty tab (src/lib/layout/Workbench.svelte:1258, :1543-1549).
|
||||
// The image lives on the work area layer behind the empty tab (src/lib/theme/background.css).
|
||||
const layer = ".workarea-background";
|
||||
await settings.getByLabel("Background image file", { exact: true }).setInputFiles({ name: "test.png", mimeType: "image/png", buffer: png });
|
||||
await page.waitForFunction(layer => getComputedStyle(document.querySelector(layer)).backgroundImage.includes("blob:"), layer);
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.settings("background").source), "image", "A chosen image selects the image source");
|
||||
await page.reload();
|
||||
await page.locator(".empty").waitFor();
|
||||
assert.ok(await page.locator(layer).evaluate(node => getComputedStyle(node).backgroundImage.includes("blob:")), "Background survives restart");
|
||||
await page.waitForFunction(layer => getComputedStyle(document.querySelector(layer)).backgroundImage.includes("blob:"), layer);
|
||||
await settings.getByRole("button", { name: "Remove image", exact: true }).click();
|
||||
await page.waitForFunction(layer => getComputedStyle(document.querySelector(layer)).backgroundImage === "none", layer);
|
||||
for (const mode of ["light", "dark"]) {
|
||||
@@ -42,8 +43,10 @@ await runSmoke(name, async ({ browser }) => {
|
||||
await settings.setViewportSize({ width: 650, height: 760 });
|
||||
await settings.screenshot({ path: path.join(output, `appearance-${mode}-narrow.png`) });
|
||||
}
|
||||
assert.equal(await settings.getByRole("button", { name: "Reset background", exact: true }).isDisabled(), true);
|
||||
assert.equal(await settings.getByRole("button", { name: "Reset background", exact: true }).count(), 0);
|
||||
assert.equal(await settings.getByRole("button", { name: "Background source", exact: true }).innerText(), "Image");
|
||||
assert.equal(await settings.getByRole("button", { name: "Choose image…", exact: true }).count(), 1);
|
||||
await page.waitForFunction(() => !window.__TEST__.settings("appearance").newTabBackground);
|
||||
assert.deepEqual([...page.errors, ...settings.errors], []);
|
||||
console.log("PASS: background image applies, survives a reload, and is removed; Reset background is disabled");
|
||||
console.log("PASS: background image applies, survives a reload, and is removed; the image source stays selected");
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Theme variants: transparency slider in eight variants, custom theme fonts, a single tooltip, and slideshow command icons.
|
||||
// Theme variants: transparency slider in eight variants, custom theme fonts, a single tooltip, plugin command icons,
|
||||
// and the native Background commands in the command palette.
|
||||
import assert from 'node:assert/strict';
|
||||
import path from 'node:path';
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
@@ -53,13 +54,21 @@ await runSmoke('appearance/themeVariants', async ({ browser }) => {
|
||||
const main = await openPage(context); await main.goto(smokeUrl);
|
||||
await main.bringToFront();
|
||||
await main.getByRole('button', { name: 'Files', exact: true }).waitFor();
|
||||
// The commands of the native Background feature (src/lib/features/catalog.ts) are in the command palette, without the feature code.
|
||||
await main.keyboard.press('Control+Shift+P');
|
||||
const palette = main.getByRole('dialog', { name: 'Commands', exact: true });
|
||||
await palette.getByRole('textbox', { name: 'Find a command', exact: true }).fill('background');
|
||||
for (const title of ['Next background image', 'Pause background']) await palette.getByRole('button').filter({ hasText: title }).first().waitFor();
|
||||
assert.equal(await main.evaluate(async () => (await import('/src/lib/features/loader.ts')).featureRequested('background')), false, 'The palette lists the commands without the feature code');
|
||||
await main.keyboard.press('Escape');
|
||||
// A third-party plugin with command icons. The Commands menu lists plugin commands only (src/lib/plugins/PluginAccessMenu.svelte).
|
||||
await main.evaluate(async () => {
|
||||
const loaded = performance.getEntriesByType('resource').map(entry => entry.name).find(name => new URL(name).pathname === '/src/lib/plugins/external.ts');
|
||||
const { pluginTools, refreshPlugins } = await import(loaded || '/src/lib/plugins/external.ts');
|
||||
await refreshPlugins();
|
||||
const invoke = window.__TAURI_INTERNALS__.invoke;
|
||||
window.__TAURI_INTERNALS__.invoke = (command, args) => command === 'plugins_snapshot' ? Promise.resolve(null) : invoke(command, args);
|
||||
const commands = [{ owner: 'runestone.background-slideshow', id: 'next-image', title: 'Next background image', kind: 'command', surface: 'commands', icon: 'skip-forward' }, { owner: 'runestone.background-slideshow', id: 'pause-resume', title: 'Pause or resume background slideshow', kind: 'command', surface: 'commands', icon: 'pause' }];
|
||||
const commands = [{ owner: 'org.test.slideshow', id: 'next-image', title: 'Next test image', kind: 'command', surface: 'commands', icon: 'skip-forward' }, { owner: 'org.test.slideshow', id: 'pause-resume', title: 'Pause or resume test slideshow', kind: 'command', surface: 'commands', icon: 'pause' }];
|
||||
pluginTools.set(commands);
|
||||
});
|
||||
const visibleTooltips = () => main.locator('[role=tooltip]:visible').count();
|
||||
@@ -77,7 +86,7 @@ await runSmoke('appearance/themeVariants', async ({ browser }) => {
|
||||
await button.click(); await main.getByRole('menu').waitFor();
|
||||
const paths = await main.locator('.rs-menu svg').evaluateAll(nodes => nodes.map(node => node.innerHTML));
|
||||
assert(paths.some(path => path.includes('M7 4v16'))); assert(paths.some(path => path.includes('m4 4 12 8')));
|
||||
await main.screenshot({ path: path.join(output, `${mode}-slideshow-command-icons.png`) }); await main.keyboard.press('Escape');
|
||||
await main.screenshot({ path: path.join(output, `${mode}-plugin-command-icons.png`) }); await main.keyboard.press('Escape');
|
||||
}
|
||||
assert.deepEqual([...page.errors, ...main.errors], []);
|
||||
console.log('PASS: eight theme variants, slider endpoints, persistence, disabled states, narrow layout, font import/export, single tooltip, and command icons.');
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Tab tooltips, translucent text selection, zero-transparency backgrounds, a stable transparency slider, and the themed install checkbox.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
import { mockTauri, outputDir, runSmoke, showSavedImage, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("appearance/tooltipsAndSelection", async ({ page }) => {
|
||||
const output = await outputDir("appearance/tooltipsAndSelection");
|
||||
@@ -35,6 +35,7 @@ await runSmoke("appearance/tooltipsAndSelection", async ({ page }) => {
|
||||
const { saveAppearance } = await import("/src/lib/theme/appearance.ts");
|
||||
saveAppearance({ theme: "default", mode, transparency: { enabled: true, amount: 0 }, newTabBackground: { image: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jM1sAAAAASUVORK5CYII=" } });
|
||||
}, mode);
|
||||
await showSavedImage(page);
|
||||
const tab = page.getByRole("tab", { name: /welcome\.md/ });
|
||||
assert.equal(await tab.getAttribute("title"), null);
|
||||
await page.mouse.move(600, 600);
|
||||
@@ -50,9 +51,10 @@ await runSmoke("appearance/tooltipsAndSelection", async ({ page }) => {
|
||||
const writer = page.getByRole("textbox", { name: "Writing editor", exact: true });
|
||||
await writer.click(); await page.keyboard.press("Control+a");
|
||||
const colors = await writer.evaluate(node => {
|
||||
const root = getComputedStyle(document.documentElement);
|
||||
const root = getComputedStyle(document.documentElement), body = getComputedStyle(document.body);
|
||||
// Background sets the image and the surfaces on the body (src/lib/plugins/backgrounds.ts).
|
||||
return { selection: root.getPropertyValue("--rs-selection"), bg: getComputedStyle(node, "::selection").backgroundColor,
|
||||
text: getComputedStyle(node).color, image: root.getPropertyValue("--rs-new-tab-image"), pluginBg: root.getPropertyValue("--rs-workarea-plugin-bg") };
|
||||
text: getComputedStyle(node).color, image: body.getPropertyValue("--rs-background-image"), pluginBg: body.getPropertyValue("--rs-workarea-plugin-bg") };
|
||||
});
|
||||
assert.match(colors.selection.trim(), /^#[0-9a-f]{6}a6$/i);
|
||||
assert.match(colors.bg, /0\.65/);
|
||||
|
||||
Reference in New Issue
Block a user