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:
@@ -17,6 +17,7 @@ fn main() {
|
||||
"folders_read",
|
||||
"folders_read_sidecar",
|
||||
"folders_write_sidecar",
|
||||
"features_legacy",
|
||||
"spelling_suggestions",
|
||||
"spelling_menu_install",
|
||||
"spelling_menu_select",
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
"allow-settings-read",
|
||||
"allow-settings-write",
|
||||
"allow-settings-migrate",
|
||||
"allow-features-legacy",
|
||||
"allow-tab-transfer-offer",
|
||||
"allow-tab-transfer-take",
|
||||
"allow-tab-transfer-finish",
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"allow-window-snap-layouts",
|
||||
"allow-settings-write",
|
||||
"allow-settings-migrate",
|
||||
"allow-features-legacy",
|
||||
"core:default",
|
||||
"core:window:allow-close",
|
||||
"core:window:allow-minimize",
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
# Automatically generated - DO NOT EDIT!
|
||||
|
||||
[[permission]]
|
||||
identifier = "allow-features-legacy"
|
||||
description = "Enables the features_legacy command without any pre-configured scope."
|
||||
commands.allow = ["features_legacy"]
|
||||
|
||||
[[permission]]
|
||||
identifier = "deny-features-legacy"
|
||||
description = "Denies the features_legacy command without any pre-configured scope."
|
||||
commands.deny = ["features_legacy"]
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ mod spelling;
|
||||
mod theme;
|
||||
mod backgrounds;
|
||||
mod folders;
|
||||
mod features;
|
||||
mod window_frame;
|
||||
|
||||
use pty::PtyState;
|
||||
@@ -51,6 +52,7 @@ pub fn run() {
|
||||
folders::folders_read,
|
||||
folders::folders_read_sidecar,
|
||||
folders::folders_write_sidecar,
|
||||
features::features_legacy,
|
||||
theme::theme_export,
|
||||
spelling::spelling_menu_install,
|
||||
spelling::spelling_suggestions,
|
||||
|
||||
@@ -1466,6 +1466,39 @@ pub async fn plugins_reveal(
|
||||
app.opener().reveal_item_in_dir(path).map_err(Error::from)
|
||||
}
|
||||
}
|
||||
/// What the feature migration (`features.rs`) reads about an old package. Nothing changes.
|
||||
#[derive(Serialize, Debug, PartialEq)]
|
||||
pub struct LegacyPackage {
|
||||
pub id: String,
|
||||
pub installed: bool,
|
||||
pub enabled: bool,
|
||||
/// The kept plugin settings. Missing, damaged, or linked settings count as none.
|
||||
pub settings: Option<serde_json::Value>,
|
||||
}
|
||||
impl Service {
|
||||
/// A package that is in removal, or whose removal did not finish, counts as not installed.
|
||||
fn legacy(&self, id: &str) -> LegacyPackage {
|
||||
let record = self.catalog.plugins.get(id).filter(|record| record.removal.is_none() && !self.removing.contains_key(id));
|
||||
let settings = self.directory("plugin-data").ok().and_then(|parent| {
|
||||
let dir = parent.join(id);
|
||||
let path = dir.join("settings.json");
|
||||
if !path.exists() || safe_child(&parent, &dir).is_err() {
|
||||
return None;
|
||||
}
|
||||
serde_json::from_slice(&bounded(&path, 1024 * 1024).ok()?).ok()
|
||||
});
|
||||
LegacyPackage {
|
||||
id: id.to_owned(),
|
||||
installed: record.is_some(),
|
||||
enabled: record.is_some_and(|record| record.enabled),
|
||||
settings,
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Read the old packages for the feature migration. The caller checks the IDs.
|
||||
pub async fn legacy_packages(app: &AppHandle, ids: Vec<String>) -> Result<Vec<LegacyPackage>> {
|
||||
PluginState::run(app, move |service| Ok(ids.iter().map(|id| service.legacy(id)).collect())).await
|
||||
}
|
||||
#[tauri::command]
|
||||
pub async fn plugins_data(
|
||||
app: AppHandle,
|
||||
@@ -1863,6 +1896,31 @@ mod tests {
|
||||
assert!(f.service.inspect("main", f.source.clone()).error.is_none());
|
||||
}
|
||||
#[test]
|
||||
fn legacy_packages_report_state_and_kept_settings_without_changes() {
|
||||
let mut disabled = Fixture::new();
|
||||
let missing = disabled.service.legacy("org.test.demo");
|
||||
assert_eq!(missing, LegacyPackage { id: "org.test.demo".into(), installed: false, enabled: false, settings: None });
|
||||
let id = disabled.install(false);
|
||||
assert_eq!(disabled.service.legacy(&id), LegacyPackage { id: id.clone(), installed: true, enabled: false, settings: None });
|
||||
let mut f = Fixture::new();
|
||||
let id = f.install(true);
|
||||
let data = f.service.directory("plugin-data").unwrap().join(&id);
|
||||
fs::create_dir(&data).unwrap();
|
||||
fs::write(data.join("settings.json"), r#"{"fontSize":15}"#).unwrap();
|
||||
let state = fs::read(f.root.join("app/plugin-state.json")).unwrap();
|
||||
assert_eq!(f.service.legacy(&id), LegacyPackage { id: id.clone(), installed: true, enabled: true, settings: Some(serde_json::json!({ "fontSize": 15 })) });
|
||||
fs::write(data.join("settings.json"), "{damaged").unwrap();
|
||||
assert_eq!(f.service.legacy(&id).settings, None);
|
||||
assert_eq!(fs::read(f.root.join("app/plugin-state.json")).unwrap(), state, "The read must not change the catalog.");
|
||||
// Settings stay after an uninstall, and the package then counts as not installed.
|
||||
fs::write(data.join("settings.json"), r#"{"kept":true}"#).unwrap();
|
||||
let plan = f.service.prepare("main", &id).unwrap();
|
||||
f.service.begin_remove("main", &plan.token).unwrap();
|
||||
assert!(!f.service.legacy(&id).installed, "A package in removal is not an installed package.");
|
||||
f.service.finish_remove(&id).unwrap();
|
||||
assert_eq!(f.service.legacy(&id), LegacyPackage { id, installed: false, enabled: false, settings: Some(serde_json::json!({ "kept": true })) });
|
||||
}
|
||||
#[test]
|
||||
fn feature_packages_use_the_standard_install_and_remove_lifecycle() {
|
||||
for id in ["runestone.terminal", "runestone.table-formulas"] {
|
||||
let mut f = Fixture::new();
|
||||
|
||||
@@ -20,7 +20,8 @@ use crate::fsutil;
|
||||
pub const FILE_NAME: &str = "settings.json";
|
||||
pub const SCHEMA: u64 = 1;
|
||||
/// The known sections. `customThemesLegacy` keeps the original version 1 themes from before their conversion.
|
||||
pub const SECTIONS: [&str; 5] = ["general", "appearance", "customThemes", "customThemesLegacy", "language"];
|
||||
/// `features` holds the switches of the native features.
|
||||
pub const SECTIONS: [&str; 6] = ["general", "appearance", "customThemes", "customThemesLegacy", "language", "features"];
|
||||
/// The appearance section can hold an image data URL of up to 3,000,000 characters.
|
||||
pub const MAX_FILE_BYTES: usize = 8 * 1024 * 1024;
|
||||
pub const CHANGED_EVENT: &str = "settings-changed";
|
||||
|
||||
Reference in New Issue
Block a user