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:
@@ -17,12 +17,25 @@ import java.util.concurrent.Executors
|
||||
@InvokeArg
|
||||
class SettingArgs { lateinit var name: String; var value: Boolean = false }
|
||||
|
||||
@InvokeArg
|
||||
class GalleryArgs { var offset: Int = 0; var limit: Int = 48 }
|
||||
|
||||
@InvokeArg
|
||||
class DeleteImageArgs { lateinit var id: String }
|
||||
|
||||
@TauriPlugin
|
||||
class WallpaperPlugin(private val activity: Activity) : Plugin(activity) {
|
||||
private val io = Executors.newSingleThreadExecutor()
|
||||
|
||||
@Command fun getState(invoke: Invoke) = io.execute { invoke.resolve(WallpaperStore.state(activity)) }
|
||||
|
||||
@Command fun getGallery(invoke: Invoke) = io.execute {
|
||||
try {
|
||||
val args = invoke.parseArgs(GalleryArgs::class.java)
|
||||
invoke.resolve(WallpaperStore.gallery(activity, args.offset, args.limit))
|
||||
} catch (error: Exception) { invoke.reject(error.message ?: "Galerie konnte nicht geladen werden") }
|
||||
}
|
||||
|
||||
@Command fun selectImages(invoke: Invoke) {
|
||||
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
@@ -33,6 +46,14 @@ class WallpaperPlugin(private val activity: Activity) : Plugin(activity) {
|
||||
startActivityForResult(invoke, intent, "selectedImages")
|
||||
}
|
||||
|
||||
@Command fun deleteImage(invoke: Invoke) = io.execute {
|
||||
try {
|
||||
val args = invoke.parseArgs(DeleteImageArgs::class.java)
|
||||
if (!WallpaperStore.delete(activity, args.id)) throw IllegalArgumentException("Bild wurde nicht gefunden")
|
||||
invoke.resolve(WallpaperStore.state(activity))
|
||||
} catch (error: Exception) { invoke.reject(error.message ?: "Bild konnte nicht gelöscht werden") }
|
||||
}
|
||||
|
||||
@ActivityCallback
|
||||
fun selectedImages(invoke: Invoke, result: ActivityResult) {
|
||||
if (result.resultCode != Activity.RESULT_OK) { invoke.reject("Bildauswahl abgebrochen"); return }
|
||||
|
||||
Reference in New Issue
Block a user