Skip to content

Commit

Permalink
Minor refactors (#130)
Browse files Browse the repository at this point in the history
* Remove unused config reloading code

* Remove unused imports

* Remove redundant lifetime specifier
  • Loading branch information
holmgr committed Jul 30, 2018
1 parent 1196169 commit 12cc0b7
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 244 deletions.
206 changes: 0 additions & 206 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions Cargo.toml
Expand Up @@ -4,13 +4,11 @@ version = "0.1.0"
authors = ["holmgr <viktor.holmgren@gmail.com>"]

[dependencies]
notify = "4.0.0"
serde = "^1.0"
app_dirs = "^1.2.1"
serde_json = "^1.0"
serde_derive = "^1.0"
rand = "^0.4"
petgraph = "0.4.8"
rayon = "0.9.0"
log = "0.4"
statrs = "0.9.0"
Expand Down
32 changes: 1 addition & 31 deletions src/game_config.rs
@@ -1,7 +1,6 @@
use app_dirs::{get_data_root, AppDataType};
use notify::{watcher, RecursiveMode, Watcher};
use std::{
fs::{create_dir_all, File}, io::{Read, Write}, sync::mpsc::{channel, RecvError}, time::Duration,
fs::{create_dir_all, File}, io::{Read, Write},
};
use toml::{de::from_str, ser::to_string_pretty};

Expand Down Expand Up @@ -69,35 +68,6 @@ impl GameConfig {
config_file.write_all(&encoded.into_bytes()).ok()
});
}

/// Setup a blocking Watcher listening for any file changes at the
/// preferences location of the GameConfig.
/// If some change is detected it will attempt to return the updated
/// GameConfig.
/// # Failures
/// Channel error when attempting to read while watching for changes.
pub fn await_update() -> Result<GameConfig, RecvError> {
// Create a channel to receive the events.
let (tx, rx) = channel();

// Create a watcher object, delivering debounced events.
// The notification back-end is selected based on the platform.
let mut watcher = watcher(tx, Duration::from_secs(30)).unwrap();

// Add a path to be watched. All files and directories at that path and
// below will be monitored for changes.
let config_path = get_data_root(AppDataType::UserConfig)
.unwrap()
.join(PREFS_PATH);
watcher
.watch(config_path, RecursiveMode::Recursive)
.unwrap();

match rx.recv() {
Ok(_) => Ok(GameConfig::retrieve()),
Err(e) => Err(e),
}
}
}

impl Default for GameConfig {
Expand Down
2 changes: 1 addition & 1 deletion src/gui/info.rs
Expand Up @@ -4,7 +4,7 @@ use tui::{
widgets::{Block, Paragraph, Widget},
};

const TITLE_ART: &'static str = include_str!("../../res/title.txt");
const TITLE_ART: &str = include_str!("../../res/title.txt");

/// Draws a information page with the given information.
pub fn draw_info_page(term: &mut Terminal<MouseBackend>, area: Rect, information: &str) {
Expand Down
4 changes: 2 additions & 2 deletions src/gui/title.rs
@@ -1,11 +1,11 @@
use event::Event;
use std::fmt;
use std::sync::{mpsc::Sender, Arc};
use std::sync::mpsc::Sender;
use termion::event as keyevent;
use tui::{backend::MouseBackend, layout::Rect, Terminal};
use tui::{
layout::{Direction, Group, Size}, style::{Alignment, Color, Style},
widgets::{Block, Borders, Paragraph, SelectableList, Widget},
widgets::{Block, Paragraph, SelectableList, Widget},
};

use super::GUIEvent;
Expand Down
2 changes: 0 additions & 2 deletions src/main.rs
Expand Up @@ -9,8 +9,6 @@ extern crate inflector;
extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate notify;
extern crate petgraph;
extern crate rand;
extern crate rayon;
extern crate serde;
Expand Down

0 comments on commit 12cc0b7

Please sign in to comment.