forked from 1b-agent/opencadstudio-upstream
feat(plugin): uninstall + clean upgrade/reinstall of external plugins
Add an Uninstall button on installed external plugin cards that deletes the package folder (effective next restart — the library stays resident for the session). Reinstalling or upgrading via the marketplace now clears any stale native library with a different name before writing the new one, so the loader always picks the freshly installed binary. Part of the #100 extensibility epic (phase 2). Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
eb53e445ab
commit
157412419e
5 files changed
+49
No files matched your search
@@ -76,6 +76,16 @@ pub fn plugins_dir() -> Option<PathBuf> {
|
||||
Some(p)
|
||||
}
|
||||
|
||||
/// Delete an installed package's folder. It stays loaded for the current
|
||||
/// session (the library is resident); the removal takes effect on next start.
|
||||
pub fn uninstall(id: &str) -> Result<(), String> {
|
||||
let dir = plugins_dir().ok_or("cannot locate the plugins folder")?.join(id);
|
||||
if dir.is_dir() {
|
||||
std::fs::remove_dir_all(&dir).map_err(|e| e.to_string())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Native dynamic-library extension for the current platform (no dot).
|
||||
fn lib_extension() -> &'static str {
|
||||
if cfg!(target_os = "windows") {
|
||||
|
||||
@@ -192,6 +192,19 @@ pub fn install(release: &Release) -> Result<String, String> {
|
||||
std::fs::create_dir_all(&dir).map_err(|e| e.to_string())?;
|
||||
|
||||
let bytes = download_bytes(&lib.url)?;
|
||||
// Clean upgrade / reinstall: drop any previously-installed native library
|
||||
// with a different name so the loader doesn't pick a stale one. The
|
||||
// currently-resident library (if loaded) keeps running until restart.
|
||||
let ext = external_lib_ext();
|
||||
if let Ok(rd) = std::fs::read_dir(&dir) {
|
||||
for old in rd.flatten() {
|
||||
let p = old.path();
|
||||
let is_lib = p.extension().and_then(|s| s.to_str()) == Some(ext);
|
||||
if is_lib && p.file_name().and_then(|s| s.to_str()) != Some(lib.name.as_str()) {
|
||||
let _ = std::fs::remove_file(&p);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::fs::write(dir.join(&lib.name), bytes).map_err(|e| e.to_string())?;
|
||||
std::fs::write(dir.join("plugin.toml"), toml_text).map_err(|e| e.to_string())?;
|
||||
Ok(manifest.id)
|
||||
|
||||
Reference in new issue
Block a user