Source code
Revision control
Copy as Markdown
Other Tools
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
use serde_json::Value;
use crate::data::ContainersData;
use crate::defaults;
use crate::definitions;
pub(crate) fn migrate_2_to_3(data: &mut ContainersData) {
data.version = 3;
}
pub(crate) fn migrate_3_to_4(data: &mut ContainersData) {
data.identities
.push(defaults::webext_storage_local_identity());
data.version = 4;
}
pub(crate) fn migrate_4_to_5(data: &mut ContainersData) {
for identity in &mut data.identities {
let legacy = identity.extra.remove("l10nID");
identity.extra.remove("accessKey");
let Some(Value::String(legacy)) = legacy else {
continue;
};
// Anything outside the four shipped labels keeps whatever it had.
let fluent = match legacy.as_str() {
"userContextPersonal.label" => Some("user-context-personal"),
"userContextWork.label" => Some("user-context-work"),
"userContextBanking.label" => Some("user-context-banking"),
"userContextShopping.label" => Some("user-context-shopping"),
_ => None,
};
if let Some(fluent) = fluent {
identity
.extra
.insert("l10nId".to_string(), Value::String(fluent.to_string()));
}
}
data.version = 5;
}
/// The color refresh: stored identities keep only canonical names.
pub(crate) fn migrate_5_to_6(data: &mut ContainersData) {
for identity in &mut data.identities {
if !identity.color.is_empty() {
identity.color = definitions::resolve_color(&identity.color);
}
}
data.version = 6;
}
/// container menu items lost their accesskeys.
pub(crate) fn migrate_6_to_7(data: &mut ContainersData) {
for identity in &mut data.identities {
let Some(Value::String(l10n_id)) = identity.extra.get_mut("l10nId") else {
continue;
};
let renamed = match l10n_id.as_str() {
"user-context-personal" => "user-context-personal2",
"user-context-work" => "user-context-work2",
"user-context-banking" => "user-context-banking2",
"user-context-shopping" => "user-context-shopping2",
_ => continue,
};
*l10n_id = renamed.to_string();
}
data.version = 7;
}
/// stored. They come from the default identities the store was opened with, so
/// renaming one no longer needs a migration.
pub(crate) fn migrate_7_to_8(data: &mut ContainersData) {
for identity in &mut data.identities {
identity.extra.remove("l10nId");
}
data.version = 8;
}