mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
Offline mode
This commit is contained in:
parent
1622660f0b
commit
4f74b8940a
@ -102,6 +102,10 @@ impl Fetcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if GLOBALS.settings.blocking_read().offline {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
// We can't fetch as we are not async and we don't want to block the caller.
|
// We can't fetch as we are not async and we don't want to block the caller.
|
||||||
// So we save this request as pending, and ask the syncer to sync us.
|
// So we save this request as pending, and ask the syncer to sync us.
|
||||||
self.pending.write().unwrap().insert(url);
|
self.pending.write().unwrap().insert(url);
|
||||||
|
@ -163,7 +163,7 @@ impl Overlord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pick Relays and start Minions
|
// Pick Relays and start Minions
|
||||||
{
|
if !GLOBALS.settings.read().await.offline {
|
||||||
let pubkeys: Vec<PublicKeyHex> = GLOBALS
|
let pubkeys: Vec<PublicKeyHex> = GLOBALS
|
||||||
.people
|
.people
|
||||||
.read()
|
.read()
|
||||||
@ -239,10 +239,10 @@ impl Overlord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
info!("Listening on {} relays", relay_count);
|
info!("Listening on {} relays", relay_count);
|
||||||
}
|
|
||||||
|
|
||||||
// Get desired events from relays
|
// Get desired events from relays
|
||||||
self.get_missing_events().await?;
|
self.get_missing_events().await?;
|
||||||
|
}
|
||||||
|
|
||||||
'mainloop: loop {
|
'mainloop: loop {
|
||||||
match self.loop_handler().await {
|
match self.loop_handler().await {
|
||||||
@ -262,6 +262,10 @@ impl Overlord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn start_minion(&mut self, url: String) -> Result<(), Error> {
|
async fn start_minion(&mut self, url: String) -> Result<(), Error> {
|
||||||
|
if GLOBALS.settings.read().await.offline {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
let url = Url::new(&url);
|
let url = Url::new(&url);
|
||||||
if !url.is_valid_relay_url() {
|
if !url.is_valid_relay_url() {
|
||||||
return Err(Error::InvalidUrl(url.inner().to_owned()));
|
return Err(Error::InvalidUrl(url.inner().to_owned()));
|
||||||
|
@ -14,6 +14,7 @@ pub const DEFAULT_MAX_RELAYS: u8 = 15;
|
|||||||
pub const DEFAULT_MAX_FPS: u32 = 30;
|
pub const DEFAULT_MAX_FPS: u32 = 30;
|
||||||
pub const DEFAULT_FEED_RECOMPUTE_INTERVAL_MS: u32 = 2000;
|
pub const DEFAULT_FEED_RECOMPUTE_INTERVAL_MS: u32 = 2000;
|
||||||
pub const DEFAULT_POW: u8 = 0;
|
pub const DEFAULT_POW: u8 = 0;
|
||||||
|
pub const DEFAULT_OFFLINE: bool = false;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
@ -29,6 +30,7 @@ pub struct Settings {
|
|||||||
pub max_fps: u32,
|
pub max_fps: u32,
|
||||||
pub feed_recompute_interval_ms: u32,
|
pub feed_recompute_interval_ms: u32,
|
||||||
pub pow: u8,
|
pub pow: u8,
|
||||||
|
pub offline: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Settings {
|
impl Default for Settings {
|
||||||
@ -46,6 +48,7 @@ impl Default for Settings {
|
|||||||
max_fps: DEFAULT_MAX_FPS,
|
max_fps: DEFAULT_MAX_FPS,
|
||||||
feed_recompute_interval_ms: DEFAULT_FEED_RECOMPUTE_INTERVAL_MS,
|
feed_recompute_interval_ms: DEFAULT_FEED_RECOMPUTE_INTERVAL_MS,
|
||||||
pow: DEFAULT_POW,
|
pow: DEFAULT_POW,
|
||||||
|
offline: DEFAULT_OFFLINE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,6 +105,7 @@ impl Settings {
|
|||||||
.unwrap_or(DEFAULT_FEED_RECOMPUTE_INTERVAL_MS)
|
.unwrap_or(DEFAULT_FEED_RECOMPUTE_INTERVAL_MS)
|
||||||
}
|
}
|
||||||
"pow" => settings.pow = row.1.parse::<u8>().unwrap_or(DEFAULT_POW),
|
"pow" => settings.pow = row.1.parse::<u8>().unwrap_or(DEFAULT_POW),
|
||||||
|
"offline" => settings.offline = numstr_to_bool(row.1),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,33 +117,40 @@ impl Settings {
|
|||||||
let maybe_db = GLOBALS.db.lock().await;
|
let maybe_db = GLOBALS.db.lock().await;
|
||||||
let db = maybe_db.as_ref().unwrap();
|
let db = maybe_db.as_ref().unwrap();
|
||||||
|
|
||||||
|
let bool_to_numstr = |b: bool| -> &str {
|
||||||
|
if b {
|
||||||
|
"1"
|
||||||
|
} else {
|
||||||
|
"0"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let mut stmt = db.prepare(
|
let mut stmt = db.prepare(
|
||||||
"REPLACE INTO settings (key, value) VALUES \
|
"REPLACE INTO settings (key, value) VALUES \
|
||||||
('feed_chunk', ?),('overlap', ?),\
|
('feed_chunk', ?),\
|
||||||
('view_posts_referred_to', ?),('view_posts_referring_to', ?),\
|
('overlap', ?),\
|
||||||
('view_threaded', ?),('num_relays_per_person', ?),\
|
('view_posts_referred_to', ?),\
|
||||||
('max_relays', ?),('max_fps', ?),('feed_recompute_interval_ms', ?),\
|
('view_posts_referring_to', ?),\
|
||||||
('pow', ?)",
|
('view_threaded', ?),\
|
||||||
|
('num_relays_per_person', ?),\
|
||||||
|
('max_relays', ?),\
|
||||||
|
('max_fps', ?),\
|
||||||
|
('feed_recompute_interval_ms', ?),\
|
||||||
|
('pow', ?),\
|
||||||
|
('offline', ?)",
|
||||||
)?;
|
)?;
|
||||||
stmt.execute((
|
stmt.execute((
|
||||||
self.feed_chunk,
|
self.feed_chunk,
|
||||||
self.overlap,
|
self.overlap,
|
||||||
if self.view_posts_referred_to {
|
bool_to_numstr(self.view_posts_referred_to),
|
||||||
"1"
|
bool_to_numstr(self.view_posts_referring_to),
|
||||||
} else {
|
bool_to_numstr(self.view_threaded),
|
||||||
"0"
|
|
||||||
},
|
|
||||||
if self.view_posts_referring_to {
|
|
||||||
"1"
|
|
||||||
} else {
|
|
||||||
"0"
|
|
||||||
},
|
|
||||||
if self.view_threaded { "1" } else { "0" },
|
|
||||||
self.num_relays_per_person,
|
self.num_relays_per_person,
|
||||||
self.max_relays,
|
self.max_relays,
|
||||||
self.max_fps,
|
self.max_fps,
|
||||||
self.feed_recompute_interval_ms,
|
self.feed_recompute_interval_ms,
|
||||||
self.pow,
|
self.pow,
|
||||||
|
bool_to_numstr(self.offline),
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
// Save private key identity
|
// Save private key identity
|
||||||
|
@ -102,6 +102,15 @@ pub(super) fn update(
|
|||||||
ui.separator();
|
ui.separator();
|
||||||
ui.add_space(12.0);
|
ui.add_space(12.0);
|
||||||
|
|
||||||
|
ui.heading("Network");
|
||||||
|
|
||||||
|
ui.checkbox(&mut app.settings.offline, "Offline Mode")
|
||||||
|
.on_hover_text("If selected, no network requests will be issued. Takes effect on restart.");
|
||||||
|
|
||||||
|
ui.add_space(12.0);
|
||||||
|
ui.separator();
|
||||||
|
ui.add_space(12.0);
|
||||||
|
|
||||||
ui.heading("User Interface");
|
ui.heading("User Interface");
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
|
Loading…
Reference in New Issue
Block a user