feat(sync): include plugin settings in snapshots
This commit is contained in:
@@ -34,6 +34,7 @@ mod sync_apply;
|
||||
mod sync_context;
|
||||
mod sync_history;
|
||||
mod sync_notes;
|
||||
mod sync_plugin_settings;
|
||||
mod sync_profiles;
|
||||
mod sync_reading_list;
|
||||
mod sync_site_permissions;
|
||||
|
||||
@@ -51,6 +51,18 @@ impl InstalledPlugin {
|
||||
self.private_window_allowed = allowed;
|
||||
}
|
||||
|
||||
pub(super) fn apply_synced_settings(
|
||||
&mut self,
|
||||
enabled: bool,
|
||||
private_window_allowed: bool,
|
||||
) -> bool {
|
||||
let changed =
|
||||
self.enabled != enabled || self.private_window_allowed != private_window_allowed;
|
||||
self.enabled = enabled;
|
||||
self.private_window_allowed = private_window_allowed;
|
||||
changed
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn manifest(&self) -> &PluginManifest {
|
||||
&self.manifest
|
||||
|
||||
@@ -34,6 +34,9 @@ impl BrowserCore {
|
||||
for record in body.history {
|
||||
self.apply_history_sync_record(record, &mut summary, &context)?;
|
||||
}
|
||||
for record in body.plugin_settings {
|
||||
self.apply_plugin_settings_sync_record(record, &mut summary)?;
|
||||
}
|
||||
Ok(summary)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
use ely_domain::{PluginId, SyncObjectKind, SyncObjectPolicy};
|
||||
use ely_sync_client::SyncClientError;
|
||||
|
||||
use super::{BrowserCore, InstalledPlugin, sync::snapshot_schema_error};
|
||||
use crate::{sync_engine::SyncSnapshotApplySummary, sync_records::PluginSettingsSyncRecord};
|
||||
|
||||
impl BrowserCore {
|
||||
pub(crate) fn visible_plugin_settings_for_sync(&self) -> Vec<&InstalledPlugin> {
|
||||
if self.sync_object_policy(SyncObjectKind::PluginSettings) == SyncObjectPolicy::Paused {
|
||||
return Vec::new();
|
||||
}
|
||||
self.installed_plugins.iter().collect()
|
||||
}
|
||||
|
||||
pub(super) fn apply_plugin_settings_sync_record(
|
||||
&mut self,
|
||||
record: PluginSettingsSyncRecord,
|
||||
summary: &mut SyncSnapshotApplySummary,
|
||||
) -> Result<(), SyncClientError> {
|
||||
let plugin_id = PluginId::parse(&record.plugin_id).map_err(snapshot_schema_error)?;
|
||||
let Some(plugin) =
|
||||
self.installed_plugins.iter_mut().find(|plugin| plugin.id() == &plugin_id)
|
||||
else {
|
||||
summary.record_skipped();
|
||||
return Ok(());
|
||||
};
|
||||
if plugin.manifest().checksum() != record.checksum {
|
||||
summary.record_skipped();
|
||||
return Ok(());
|
||||
}
|
||||
if plugin.apply_synced_settings(record.enabled, record.private_window_allowed) {
|
||||
summary.record_updated();
|
||||
} else {
|
||||
summary.record_skipped();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ use ely_domain::{
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::state::BrowserCore;
|
||||
use crate::state::InstalledPlugin;
|
||||
|
||||
pub(crate) const SNAPSHOT_SCHEMA_REV: u32 = 1;
|
||||
|
||||
@@ -29,6 +30,8 @@ pub(crate) struct SyncSnapshotBody {
|
||||
pub(crate) site_permissions: Vec<SitePermissionSyncRecord>,
|
||||
#[serde(default)]
|
||||
pub(crate) history: Vec<HistorySyncRecord>,
|
||||
#[serde(default)]
|
||||
pub(crate) plugin_settings: Vec<PluginSettingsSyncRecord>,
|
||||
}
|
||||
|
||||
impl SyncSnapshotBody {
|
||||
@@ -91,6 +94,11 @@ impl SyncSnapshotBody {
|
||||
HistorySyncRecord::from_entry(entry, core.sync_space_name_for(entry.space_id()))
|
||||
})
|
||||
.collect(),
|
||||
plugin_settings: core
|
||||
.visible_plugin_settings_for_sync()
|
||||
.into_iter()
|
||||
.map(PluginSettingsSyncRecord::from_plugin)
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -440,6 +448,25 @@ impl HistorySyncRecord {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub(crate) struct PluginSettingsSyncRecord {
|
||||
pub(crate) plugin_id: String,
|
||||
pub(crate) checksum: String,
|
||||
pub(crate) enabled: bool,
|
||||
pub(crate) private_window_allowed: bool,
|
||||
}
|
||||
|
||||
impl PluginSettingsSyncRecord {
|
||||
fn from_plugin(plugin: &InstalledPlugin) -> Self {
|
||||
Self {
|
||||
plugin_id: plugin.id().as_str().to_string(),
|
||||
checksum: plugin.manifest().checksum().to_string(),
|
||||
enabled: plugin.enabled(),
|
||||
private_window_allowed: plugin.private_window_allowed(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn default_sync_enabled() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user