diff --git a/src/overlord/mod.rs b/src/overlord/mod.rs index 4941bad5..5a819760 100644 --- a/src/overlord/mod.rs +++ b/src/overlord/mod.rs @@ -5,7 +5,6 @@ use crate::comms::BusMessage; use crate::db::{DbEvent, DbPerson, DbPersonRelay, DbRelay}; use crate::error::Error; use crate::globals::{Globals, GLOBALS}; -use crate::settings::Settings; use minion::Minion; use nostr_types::{ Event, EventKind, Id, Nip05, PreEvent, PrivateKey, PublicKey, PublicKeyHex, Tag, Unixtime, Url, @@ -360,15 +359,7 @@ impl Overlord { "overlord" => match &*bus_message.kind { "minion_is_ready" => {} "save_settings" => { - // from ui - let settings: Settings = serde_json::from_str(&bus_message.json_payload)?; - - // Save to database - settings.save().await?; // to database - - // Update in globals - *GLOBALS.settings.write().await = settings; - + GLOBALS.settings.read().await.save().await?; debug!("Settings saved."); } "get_missing_events" => { diff --git a/src/ui/feed.rs b/src/ui/feed.rs index 957a3e12..ff311b4f 100644 --- a/src/ui/feed.rs +++ b/src/ui/feed.rs @@ -5,7 +5,6 @@ use crate::ui::widgets::{CopyButton, ReplyButton}; use eframe::egui; use egui::{Align, Color32, Context, Layout, RichText, ScrollArea, TextEdit, Ui, Vec2}; use nostr_types::{EventKind, Id}; -use tracing::debug; pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Frame, ui: &mut Ui) { let feed = GLOBALS.feed.blocking_lock().get(); @@ -170,9 +169,11 @@ fn render_post( // Try LayoutJob + let threaded = GLOBALS.settings.blocking_read().view_threaded; + ui.horizontal(|ui| { // Indents first (if threaded) - if app.settings.view_threaded { + if threaded { let space = 16.0 * (10.0 - (100.0 / (indent as f32 + 10.0))); ui.add_space(space); if indent > 0 { @@ -261,7 +262,7 @@ fn render_post( ui.separator(); - if app.settings.view_threaded && !as_reply_to { + if threaded && !as_reply_to { for reply_id in replies { render_post(app, _ctx, _frame, ui, reply_id, indent + 1, as_reply_to); } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index c3722d69..96c7eab7 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -147,9 +147,11 @@ impl GossipUi { impl eframe::App for GossipUi { fn update(&mut self, ctx: &Context, frame: &mut eframe::Frame) { + let max_fps = GLOBALS.settings.blocking_read().max_fps as f32; + // Wait until the next frame std::thread::sleep(self.next_frame - Instant::now()); - self.next_frame += Duration::from_secs_f32(1.0 / self.settings.max_fps as f32); + self.next_frame += Duration::from_secs_f32(1.0 / max_fps); // Redraw at least once per second ctx.request_repaint_after(Duration::from_secs(1)); diff --git a/src/ui/settings.rs b/src/ui/settings.rs index 60dc6f36..454b9c85 100644 --- a/src/ui/settings.rs +++ b/src/ui/settings.rs @@ -130,11 +130,15 @@ pub(super) fn update( ui.with_layout(Layout::top_down(Align::Center), |ui| { if ui.button("SAVE CHANGES").clicked() { + // Copy local settings to global settings + *GLOBALS.settings.blocking_write() = app.settings.clone(); + + // Tell the overlord to save them let tx = GLOBALS.to_overlord.clone(); let _ = tx.send(BusMessage { target: "overlord".to_string(), kind: "save_settings".to_string(), - json_payload: serde_json::to_string(&app.settings).unwrap(), + json_payload: serde_json::to_string("").unwrap(), }); } });