From baca704d4b5fae239fc320d10140f35bd705bfbb Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Mon, 5 Feb 2024 09:54:29 -0300 Subject: [PATCH] fix(cli): skip migrating updater config if not active (#8768) --- .changes/fix-migrate-updater.md | 6 ++++ tooling/cli/src/migrate/config.rs | 47 +++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 .changes/fix-migrate-updater.md diff --git a/.changes/fix-migrate-updater.md b/.changes/fix-migrate-updater.md new file mode 100644 index 000000000..eec5c5b49 --- /dev/null +++ b/.changes/fix-migrate-updater.md @@ -0,0 +1,6 @@ +--- +"@tauri-apps/cli": patch:bug +"tauri-cli": patch:bug +--- + +Do not migrate updater configuration if the active flag is set to false. diff --git a/tooling/cli/src/migrate/config.rs b/tooling/cli/src/migrate/config.rs index 67d840e53..e37286c48 100644 --- a/tooling/cli/src/migrate/config.rs +++ b/tooling/cli/src/migrate/config.rs @@ -503,9 +503,20 @@ fn process_updater( if let Some(mut updater) = tauri_config.remove("updater") { if let Some(updater) = updater.as_object_mut() { updater.remove("dialog"); - updater.remove("active"); + + // we only migrate the updater config if it's active + // since we now assume it's always active if the config object is set + // we also migrate if pubkey is set so we do not lose that information on the migration + // in this case, the user need to deal with the updater being inactive on their own + if updater + .remove("active") + .and_then(|a| a.as_bool()) + .unwrap_or_default() + || updater.get("pubkey").is_some() + { + plugins.insert("updater".into(), serde_json::to_value(updater)?); + } } - plugins.insert("updater".into(), serde_json::to_value(updater)?); } Ok(()) @@ -711,6 +722,38 @@ mod test { ); } + #[test] + fn skips_migrating_updater() { + let original = serde_json::json!({ + "tauri": { + "updater": { + "active": false + } + } + }); + + let migrated = migrate(&original); + assert_eq!(migrated["plugins"]["updater"], serde_json::Value::Null); + } + + #[test] + fn migrate_updater_pubkey() { + let original = serde_json::json!({ + "tauri": { + "updater": { + "active": false, + "pubkey": "somekey" + } + } + }); + + let migrated = migrate(&original); + assert_eq!( + migrated["plugins"]["updater"]["pubkey"], + original["tauri"]["updater"]["pubkey"] + ); + } + #[test] fn migrate_csp_object() { let original = serde_json::json!({