mirror of
https://github.com/patarapolw/cjdic2.git
synced 2026-11-09 17:39:35 +00:00
check for yomitan init
This commit is contained in:
1 parent
dcfe074535
commit
3b5afbc34e
3 files changed
+16
-7
No files matched your search
+12
-3
@@ -7,7 +7,7 @@ use std::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::{Ok, Result};
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
|
|
||||||
mod yomitan;
|
mod yomitan;
|
||||||
@@ -46,8 +46,17 @@ impl Database {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_yomitan_dbfile_exists(&self) -> bool {
|
pub fn is_yomitan_dbfile_init(&self) -> Result<bool> {
|
||||||
self.dir.join(YOMITAN_DBFILE).exists()
|
let yomitan_db_path = self.dir.join(YOMITAN_DBFILE);
|
||||||
|
|
||||||
|
if yomitan_db_path.exists() {
|
||||||
|
return Ok(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
let conn = Connection::open(yomitan_db_path)?;
|
||||||
|
let mut stmt = conn.prepare("SELECT 1 FROM dictionaries")?;
|
||||||
|
|
||||||
|
Ok(stmt.exists([])?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn yomitan(&self) -> Result<yomitan::YomitanDatabase> {
|
pub fn yomitan(&self) -> Result<yomitan::YomitanDatabase> {
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ impl AppService {
|
|||||||
Ok(Self { db })
|
Ok(Self { db })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_yomitan_setup_yet(&self) -> bool {
|
pub fn is_yomitan_setup_yet(&self) -> Result<bool, CJDicError> {
|
||||||
self.db.is_yomitan_dbfile_exists()
|
Ok(self.db.is_yomitan_dbfile_init()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn search_yomitan(
|
pub fn search_yomitan(
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
use cjdic2_core::{AppService, YomitanRow};
|
use cjdic2_core::{AppService, YomitanRow};
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn is_yomitan_setup_yet(state: tauri::State<AppService>) -> bool {
|
pub fn is_yomitan_setup_yet(state: tauri::State<AppService>) -> Result<bool, String> {
|
||||||
state.is_yomitan_setup_yet()
|
state.is_yomitan_setup_yet().map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
|
|||||||
Reference in new issue
Block a user