mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 11:43:43 +00:00
UI to use global(saved) settings; but to edit local(unsaved app) settings
This commit is contained in:
parent
7b0d9d6370
commit
acbd71ba11
@ -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" => {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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(),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user