Change using Result

This commit is contained in:
fromost
2025-10-09 18:28:35 +08:00
parent 6f8a1eada1
commit 473ef8452b
3 changed files with 31 additions and 25 deletions

View File

@@ -24,13 +24,13 @@ pub(crate) struct App {
}
impl App {
pub fn new() -> App {
pub fn new() -> Self {
let app_conf =
if APP_CONIFG_FILE_PATH.exists() { ApplicationConfig::from_file(&APP_CONIFG_FILE_PATH) }
if APP_CONIFG_FILE_PATH.exists() { ApplicationConfig::from_file(&APP_CONIFG_FILE_PATH).unwrap() }
else { ApplicationConfig::new() };
Self::initialize();
let db_conn = Self::establish_db_connection(app_conf.clone());
App {
Self {
running: true,
events: EventHandler::new(Duration::from_millis(app_conf.basic_config.tick_rate)),
db_connection: db_conn,
@@ -67,7 +67,7 @@ impl App {
fn update(&mut self, event: Event) -> Result<()> {
if let Event::Key(key) = event && event::KeyEventKind::is_press(&key.kind) {
match key.code {
Char('q') => self.quit(),
Char('q') => self.quit()?,
_ => {}
}
}
@@ -129,10 +129,11 @@ impl App {
// event handlers
impl App {
fn quit(&mut self) {
fn quit(&mut self) -> Result<()> {
self.running = false;
self.app_config
.clone()
.write_to_file(APP_CONIFG_FILE_PATH.to_path_buf());
.write_to_file(APP_CONIFG_FILE_PATH.to_path_buf())?;
Ok(())
}
}