Mode configuration backported to beta (#3213)
* Mode improvements for UI (#3109) * `--mode=off` now works. * Add Mode::Off as a persistent CLI option. * "last" not "auto" as default. * Commit accidentally unsaved file. * Whitespace [ci:skip] * Mode CLI parse fix * or offline * Save mode when it gets changed. * Fix Offline mode * Fix up mode operations. * Make passive default, but not overriding. * Fix test * Maybe not everyone wants to run an archive node... * Parity configuration settings, i.e. mode (#3212) * Add initial page * Add parity icon * opacity for parity icon * Mode selector * Actually set mode when value changes Former-commit-id: 64386d94adfa58aa30bab2005eeb64f6343c8248
This commit is contained in:
committed by
Gav Wood
parent
8b5a9b701a
commit
e727d92e0f
@@ -147,6 +147,7 @@ pub struct Client {
|
||||
factories: Factories,
|
||||
history: u64,
|
||||
rng: Mutex<OsRng>,
|
||||
on_mode_change: Mutex<Option<Box<FnMut(&Mode) + 'static + Send>>>,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
@@ -211,7 +212,7 @@ impl Client {
|
||||
let panic_handler = PanicHandler::new_in_arc();
|
||||
panic_handler.forward_from(&block_queue);
|
||||
|
||||
let awake = match config.mode { Mode::Dark(..) => false, _ => true };
|
||||
let awake = match config.mode { Mode::Dark(..) | Mode::Off => false, _ => true };
|
||||
|
||||
let factories = Factories {
|
||||
vm: EvmFactory::new(config.vm_type.clone(), config.jump_table_size),
|
||||
@@ -243,6 +244,7 @@ impl Client {
|
||||
factories: factories,
|
||||
history: history,
|
||||
rng: Mutex::new(try!(OsRng::new().map_err(::util::UtilError::StdIo))),
|
||||
on_mode_change: Mutex::new(None),
|
||||
};
|
||||
Ok(Arc::new(client))
|
||||
}
|
||||
@@ -260,6 +262,11 @@ impl Client {
|
||||
}
|
||||
}
|
||||
|
||||
/// Register an action to be done if a mode change happens.
|
||||
pub fn on_mode_change<F>(&self, f: F) where F: 'static + FnMut(&Mode) + Send {
|
||||
*self.on_mode_change.lock() = Some(Box::new(f));
|
||||
}
|
||||
|
||||
/// Flush the block import queue.
|
||||
pub fn flush_queue(&self) {
|
||||
self.block_queue.flush();
|
||||
@@ -856,18 +863,37 @@ impl BlockChainClient for Client {
|
||||
}
|
||||
|
||||
fn keep_alive(&self) {
|
||||
let mode = self.mode.lock().clone();
|
||||
if mode != Mode::Active {
|
||||
let should_wake = match &*self.mode.lock() {
|
||||
&Mode::Dark(..) | &Mode::Passive(..) => true,
|
||||
_ => false,
|
||||
};
|
||||
if should_wake {
|
||||
self.wake_up();
|
||||
(*self.sleep_state.lock()).last_activity = Some(Instant::now());
|
||||
}
|
||||
}
|
||||
|
||||
fn mode(&self) -> IpcMode { self.mode.lock().clone().into() }
|
||||
fn mode(&self) -> IpcMode {
|
||||
let r = self.mode.lock().clone().into();
|
||||
trace!(target: "mode", "Asked for mode = {:?}. returning {:?}", &*self.mode.lock(), r);
|
||||
r
|
||||
}
|
||||
|
||||
fn set_mode(&self, mode: IpcMode) {
|
||||
*self.mode.lock() = mode.clone().into();
|
||||
match mode {
|
||||
fn set_mode(&self, new_mode: IpcMode) {
|
||||
trace!(target: "mode", "Client::set_mode({:?})", new_mode);
|
||||
{
|
||||
let mut mode = self.mode.lock();
|
||||
*mode = new_mode.clone().into();
|
||||
trace!(target: "mode", "Mode now {:?}", &*mode);
|
||||
match *self.on_mode_change.lock() {
|
||||
Some(ref mut f) => {
|
||||
trace!(target: "mode", "Making callback...");
|
||||
f(&*mode)
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
match new_mode {
|
||||
IpcMode::Active => self.wake_up(),
|
||||
IpcMode::Off => self.sleep(),
|
||||
_ => {(*self.sleep_state.lock()).last_activity = Some(Instant::now()); }
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
use std::str::FromStr;
|
||||
use std::path::Path;
|
||||
use std::fmt::{Display, Formatter, Error as FmtError};
|
||||
pub use std::time::Duration;
|
||||
pub use blockchain::Config as BlockChainConfig;
|
||||
pub use trace::Config as TraceConfig;
|
||||
@@ -86,6 +87,17 @@ impl Default for Mode {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Mode {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
|
||||
match *self {
|
||||
Mode::Active => write!(f, "active"),
|
||||
Mode::Passive(..) => write!(f, "passive"),
|
||||
Mode::Dark(..) => write!(f, "dark"),
|
||||
Mode::Off => write!(f, "offline"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Client configuration. Includes configs for all sub-systems.
|
||||
#[derive(Debug, PartialEq, Default)]
|
||||
pub struct ClientConfig {
|
||||
|
||||
@@ -20,7 +20,7 @@ pub use std::time::Duration;
|
||||
use client::Mode as ClientMode;
|
||||
|
||||
/// IPC-capable shadow-type for client::config::Mode
|
||||
#[derive(Clone, Binary)]
|
||||
#[derive(Clone, Binary, Debug)]
|
||||
pub enum Mode {
|
||||
/// Same as ClientMode::Off.
|
||||
Off,
|
||||
|
||||
Reference in New Issue
Block a user