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.

add PlatformRegistry struct for managing platform downloaders

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