changepacks_core/
workspace.rs

1use std::path::Path;
2
3use crate::{Language, update_type::UpdateType};
4use anyhow::{Context, Result};
5use async_trait::async_trait;
6
7#[async_trait]
8pub trait Workspace: std::fmt::Debug + Send + Sync {
9    fn name(&self) -> Option<&str>;
10    fn path(&self) -> &Path;
11    fn relative_path(&self) -> &Path;
12    fn version(&self) -> Option<&str>;
13    async fn update_version(&self, update_type: UpdateType) -> Result<()>;
14    fn language(&self) -> Language;
15
16    // Default implementation for check_changed
17    fn check_changed(&mut self, path: &Path) -> Result<()> {
18        if self.is_changed() {
19            return Ok(());
20        }
21        if !path.to_string_lossy().contains(".changepacks")
22            && path.starts_with(self.path().parent().context("Parent not found")?)
23        {
24            self.set_changed(true);
25        }
26        Ok(())
27    }
28
29    fn is_changed(&self) -> bool;
30    fn set_changed(&mut self, changed: bool);
31}