Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

feat: add PlatformRegistry struct for managing platform downloaders

Tonhob0e6fb0b1912
diff --git a/src-tauri/omniget-core/src/core/registry.rs b/src-tauri/omniget-core/src/core/registry.rs
new file mode 100644
index 00000000..c1a26216
--- /dev/null
+++ b/src-tauri/omniget-core/src/core/registry.rs
@@ -0,0 +1,32 @@
+use std::sync::Arc;
+
+use crate::platforms::traits::PlatformDownloader;
+
+pub struct PlatformRegistry {
+ platforms: Vec<Arc<dyn PlatformDownloader>>,
+}
+
+impl PlatformRegistry {
+ pub fn new() -> Self {
+ Self {
+ platforms: Vec::new(),
+ }
+ }
+
+ pub fn register(&mut self, platform: Arc<dyn PlatformDownloader>) {
+ self.platforms.push(platform);
+ }
+
+ pub fn find_platform(&self, url: &str) -> Option<Arc<dyn PlatformDownloader>> {
+ self.platforms
+ .iter()
+ .find(|p| p.can_handle(url))
+ .cloned()
+ }
+}
+
+impl Default for PlatformRegistry {
+ fn default() -> Self {
+ Self::new()
+ }
+}