This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Mode improvements for UI #3109
Merged
Mode improvements for UI #3109
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
bfce244
`--mode=off` now works.
gavofyork 8656583
Merge remote-tracking branch 'origin/master' into off-mode
gavofyork 61c3273
Add Mode::Off as a persistent CLI option.
gavofyork 57cc846
Merge remote-tracking branch 'origin/master' into off-mode
gavofyork 770ebf4
"last" not "auto" as default.
gavofyork 0fa7ef5
Commit accidentally unsaved file.
gavofyork 79c372a
Whitespace
gavofyork 84cf709
Mode CLI parse fix
arkpar 3ad652c
or offline
arkpar 64f9017
Save mode when it gets changed.
gavofyork 957552b
Merge branch 'off-mode' of github.com:ethcore/parity into off-mode
gavofyork b976cd6
Fix Offline mode
gavofyork f0544cf
Merge remote-tracking branch 'origin/master' into off-mode
gavofyork fe7969e
Fix up mode operations.
gavofyork 0c4c573
Make passive default, but not overriding.
gavofyork 2024c05
Fix test
gavofyork 7d543d6
Maybe not everyone wants to run an archive node...
gavofyork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,19 +18,22 @@ use std::fs::File; | |
use std::io::Write; | ||
use std::path::Path; | ||
use std::collections::BTreeMap; | ||
use std::time::Duration; | ||
use serde::{Serialize, Serializer, Error, Deserialize, Deserializer}; | ||
use serde::de::{Visitor, MapVisitor}; | ||
use serde::de::impls::BTreeMapVisitor; | ||
use serde_json::Value; | ||
use serde_json::de::from_reader; | ||
use serde_json::ser::to_string; | ||
use util::journaldb::Algorithm; | ||
use ethcore::client::Mode; | ||
|
||
pub struct UserDefaults { | ||
pub is_first_launch: bool, | ||
pub pruning: Algorithm, | ||
pub tracing: bool, | ||
pub fat_db: bool, | ||
pub mode: Mode, | ||
} | ||
|
||
impl Serialize for UserDefaults { | ||
|
@@ -40,6 +43,21 @@ impl Serialize for UserDefaults { | |
map.insert("pruning".into(), Value::String(self.pruning.as_str().into())); | ||
map.insert("tracing".into(), Value::Bool(self.tracing)); | ||
map.insert("fat_db".into(), Value::Bool(self.fat_db)); | ||
let mode_str = match self.mode { | ||
Mode::Off => "offline", | ||
Mode::Dark(timeout) => { | ||
map.insert("mode.timeout".into(), Value::U64(timeout.as_secs())); | ||
"dark" | ||
}, | ||
Mode::Passive(timeout, alarm) => { | ||
map.insert("mode.timeout".into(), Value::U64(timeout.as_secs())); | ||
map.insert("mode.alarm".into(), Value::U64(alarm.as_secs())); | ||
"passive" | ||
}, | ||
Mode::Active => "active", | ||
}; | ||
map.insert("mode".into(), Value::String(mode_str.into())); | ||
|
||
map.serialize(serializer) | ||
} | ||
} | ||
|
@@ -67,11 +85,28 @@ impl Visitor for UserDefaultsVisitor { | |
let fat_db: Value = map.remove("fat_db".into()).unwrap_or_else(|| Value::Bool(false)); | ||
let fat_db = try!(fat_db.as_bool().ok_or_else(|| Error::custom("invalid fat_db value"))); | ||
|
||
let mode: Value = map.remove("mode".into()).unwrap_or_else(|| Value::String("active".to_owned())); | ||
let mode = match try!(mode.as_str().ok_or_else(|| Error::custom("invalid mode value"))) { | ||
"off" => Mode::Off, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "offline" probably? |
||
"dark" => { | ||
let timeout = try!(map.remove("mode.timeout".into()).and_then(|v| v.as_u64()).ok_or_else(|| Error::custom("invalid/missing mode.timeout value"))); | ||
Mode::Dark(Duration::from_secs(timeout)) | ||
}, | ||
"passive" => { | ||
let timeout = try!(map.remove("mode.timeout".into()).and_then(|v| v.as_u64()).ok_or_else(|| Error::custom("invalid/missing mode.timeout value"))); | ||
let alarm = try!(map.remove("mode.alarm".into()).and_then(|v| v.as_u64()).ok_or_else(|| Error::custom("invalid/missing mode.alarm value"))); | ||
Mode::Passive(Duration::from_secs(timeout), Duration::from_secs(alarm)) | ||
}, | ||
"active" => Mode::Active, | ||
_ => { return Err(Error::custom("invalid mode value")); }, | ||
}; | ||
|
||
let user_defaults = UserDefaults { | ||
is_first_launch: false, | ||
pruning: pruning, | ||
tracing: tracing, | ||
fat_db: fat_db, | ||
mode: mode, | ||
}; | ||
|
||
Ok(user_defaults) | ||
|
@@ -85,6 +120,7 @@ impl Default for UserDefaults { | |
pruning: Algorithm::default(), | ||
tracing: false, | ||
fat_db: false, | ||
mode: Mode::Active, | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto not mentioned here, but is set as the default