mirror of
https://github.com/patarapolw/cjdic2.git
synced 2026-11-08 17:35:18 +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;
|
||||
|
||||
mod yomitan;
|
||||
@@ -46,8 +46,17 @@ impl Database {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn is_yomitan_dbfile_exists(&self) -> bool {
|
||||
self.dir.join(YOMITAN_DBFILE).exists()
|
||||
pub fn is_yomitan_dbfile_init(&self) -> Result<bool> {
|
||||
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> {
|
||||
|
||||
@@ -20,8 +20,8 @@ impl AppService {
|
||||
Ok(Self { db })
|
||||
}
|
||||
|
||||
pub fn is_yomitan_setup_yet(&self) -> bool {
|
||||
self.db.is_yomitan_dbfile_exists()
|
||||
pub fn is_yomitan_setup_yet(&self) -> Result<bool, CJDicError> {
|
||||
Ok(self.db.is_yomitan_dbfile_init()?)
|
||||
}
|
||||
|
||||
pub fn search_yomitan(
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
use cjdic2_core::{AppService, YomitanRow};
|
||||
|
||||
#[tauri::command]
|
||||
pub fn is_yomitan_setup_yet(state: tauri::State<AppService>) -> bool {
|
||||
state.is_yomitan_setup_yet()
|
||||
pub fn is_yomitan_setup_yet(state: tauri::State<AppService>) -> Result<bool, String> {
|
||||
state.is_yomitan_setup_yet().map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
Reference in new issue
Block a user