Something went wrong. Try again.
Some shell. slowshell.bushyice.com
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045mod config;mod events;mod host;mod service;mod services;mod state;mod store;
pub use service::start as start_service;
mod compositor;mod desktop;mod payload;mod quicksettings;mod render;mod renderable;
#[cfg(feature = "spotlight")]mod spotlight;
#[cfg(feature = "panels")]mod component;
use std::{ collections::{BTreeSet, HashMap}, path::{Path, PathBuf}, sync::{Mutex, OnceLock},};
use abi_stable::library::{RawLibrary, lib_header_from_raw_library};use slowshell_config::{Config, find_node, node_children, node_name};use slowshell_core::Store;use slowshell_desktop::DesktopItem;use slowshell_plugin_abi::{ ComponentFactoryBox, CompositorFactoryBox, Context, DesktopItemFactoryBox, PluginMod_Ref, RenderableFactoryBox,};use slowshell_registry::{GlobalRegistry, ResourceRegistration};
use crate::state::{Pending, PluginScope, contribute, plugin_ids, plugin_infos, plugin_log};
pub use crate::config::PluginConfigs;pub use crate::state::{PluginContributions, PluginInfo, set_silent};
#[derive(Default, Clone)]pub struct PluginSelection { pub enabled: Vec<String>, pub disabled: Vec<String>,}
impl PluginSelection { pub fn from_path(path: Option<&Path>) -> Self { let Some(path) = path else { return Self::default(); }; let Ok(content) = std::fs::read_to_string(path) else { return Self::default(); }; let Ok(document) = content.parse::<kdl::KdlDocument>() else { return Self::default(); }; let Some(node) = find_node(document.nodes(), "plugins") else { return Self::default(); };
let mut selection = Self::default(); for child in node_children(node) { let values: Vec<String> = child .entries() .iter() .filter_map(|entry| entry.value().as_string().map(str::to_owned)) .collect();
match node_name(child) { "enabled" => selection.enabled.extend(values), "disabled" => selection.disabled.extend(values), _ => {} } } selection }
fn allows(&self, id: &str) -> bool { if self.disabled.iter().any(|disabled| disabled == id) { return false; } if self.enabled.is_empty() { return true; } self.enabled.iter().any(|enabled| enabled == id) }}
pub struct PluginHost;
impl PluginHost { pub fn load(registry: &mut GlobalRegistry, selection: &PluginSelection) -> Self { let candidates = discover(selection); let metas: Vec<CandidateMeta> = candidates .iter() .map(|candidate| candidate.meta.clone()) .collect(); let plan = resolve(&metas);
for (index, report) in &plan.skipped { let id = &candidates[*index].meta.id; state::record_plugin_error(id, report.code, &report.reason); }
for index in &plan.order { let candidate = &candidates[*index]; register_one(candidate, registry); plugin_log(format_args!("[plugin] loaded {}", candidate.path.display())); }
let has_payloads = payload::payloads() .lock() .map(|payloads| !payloads.is_empty()) .unwrap_or(false); if has_payloads { registry.include_in("app", ResourceRegistration::Item(plugin_dispatcher_item)); }
let has_renderables = renderable_entries() .lock() .map(|renderables| !renderables.is_empty()) .unwrap_or(false); if has_renderables { registry.include_in( "app", ResourceRegistration::CustomConfig(register_plugin_renderables), ); }
#[cfg(feature = "spotlight")] { let has_spotlights = spotlight::spotlights() .lock() .map(|spotlights| !spotlights.is_empty()) .unwrap_or(false); if has_spotlights { registry.include_in( "app", ResourceRegistration::CustomConfig(register_plugin_spotlights), ); } }
let has_desktop_items = desktop_entries() .lock() .map(|items| !items.is_empty()) .unwrap_or(false); if has_desktop_items { registry.include_in("app", ResourceRegistration::Item(plugin_desktop_items)); }
let has_desktop_deployers = desktop_deployer_entries() .lock() .map(|items| !items.is_empty()) .unwrap_or(false); if has_desktop_deployers { registry.include_in( "app", ResourceRegistration::Deployable(plugin_desktop_deployers), ); }
let has_quick_settings = quicksettings::providers() .lock() .map(|providers| !providers.is_empty()) .unwrap_or(false); if has_quick_settings { registry.include_in("app", ResourceRegistration::Custom(quicksettings::install)); }
let has_plugins = plugin_ids() .lock() .map(|ids| !ids.is_empty()) .unwrap_or(false); if has_plugins { registry.include_in( "config", ResourceRegistration::Unknown(Box::new(slowshell_config::ConfigParser { type_id: std::any::TypeId::of::<PluginConfigs>(), de: config::parse_plugin_configs, })), ); registry.include_in( "app", ResourceRegistration::CustomConfig(service::start_autostart), ); }
let payload_count = payload::payloads().lock().map(|p| p.len()).unwrap_or(0); let renderable_count = renderable_entries().lock().map(|r| r.len()).unwrap_or(0); let desktop_count = desktop_entries().lock().map(|d| d.len()).unwrap_or(0); let deployer_count = desktop_deployer_entries() .lock() .map(|d| d.len()) .unwrap_or(0); if payload_count + renderable_count + desktop_count + deployer_count > 0 { plugin_log(format_args!( "[plugin] registered {payload_count} payload(s), {renderable_count} renderable(s), {desktop_count} desktop item(s), {deployer_count} desktop deployer(s)" )); }
Self }}
pub fn registered_surface_counts() -> (usize, usize, usize) { let payloads = payload::payloads().lock().map(|p| p.len()).unwrap_or(0); let renderables = renderable_entries().lock().map(|r| r.len()).unwrap_or(0); let desktop_items = desktop_entries().lock().map(|d| d.len()).unwrap_or(0); (payloads, renderables, desktop_items)}
pub fn registered_renderable_names() -> Vec<String> { renderable_names()}
pub fn renderable_names() -> Vec<String> { renderable_entries() .lock() .map(|entries| entries.iter().map(|entry| entry.name.to_string()).collect()) .unwrap_or_default()}
pub fn spotlight_names() -> Vec<String> { #[cfg(feature = "spotlight")] { spotlight::spotlights() .lock() .map(|entries| entries.iter().map(|entry| entry.name.clone()).collect()) .unwrap_or_default() }
#[cfg(not(feature = "spotlight"))] { Vec::new() }}
pub fn loaded_plugins() -> Vec<PluginInfo> { plugin_infos().lock().unwrap().clone()}
pub fn last_plugin_error(plugin_id: &str) -> Option<(u32, String)> { crate::state::plugin_errors() .lock() .unwrap() .get(plugin_id) .cloned()}
pub fn contributions(plugin_id: &str) -> PluginContributions { crate::state::plugin_contributions() .lock() .unwrap() .get(plugin_id) .cloned() .unwrap_or_default()}
#[derive(Clone, Debug)]struct Requirement { id: String, req: semver::VersionReq, raw: String,}
#[derive(Clone, Debug)]struct CandidateMeta { id: String, version: String, parsed_version: Option<semver::Version>, requires: Vec<Requirement>,}
struct Candidate { path: PathBuf, root: PluginMod_Ref, meta: CandidateMeta,}
#[derive(Debug)]struct SkipReport { code: u32, reason: String,}
struct PluginPlan { order: Vec<usize>, skipped: Vec<(usize, SkipReport)>,}
const ERR_DEPENDENCY_MISSING: u32 = 0x1001;const ERR_DEPENDENCY_VERSION: u32 = 0x1002;const ERR_DEPENDENCY_CYCLE: u32 = 0x1003;
fn discover(selection: &PluginSelection) -> Vec<Candidate> { let mut by_id: HashMap<String, Candidate> = HashMap::new();
for dir in plugin_dirs() { let Ok(entries) = std::fs::read_dir(&dir) else { continue; };
let mut paths: Vec<PathBuf> = entries.flatten().map(|entry| entry.path()).collect(); paths.sort();
for path in paths { if path.extension().and_then(|ext| ext.to_str()) != Some("so") { continue; }
match read_candidate(&path) { Ok(candidate) if !selection.allows(&candidate.meta.id) => { plugin_log(format_args!("[plugin] {} disabled", candidate.meta.id)); } Ok(candidate) => { if let Some(existing) = by_id.get(&candidate.meta.id) { plugin_log(format_args!( "[plugin] {} from {} shadowed by {}", candidate.meta.id, path.display(), existing.path.display() )); } else { by_id.insert(candidate.meta.id.clone(), candidate); } } Err(e) => plugin_log(format_args!( "[plugin] failed to load {}: {e}", path.display() )), } } }
let mut candidates: Vec<Candidate> = by_id.into_values().collect(); candidates.sort_by(|a, b| a.meta.id.cmp(&b.meta.id)); candidates}
fn read_candidate(path: &Path) -> miette::Result<Candidate> { let raw_library = RawLibrary::load_at(path).map_err(|e| miette::miette!("{e}"))?; let header = unsafe { lib_header_from_raw_library(&raw_library) }.map_err(|e| miette::miette!("{e}"))?; header.ensure_layout::<PluginMod_Ref>().map_err(|e| { miette::miette!("{e} (the plugin may need to be rebuilt against the current slowshell ABI)") })?;
let library = unsafe { header.init_root_module_with_unchecked_layout::<PluginMod_Ref>() } .map_err(|e| miette::miette!("{e}"))?;
std::mem::forget(raw_library);
let id = library.id().to_string(); let version = library.version().to_string(); let parsed_version = semver::Version::parse(&version).ok();
let mut requires = Vec::new(); for dependency in library.requires().iter() { let dep_id = dependency.id.to_string(); let raw = dependency.version_req.to_string(); let req = semver::VersionReq::parse(&raw).map_err(|e| { miette::miette!("invalid version requirement `{raw}` for dependency `{dep_id}`: {e}") })?; requires.push(Requirement { id: dep_id, req, raw, }); }
Ok(Candidate { path: path.to_path_buf(), root: library, meta: CandidateMeta { id, version, parsed_version, requires, }, })}
fn resolve(metas: &[CandidateMeta]) -> PluginPlan { let count = metas.len(); let mut by_id: HashMap<&str, usize> = HashMap::with_capacity(count); for (index, meta) in metas.iter().enumerate() { by_id.insert(meta.id.as_str(), index); }
let mut skipped: Vec<Option<SkipReport>> = (0..count).map(|_| None).collect();
for (index, meta) in metas.iter().enumerate() { for dependency in &meta.requires { let Some(&dep_index) = by_id.get(dependency.id.as_str()) else { set_skip( &mut skipped, index, ERR_DEPENDENCY_MISSING, format!( "requires `{}` {}, which is not installed or is disabled", dependency.id, dependency.raw ), ); break; };
if dep_index == index { set_skip( &mut skipped, index, ERR_DEPENDENCY_MISSING, format!("depends on itself (`{}`)", dependency.id), ); break; }
match metas[dep_index].parsed_version.as_ref() { Some(version) if dependency.req.matches(version) => {} Some(version) => { set_skip( &mut skipped, index, ERR_DEPENDENCY_VERSION, format!( "requires `{}` {}, but {} is installed", dependency.id, dependency.raw, version ), ); break; } None => { set_skip( &mut skipped, index, ERR_DEPENDENCY_VERSION, format!( "requires `{}` {}, but `{}` has a non-semver version `{}`", dependency.id, dependency.raw, dependency.id, metas[dep_index].version ), ); break; } } } }
loop { let mut changed = false; for index in 0..count { if skipped[index].is_some() { continue; }
let blocked = metas[index].requires.iter().find_map(|dependency| { let dep_index = *by_id.get(dependency.id.as_str())?; skipped[dep_index].as_ref().map(|_| dependency) });
if let Some(dependency) = blocked { skipped[index] = Some(SkipReport { code: ERR_DEPENDENCY_MISSING, reason: format!( "requires `{}` {}, which was skipped", dependency.id, dependency.raw ), }); changed = true; } }
if !changed { break; } }
let mut indegree = vec![0usize; count]; let mut dependents: Vec<Vec<usize>> = vec![Vec::new(); count]; for (index, meta) in metas.iter().enumerate() { if skipped[index].is_some() { continue; }
for dependency in &meta.requires { if let Some(&dep_index) = by_id.get(dependency.id.as_str()) && skipped[dep_index].is_none() { indegree[index] += 1; dependents[dep_index].push(index); } } }
let mut ready: BTreeSet<usize> = (0..count) .filter(|&index| skipped[index].is_none() && indegree[index] == 0) .collect();
let mut order = Vec::with_capacity(count); let mut scheduled = vec![false; count]; while let Some(index) = ready.pop_first() { scheduled[index] = true; order.push(index); for &dependent in &dependents[index] { indegree[dependent] -= 1; if indegree[dependent] == 0 { ready.insert(dependent); } } }
let cycle: Vec<usize> = (0..count) .filter(|&index| skipped[index].is_none() && !scheduled[index]) .collect(); if !cycle.is_empty() { let reason = format!( "dependency cycle involving: {}", cycle .iter() .map(|&index| metas[index].id.as_str()) .collect::<Vec<_>>() .join(", ") ); for &index in &cycle { skipped[index] = Some(SkipReport { code: ERR_DEPENDENCY_CYCLE, reason: reason.clone(), }); } }
PluginPlan { order, skipped: skipped .into_iter() .enumerate() .filter_map(|(index, report)| report.map(|report| (index, report))) .collect(), }}
fn set_skip(skipped: &mut [Option<SkipReport>], index: usize, code: u32, reason: String) { if skipped[index].is_none() { skipped[index] = Some(SkipReport { code, reason }); }}
fn register_one(candidate: &Candidate, registry: &mut GlobalRegistry) { let id = &candidate.meta.id;
plugin_ids().lock().unwrap().push(id.clone()); plugin_infos().lock().unwrap().push(PluginInfo { id: id.clone(), version: candidate.meta.version.clone(), requires: candidate .meta .requires .iter() .map(|dependency| format!("{} {}", dependency.id, dependency.raw)) .collect(), path: candidate.path.clone(), });
state::PENDING.with(|pending| pending.borrow_mut().clear());
{ let _scope = PluginScope::enter(id); (candidate.root.register())(host::host()); }
drain_pending(registry, id);}
fn plugin_dirs() -> Vec<PathBuf> { let mut dirs = Vec::new();
if let Ok(paths) = std::env::var("SLOWSHELL_PLUGIN_PATH") { dirs.extend( paths .split(':') .filter(|p| !p.is_empty()) .map(PathBuf::from), ); }
let data_home = std::env::var_os("XDG_DATA_HOME") .map(PathBuf::from) .or_else(|| std::env::var_os("HOME").map(|home| PathBuf::from(home).join(".local/share"))); if let Some(data_home) = data_home { dirs.push(data_home.join("slowshell/plugins")); }
let data_dirs = std::env::var("XDG_DATA_DIRS").unwrap_or_else(|_| "/usr/local/share:/usr/share".into()); dirs.extend( data_dirs .split(':') .filter(|d| !d.is_empty()) .map(|d| PathBuf::from(d).join("slowshell/plugins")), );
if cfg!(debug_assertions) { dirs.push(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../target/debug")); }
dirs}
fn drain_pending(registry: &mut GlobalRegistry, plugin_id: &str) { let pending = state::PENDING.with(|pending| std::mem::take(&mut *pending.borrow_mut()));
for item in pending { match item { Pending::Component { name, factory } => { register_component(registry, plugin_id, name, factory); } Pending::Compositor { name, factory } => { register_compositor(registry, plugin_id, name, factory); } Pending::Payload { command, factory } => { let ctx = Context::new(host::host()); let inner = factory.create(&ctx); payload::payloads() .lock() .unwrap() .push(payload::PayloadEntry { command: command.clone().into(), plugin_id: plugin_id.to_owned(), inner, }); contribute(plugin_id, |contributions| { contributions.payloads.push(command.clone()); }); registry.include_in( "payload", ResourceRegistration::Unknown(Box::new(slowshell_core::types::PayloadBuilder { commands: Box::leak( vec![Box::leak(command.into_boxed_str()) as &'static str].into_boxed_slice(), ), build: payload::plugin_payload_build, })), ); } Pending::Renderable { name, factory } => { renderable_entries().lock().unwrap().push(RenderableEntry { name: name.clone().into(), plugin_id: plugin_id.to_owned(), factory, }); contribute(plugin_id, |contributions| { contributions.renderables.push(name); }); } Pending::DesktopItem { name, factory } => { desktop_entries().lock().unwrap().push(DesktopEntry { name: name.clone().into(), plugin_id: plugin_id.to_owned(), factory, }); contribute(plugin_id, |contributions| { contributions.desktop_items.push(name); }); } Pending::DesktopItemDeployer { name, factory } => { desktop_deployer_entries() .lock() .unwrap() .push(DesktopDeployerEntry { name: name.clone().into(), plugin_id: plugin_id.to_owned(), factory, }); contribute(plugin_id, |contributions| { contributions.desktop_item_deployers.push(name); }); } Pending::PayloadParser { commands, parser } => { crate::payload::register_parser(plugin_id.to_owned(), commands.clone(), parser); contribute(plugin_id, |contributions| { contributions.payload_parsers.push(commands.join(",")); });
let commands: Vec<&'static str> = commands .iter() .map(|command| &*Box::leak(command.clone().into_boxed_str())) .collect(); registry.include_in( "payload", ResourceRegistration::Unknown(Box::new(slowshell_core::types::PayloadBuilder { commands: Box::leak(commands.into_boxed_slice()), build: payload::plugin_payload_build, })), ); } Pending::ConfigParser { name, parser } => { contribute(plugin_id, |contributions| { contributions.config_parsers.push(name.clone()); }); crate::state::plugin_config_parsers().lock().unwrap().push(( plugin_id.to_owned(), name, parser, )); } Pending::Service { name, factory, autostart, } => { service::register(plugin_id, name, factory, autostart); } Pending::ForegroundService { name, factory } => { contribute(plugin_id, |contributions| { contributions.foreground_services.push(name.clone()); }); registry.include_in( "foreground_services", ResourceRegistration::Unknown(Box::new(PluginForegroundServiceRegistration { name, plugin_id: plugin_id.to_owned(), factory: std::sync::Arc::new(factory), })), ); } Pending::Spotlight { name, factory } => { #[cfg(feature = "spotlight")] { let ctx = Context::new(host::host()); let inner = factory.create(&ctx); spotlight::spotlights() .lock() .unwrap() .push(spotlight::SpotlightEntry { name: name.clone(), plugin_id: plugin_id.to_owned(), inner, }); } #[cfg(not(feature = "spotlight"))] let _ = factory; contribute(plugin_id, |contributions| { contributions.spotlights.push(name); }); } Pending::QuickSettings { name, factory } => { let ctx = Context::new(host::host()); let inner = factory.create(&ctx); quicksettings::providers().lock().unwrap().push( quicksettings::PluginQuickSettingsProvider::new(name, plugin_id.to_owned(), inner), ); } Pending::Command { name, title, description, } => { slowshell_core::commands::register(slowshell_core::commands::CommandEntry { name: name.clone().into(), title, description, icon: None, action: slowshell_core::listeners::ListenerAction::Named(name.clone().into()), });
contribute(plugin_id, |contributions| { contributions.commands.push(name); }); } } }}
#[cfg(feature = "panels")]fn register_component( registry: &mut GlobalRegistry, plugin_id: &str, name: String, factory: ComponentFactoryBox,) { use slowshell_components::{Component, ComponentRegistration};
let owner = plugin_id.to_owned(); let registration = ComponentRegistration::new( name.clone(), Box::new(move || { let ctx = Context::new(host::host()); let _scope = PluginScope::enter(&owner); let inner = factory.create(&ctx); Box::new(component::PluginComponent::new( owner.clone(), inner, factory.hoverable(), )) as Box<dyn Component> }), );
contribute(plugin_id, |contributions| { contributions.components.push(name); });
registry.include_in( "components", ResourceRegistration::Unknown(Box::new(registration)), );}
#[cfg(not(feature = "panels"))]fn register_component( _registry: &mut GlobalRegistry, _plugin_id: &str, _name: String, _factory: ComponentFactoryBox,) {}
fn register_compositor( registry: &mut GlobalRegistry, plugin_id: &str, name: String, factory: CompositorFactoryBox,) { use slowshell_compositor::{Compositor, CompositorRegistration};
let owner = plugin_id.to_owned(); let registration = CompositorRegistration::new( name.clone(), Box::new(move || { let ctx = Context::new(host::host()); let _scope = PluginScope::enter(&owner); let inner = factory.create(&ctx); Box::new(compositor::PluginCompositor::new(owner.clone(), inner)) as Box<dyn Compositor> }), );
contribute(plugin_id, |contributions| { contributions.compositors.push(name); });
registry.include_in( "compositor", ResourceRegistration::Unknown(Box::new(registration)), );}
#[cfg_attr(not(feature = "panels"), allow(dead_code))]struct RenderableEntry { name: slowshell_core::types::Ustr, plugin_id: String, factory: RenderableFactoryBox,}
fn renderable_entries() -> &'static Mutex<Vec<RenderableEntry>> { static ENTRIES: OnceLock<Mutex<Vec<RenderableEntry>>> = OnceLock::new(); ENTRIES.get_or_init(|| Mutex::new(Vec::new()))}
#[cfg(feature = "panels")]fn register_plugin_renderables(_config: &Config, store: &mut Store) { use slowshell_plugin_abi::Context; use slowshell_widgets::Renderables;
let Some(table) = store.borrow_mut::<Renderables>() else { return; };
let entries = renderable_entries().lock().unwrap(); for entry in entries.iter() { let ctx = Context::new(host::host()); let _scope = PluginScope::enter(&entry.plugin_id); let inner = entry.factory.create(&ctx); table.insert( entry.name.clone(), Box::new(renderable::PluginRenderable::new( entry.plugin_id.clone(), inner, )), ); }}
#[cfg(not(feature = "panels"))]fn register_plugin_renderables(_config: &Config, _store: &mut Store) {}
struct DesktopEntry { name: slowshell_core::types::Ustr, plugin_id: String, factory: DesktopItemFactoryBox,}
fn desktop_entries() -> &'static Mutex<Vec<DesktopEntry>> { static ENTRIES: OnceLock<Mutex<Vec<DesktopEntry>>> = OnceLock::new(); ENTRIES.get_or_init(|| Mutex::new(Vec::new()))}
fn plugin_desktop_items( _config: &Config, _store: &Store,) -> miette::Result<Vec<Box<dyn DesktopItem + Send>>> { let entries = desktop_entries().lock().unwrap(); let items = entries .iter() .map(|entry| { let ctx = Context::new(host::host()); let _scope = PluginScope::enter(&entry.plugin_id); let inner = entry.factory.create(&ctx); Box::new(desktop::PluginDesktopItem::new( entry.name.clone(), entry.plugin_id.clone(), inner, )) as Box<dyn DesktopItem + Send> }) .collect(); Ok(items)}
struct DesktopDeployerEntry { name: slowshell_core::types::Ustr, plugin_id: String, factory: slowshell_plugin_abi::DeployableDesktopItemFactoryBox,}
fn desktop_deployer_entries() -> &'static Mutex<Vec<DesktopDeployerEntry>> { static ENTRIES: OnceLock<Mutex<Vec<DesktopDeployerEntry>>> = OnceLock::new(); ENTRIES.get_or_init(|| Mutex::new(Vec::new()))}
fn plugin_desktop_deployers( _config: &Config, _store: &Store,) -> miette::Result<Vec<Box<dyn slowshell_desktop::DeployableDesktopItem>>> { let entries = desktop_deployer_entries().lock().unwrap(); let deployers = entries .iter() .map(|entry| { let ctx = Context::new(host::host()); let _scope = PluginScope::enter(&entry.plugin_id); let inner = entry.factory.create(&ctx); Box::new(desktop::PluginDeployable::new( entry.name.clone(), entry.plugin_id.clone(), inner, )) as Box<dyn slowshell_desktop::DeployableDesktopItem> }) .collect(); Ok(deployers)}
#[cfg(feature = "spotlight")]fn register_plugin_spotlights(_config: &Config, store: &mut Store) { use slowshell_spotlight::{SpotlightKind, SpotlightMode, SpotlightModes};
let Some(modes) = store.borrow_mut::<SpotlightModes>() else { return; };
let entries = spotlight::spotlights().lock().unwrap(); for (index, entry) in entries.iter().enumerate() { let display = spotlight::display_styles(entry.inner.display_styles()); let allows_triggers = entry.inner.allows_triggers();
modes.register_mode( entry.name.clone(), SpotlightMode { kind: SpotlightKind::Generate(Box::new(move |query, store| { spotlight::generate(index, query, store) })), display, }, allows_triggers, );
modes.register_trigger(entry.name.clone(), move |query: &str| { spotlight::trigger_check(index, query) }); }}
#[cfg(not(feature = "spotlight"))]#[allow(dead_code)]fn register_plugin_spotlights(_config: &Config, _store: &mut Store) {}
fn plugin_dispatcher_item( _config: &Config, _store: &Store,) -> miette::Result<Vec<Box<dyn DesktopItem + Send>>> { Ok(vec![Box::new(payload::PluginDispatcher)])}
pub struct PluginForegroundService { pub name: String, pub plugin_id: String, pub inner: std::sync::Mutex<slowshell_plugin_abi::ForegroundServiceObjectBox>,}
impl PluginForegroundService { pub fn new( name: String, plugin_id: String, inner: slowshell_plugin_abi::ForegroundServiceObjectBox, ) -> Self { Self { name, plugin_id, inner: std::sync::Mutex::new(inner), } }}
impl slowshell_services::ForegroundService for PluginForegroundService { fn update( &mut self, _store: &mut slowshell_core::Store, action: &slowshell_core::listeners::ListenerAction, ) -> bool { let _scope = crate::state::PluginScope::enter(&self.plugin_id); let event = crate::events::event_from_action(action); let ctx = slowshell_plugin_abi::Context::new(crate::host::host()); self.inner.lock().unwrap().update(&ctx, &event) }}
#[derive(Clone)]pub struct PluginForegroundServiceRegistration { pub name: String, pub plugin_id: String, pub factory: std::sync::Arc<slowshell_plugin_abi::ForegroundServiceFactoryBox>,}
impl PluginForegroundServiceRegistration { pub fn create_service(&self) -> Box<dyn slowshell_services::ForegroundService> { let _scope = crate::state::PluginScope::enter(&self.plugin_id); let ctx = slowshell_plugin_abi::Context::new(crate::host::host()); let inner = self.factory.create(&ctx); Box::new(PluginForegroundService::new( self.name.clone(), self.plugin_id.clone(), inner, )) }}