Make Git a native feature with an off switch
- Add the native feature runtime in src/lib/features/: the catalog, the switches, the first-start migration, the loader, and the feature sessions. - Add Settings → Features and the features settings section. - Add features_legacy. It reads the old plugin packages and changes nothing. - Move Git from the plugin into src/lib/features/git/, on host internals. - Remove api.git, the git contribution key, and the SDK Git types. - Add pnpm check:features. It fails when a feature module loads at start. - Update the tests, the menu inventory, the docs, and UI-055.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
//! The old plugin packages of the native features. The frontend reads them one time for each feature,
|
||||
//! when the `features` settings section has no switch for it (`src/lib/features/migration.ts`).
|
||||
//! Nothing here changes plugin files.
|
||||
|
||||
use tauri::AppHandle;
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
use crate::plugins::{legacy_packages, LegacyPackage};
|
||||
|
||||
/// The packages that native features replace. A request for another ID fails.
|
||||
pub const LEGACY_PACKAGES: [&str; 1] = ["runestone.git"];
|
||||
|
||||
fn check(ids: &[String]) -> Result<()> {
|
||||
if ids.len() > LEGACY_PACKAGES.len() {
|
||||
return Err(Error::new("Too many feature packages."));
|
||||
}
|
||||
match ids.iter().find(|id| !LEGACY_PACKAGES.contains(&id.as_str())) {
|
||||
Some(id) => Err(Error::new(format!("Unknown feature package: {id}"))),
|
||||
None => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn features_legacy(app: AppHandle, ids: Vec<String>) -> Result<Vec<LegacyPackage>> {
|
||||
check(&ids)?;
|
||||
legacy_packages(&app, ids).await
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn only_the_packages_of_native_features_are_read() {
|
||||
assert!(check(&["runestone.git".into()]).is_ok());
|
||||
assert!(check(&[]).is_ok());
|
||||
for id in ["runestone.csv-viewer", "../plugin-state", "runestone.git/..", ""] {
|
||||
assert!(check(&[id.into()]).is_err(), "{id}");
|
||||
}
|
||||
assert!(check(&["runestone.git".into(), "runestone.git".into()]).is_err());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user