Host: the media panel's commands (gallery folders, previews, the clipboard history and its watcher) are served for every app that sets AppConfig::with_media; commands::MEDIA, media_commands::gallery_file/clip_image for an app's attach command, testkit::assert_media_guards

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
CRTkafa 2026-10-01 04:02:35 +07:00
parent 419f60b5b1
commit 873f8561ca
5 changed files with 312 additions and 5 deletions

View file

@ -84,6 +84,8 @@ pub struct AppConfig {
/// files, the signed catalog): serves [`commands::STORE`]. Needs `deep_link` for the links and
/// the `net` feature for downloads.
pub store: Option<&'static crate::store::StoreConfig>,
/// The shell's media panel (gallery folders, the clipboard history): serves [`commands::MEDIA`].
pub media: bool,
}
impl AppConfig {
@ -106,9 +108,16 @@ impl AppConfig {
plugins,
home_url: None,
store: None,
media: false,
}
}
/// Serves the media panel's commands ([`commands::MEDIA`]).
pub const fn with_media(mut self) -> Self {
self.media = true;
self
}
/// Serves the store's commands ([`commands::STORE`]) with this configuration.
pub const fn with_store(mut self, store: &'static crate::store::StoreConfig) -> Self {
self.store = Some(store);
@ -1085,6 +1094,11 @@ fn store_handler() -> impl Fn(tauri::ipc::Invoke<Wry>) -> bool + Send + Sync + '
|_| false
}
/// The media panel's commands ([`commands::MEDIA`]).
fn media_handler() -> impl Fn(tauri::ipc::Invoke<Wry>) -> bool + Send + Sync + 'static {
crate::media_commands::handler()
}
type Setup = Box<dyn FnOnce(&AppHandle) -> Result<(), Box<dyn std::error::Error>> + Send>;
/// The app builder: config, site hooks, the app's own setup, then [`App::run`].
@ -1116,6 +1130,7 @@ impl App {
let App { config, hooks, setup } = self;
let host_handler = host_handler();
let store_handler = store_handler();
let media_handler = media_handler();
let builder = tauri::Builder::<Wry>::default()
// Must be first: a second launch focuses the running window instead of fighting over
// the app's data and WebView profile (and hands over its link).
@ -1195,6 +1210,7 @@ impl App {
tauri_app.manage(Host { config, hooks });
#[cfg(feature = "net")]
crate::store_commands::init(&handle, &config);
crate::media_commands::init(&handle);
// Safe mode for this run: the launch argument, or Shift held while starting (Windows).
crate::safe::set(crate::safe::at_launch(std::env::args(), host::shift_held()));
#[cfg(debug_assertions)]
@ -1207,6 +1223,8 @@ impl App {
.invoke_handler(move |invoke| {
if commands::STORE.contains(&invoke.message.command()) {
store_handler(invoke)
} else if commands::MEDIA.contains(&invoke.message.command()) {
media_handler(invoke)
} else if commands::is_host(invoke.message.command()) {
host_handler(invoke)
} else {