feat(wallpaper): extend commands with gallery, delete image, and crop
The plugin now exposes gallery retrieval, image deletion and image crop across Android, desktop and mobile. The Rust core and Android bridge are wired to handle these commands, updating state as needed. - Add gallery, delete_image, and set_image_crop commands - across Android, desktop and mobile. - Update permissions, defaults, and schema to enable new commands.
This commit is contained in:
@@ -9,6 +9,17 @@ export type WallpaperState = {
|
||||
imageUrls: string[];
|
||||
};
|
||||
|
||||
export type GalleryImage = {
|
||||
id: string;
|
||||
url: string;
|
||||
selected: boolean;
|
||||
};
|
||||
|
||||
export type GalleryPage = {
|
||||
total: number;
|
||||
items: GalleryImage[];
|
||||
};
|
||||
|
||||
const demoState: WallpaperState = {
|
||||
imageCount: 3,
|
||||
enabled: true,
|
||||
@@ -24,11 +35,34 @@ export async function getState(): Promise<WallpaperState> {
|
||||
return inTauri() ? invoke<WallpaperState>("plugin:wallpaper|get_state") : demoState;
|
||||
}
|
||||
|
||||
export async function getGallery(offset = 0, limit = 48): Promise<GalleryPage> {
|
||||
if (inTauri()) return invoke<GalleryPage>("plugin:wallpaper|get_gallery", { offset, limit });
|
||||
return {
|
||||
total: demoState.imageUrls.length,
|
||||
items: demoState.imageUrls.slice(offset, offset + limit).map((url, index) => ({
|
||||
id: `demo-${offset + index}`,
|
||||
url,
|
||||
selected: offset + index === demoState.currentIndex,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
export async function selectImages(): Promise<WallpaperState> {
|
||||
if (!inTauri()) return demoState;
|
||||
return invoke<WallpaperState>("plugin:wallpaper|select_images");
|
||||
}
|
||||
|
||||
export async function deleteImage(id: string): Promise<WallpaperState> {
|
||||
if (inTauri()) return invoke<WallpaperState>("plugin:wallpaper|delete_image", { id });
|
||||
const index = Number(id.replace("demo-", ""));
|
||||
if (Number.isInteger(index) && index >= 0 && index < demoState.imageUrls.length) {
|
||||
demoState.imageUrls.splice(index, 1);
|
||||
demoState.imageCount = demoState.imageUrls.length;
|
||||
demoState.currentIndex = Math.min(demoState.currentIndex, Math.max(0, demoState.imageCount - 1));
|
||||
}
|
||||
return { ...demoState, imageUrls: [...demoState.imageUrls] };
|
||||
}
|
||||
|
||||
export async function setSetting(name: "enabled" | "shuffle" | "lockScreenOnly", value: boolean) {
|
||||
if (!inTauri()) return { ...demoState, [name]: value };
|
||||
return invoke<WallpaperState>("plugin:wallpaper|set_setting", { name, value });
|
||||
|
||||
Reference in New Issue
Block a user