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:
@@ -103,20 +103,13 @@ test('subscriber errors do not prevent frame cleanup or remaining notifications'
|
||||
assert.equal(hub.get('pm-all'), null);
|
||||
});
|
||||
|
||||
test('disable removes frames and subscriptions before cleanup and rejects pending file results', async () => {
|
||||
test('disable removes frames and subscriptions before cleanup', async () => {
|
||||
let api!: PluginApi;
|
||||
let finishRead!: (value: Uint8Array) => void;
|
||||
let finishList!: (value: { name: string }[]) => void;
|
||||
let finishPicker!: (value: string | null) => void;
|
||||
const session = new ExternalSession('org.test.backgrounds', {
|
||||
workspace: { list: async () => [], read: async () => '', write: async () => {} },
|
||||
settings: { read: async () => null, write: async () => {} },
|
||||
assets: { read: async () => new Uint8Array() },
|
||||
backgrounds: {
|
||||
chooseFolder: () => new Promise(resolve => { finishPicker = resolve; }),
|
||||
list: () => new Promise(resolve => { finishList = resolve; }),
|
||||
read: () => new Promise(resolve => { finishRead = resolve; }),
|
||||
},
|
||||
backgrounds: true,
|
||||
}, () => {}, () => {});
|
||||
let notifications = 0;
|
||||
await session.start({ activate(value) {
|
||||
@@ -130,26 +123,49 @@ test('disable removes frames and subscriptions before cleanup and rejects pendin
|
||||
assert.throws(() => api.backgrounds!.get('app'), /disabled/);
|
||||
});
|
||||
} });
|
||||
const pending = [api.backgrounds!.read('folder', 'file.png'), api.backgrounds!.list('folder'), api.backgrounds!.chooseFolder()];
|
||||
const rejected = pending.map(request => assert.rejects(request, /disabled/));
|
||||
// The deprecated folder methods are gone. Plugins use the folder grants of `api.files`.
|
||||
for (const name of ['chooseFolder', 'defaultFolder', 'list', 'read', 'readImageSettings', 'writeImageSettings']) assert.equal(name in api.backgrounds!, false, name);
|
||||
await session.stop();
|
||||
finishRead(new Uint8Array([1])); finishList([{ name: 'file.png' }]); finishPicker('folder');
|
||||
await Promise.all(rejected);
|
||||
assert.equal(notifications, 2);
|
||||
assert.throws(() => api.backgrounds!.set('app', frame), /disabled/);
|
||||
assert.throws(() => api.backgrounds!.read('folder', 'file.png'), /disabled/);
|
||||
assert.throws(() => api.backgrounds!.subscribe(() => {}), /disabled/);
|
||||
assert.equal(backgroundHub.get('app'), null);
|
||||
});
|
||||
|
||||
|
||||
test('background commands are allowed in main and settings windows', () => {
|
||||
test('the Background commands are allowed in the windows that use them, and the old plugin commands are gone', () => {
|
||||
const build = readFileSync(new URL('../../../src-tauri/build.rs', import.meta.url), 'utf8');
|
||||
for (const scope of ['default', 'settings']) {
|
||||
const all = ['background_choose_folder', 'background_folder', 'background_clear_folder', 'background_list', 'background_read', 'background_read_sidecar', 'background_write_sidecar', 'background_migrate'];
|
||||
const scopes: Record<string, string[]> = { default: all, settings: all, browser: ['background_folder', 'background_list', 'background_read', 'background_read_sidecar'] };
|
||||
for (const [scope, commands] of Object.entries(scopes)) {
|
||||
const capability = JSON.parse(readFileSync(new URL(`../../../src-tauri/capabilities/${scope}.json`, import.meta.url), 'utf8'));
|
||||
for (const command of ['backgrounds_choose_folder', 'backgrounds_default_folder', 'backgrounds_list', 'backgrounds_read', 'backgrounds_read_image_settings', 'backgrounds_write_image_settings']) {
|
||||
for (const command of all) {
|
||||
assert(build.includes(`"${command}"`), `${command} needs a generated desktop permission`);
|
||||
assert(capability.permissions.includes(`allow-${command.replaceAll('_', '-')}`), `${scope} must allow ${command}`);
|
||||
assert.equal(capability.permissions.includes(`allow-${command.replaceAll('_', '-')}`), commands.includes(command), `${scope} and ${command}`);
|
||||
}
|
||||
assert.equal(capability.permissions.some((permission: string) => permission.startsWith('allow-backgrounds-')), false, `${scope} has no old plugin command`);
|
||||
}
|
||||
assert.equal(/"backgrounds_/.test(build), false);
|
||||
});
|
||||
|
||||
test('a new app frame changes only the custom properties with a new value', () => {
|
||||
const writes: string[] = [];
|
||||
const properties = new Map<string, string>();
|
||||
const style = { getPropertyValue: (key: string) => properties.get(key) ?? '', getPropertyPriority: () => '',
|
||||
setProperty: (key: string, value: string) => { writes.push(key); properties.set(key, value); }, removeProperty: (key: string) => { properties.delete(key); } };
|
||||
const hub = new BackgroundHub(() => ({ style }) as unknown as HTMLElement), owner = Symbol();
|
||||
hub.set(owner, 'app', frame);
|
||||
assert.equal(writes.length, 19);
|
||||
writes.length = 0;
|
||||
hub.set(owner, 'app', { ...frame, url: 'blob:http://localhost/second' });
|
||||
assert.deepEqual(writes, ['--rs-background-image']);
|
||||
writes.length = 0;
|
||||
hub.set(owner, 'app', { ...frame, url: 'blob:http://localhost/second' });
|
||||
assert.deepEqual(writes, [], 'The same frame writes nothing');
|
||||
hub.removeOwner(owner);
|
||||
assert.equal(properties.size, 0);
|
||||
writes.length = 0;
|
||||
hub.set(owner, 'app', frame);
|
||||
assert.equal(writes.length, 19, 'After a removal, the next frame writes every property again');
|
||||
hub.removeOwner(owner);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user