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:
+76
-8
@@ -4,19 +4,87 @@ use tauri::{plugin::PluginApi, AppHandle, Runtime};
|
||||
use crate::models::*;
|
||||
|
||||
pub fn init<R: Runtime, C: DeserializeOwned>(
|
||||
app: &AppHandle<R>,
|
||||
_api: PluginApi<R, C>,
|
||||
app: &AppHandle<R>,
|
||||
_api: PluginApi<R, C>,
|
||||
) -> crate::Result<Wallpaper<R>> {
|
||||
Ok(Wallpaper(app.clone()))
|
||||
Ok(Wallpaper(app.clone()))
|
||||
}
|
||||
|
||||
/// Access to the wallpaper APIs.
|
||||
pub struct Wallpaper<R: Runtime>(AppHandle<R>);
|
||||
|
||||
impl<R: Runtime> Wallpaper<R> {
|
||||
fn demo() -> WallpaperState { WallpaperState { image_count: 3, enabled: true, shuffle: true, lock_screen_only: true, current_index: 0, image_urls: vec!["/wallpapers/alpine.png".into(), "/wallpapers/waterfall.png".into(), "/wallpapers/coast.png".into()] } }
|
||||
pub fn get_state(&self) -> crate::Result<WallpaperState> { Ok(Self::demo()) }
|
||||
pub fn select_images(&self) -> crate::Result<WallpaperState> { Ok(Self::demo()) }
|
||||
pub fn set_setting(&self, payload: SettingRequest) -> crate::Result<WallpaperState> { let mut state = Self::demo(); match payload.name.as_str() { "enabled" => state.enabled = payload.value, "shuffle" => state.shuffle = payload.value, "lockScreenOnly" => state.lock_screen_only = payload.value, _ => {} }; Ok(state) }
|
||||
pub fn next_wallpaper(&self) -> crate::Result<WallpaperState> { let mut state = Self::demo(); state.current_index = 1; Ok(state) }
|
||||
fn demo() -> WallpaperState {
|
||||
WallpaperState {
|
||||
image_count: 3,
|
||||
enabled: true,
|
||||
shuffle: true,
|
||||
lock_screen_only: true,
|
||||
current_index: 0,
|
||||
image_urls: vec![
|
||||
"/wallpapers/alpine.png".into(),
|
||||
"/wallpapers/waterfall.png".into(),
|
||||
"/wallpapers/coast.png".into(),
|
||||
],
|
||||
}
|
||||
}
|
||||
pub fn get_state(&self) -> crate::Result<WallpaperState> {
|
||||
Ok(Self::demo())
|
||||
}
|
||||
pub fn get_gallery(&self, payload: GalleryRequest) -> crate::Result<GalleryPage> {
|
||||
let urls = Self::demo().image_urls;
|
||||
let items = urls
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.skip(payload.offset)
|
||||
.take(payload.limit)
|
||||
.map(|(index, url)| GalleryImage {
|
||||
id: format!("demo-{index}"),
|
||||
url,
|
||||
selected: index == 0,
|
||||
crop_mode: "cover".into(),
|
||||
crop_zoom: 1.0,
|
||||
crop_position_x: 0.5,
|
||||
crop_position_y: 0.5,
|
||||
})
|
||||
.collect();
|
||||
Ok(GalleryPage { total: 3, items })
|
||||
}
|
||||
pub fn select_images(&self) -> crate::Result<WallpaperState> {
|
||||
Ok(Self::demo())
|
||||
}
|
||||
pub fn delete_image(&self, _payload: DeleteImageRequest) -> crate::Result<WallpaperState> {
|
||||
Ok(Self::demo())
|
||||
}
|
||||
pub fn set_image_crop(&self, payload: ImageCropRequest) -> crate::Result<GalleryImage> {
|
||||
let url = Self::demo()
|
||||
.image_urls
|
||||
.into_iter()
|
||||
.nth(payload.id.trim_start_matches("demo-").parse().unwrap_or(0))
|
||||
.unwrap_or_default();
|
||||
Ok(GalleryImage {
|
||||
id: payload.id,
|
||||
url,
|
||||
selected: false,
|
||||
crop_mode: payload.mode,
|
||||
crop_zoom: payload.zoom,
|
||||
crop_position_x: payload.position_x,
|
||||
crop_position_y: payload.position_y,
|
||||
})
|
||||
}
|
||||
pub fn set_setting(&self, payload: SettingRequest) -> crate::Result<WallpaperState> {
|
||||
let mut state = Self::demo();
|
||||
match payload.name.as_str() {
|
||||
"enabled" => state.enabled = payload.value,
|
||||
"shuffle" => state.shuffle = payload.value,
|
||||
"lockScreenOnly" => state.lock_screen_only = payload.value,
|
||||
_ => {}
|
||||
};
|
||||
Ok(state)
|
||||
}
|
||||
pub fn next_wallpaper(&self) -> crate::Result<WallpaperState> {
|
||||
let mut state = Self::demo();
|
||||
state.current_index = 1;
|
||||
Ok(state)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user