mirror of
https://github.com/patarapolw/cjdic2.git
synced 2026-11-09 17:39:35 +00:00
fix for Android
This commit is contained in:
1 parent
7b75d6302e
commit
653eacf8d4
5 files changed
+23
-29
No files matched your search
@@ -83,7 +83,6 @@ impl YomitanWriter {
|
||||
|
||||
pub fn create_schema(
|
||||
&mut self,
|
||||
tokenizer: Tokenizer,
|
||||
progress_callback: impl Fn(YomitanProgress),
|
||||
) -> Result<(), CJDicError> {
|
||||
self.conn.execute_batch(
|
||||
@@ -176,25 +175,6 @@ impl YomitanWriter {
|
||||
self.attach_db(DbChild::YomitanGlossary)?;
|
||||
self.attach_db(DbChild::Search)?;
|
||||
|
||||
let search_max_id = {
|
||||
let mut stmt = self.conn.prepare(&format!(
|
||||
"SELECT COALESCE(MAX(id), 0) FROM {}.terms",
|
||||
DBSCHEMA[DbChild::Search]
|
||||
))?;
|
||||
let mut rows = stmt.query([])?;
|
||||
|
||||
if let Some(r) = rows.next()? {
|
||||
r.get(0)?
|
||||
} else {
|
||||
0
|
||||
}
|
||||
};
|
||||
if search_max_id == 0 {
|
||||
let mut search_db = SearchDatabase::new(&mut self.conn);
|
||||
search_db.reset_db()?;
|
||||
search_db.regenerate_yomitan("main", tokenizer.clone(), &progress_callback)?;
|
||||
}
|
||||
|
||||
let schema_version = "2026-03-08";
|
||||
let current_schema_version = {
|
||||
let mut stmt = self
|
||||
@@ -807,6 +787,18 @@ impl YomitanWriter {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn make_search_db(
|
||||
&mut self,
|
||||
tokenizer: Tokenizer,
|
||||
progress_callback: impl Fn(YomitanProgress),
|
||||
) -> Result<(), CJDicError> {
|
||||
let mut search_db = SearchDatabase::new(&mut self.conn);
|
||||
search_db.reset_db()?;
|
||||
search_db.regenerate_yomitan("main", tokenizer.clone(), &progress_callback)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn intern(
|
||||
|
||||
@@ -121,7 +121,7 @@ impl AppService {
|
||||
progress_callback: impl Fn(YomitanProgress),
|
||||
) -> Result<YomitanWriter, CJDicError> {
|
||||
let mut writer = YomitanWriter::new(self.db.dir.clone())?;
|
||||
writer.create_schema(self.tokenizer.clone(), &progress_callback)?;
|
||||
writer.create_schema(&progress_callback)?;
|
||||
Ok(writer)
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ impl AppService {
|
||||
|
||||
{
|
||||
let mut writer = YomitanWriter::new(self.db.dir.clone())?;
|
||||
writer.create_schema(self.tokenizer.clone(), &import_callback)?;
|
||||
writer.create_schema(&import_callback)?;
|
||||
}
|
||||
|
||||
{
|
||||
@@ -208,6 +208,8 @@ impl AppService {
|
||||
Self::import_yomitan_zip_file(&mut writer, *zip_file, lang, &import_callback)?;
|
||||
}
|
||||
}
|
||||
|
||||
writer.make_search_db(self.tokenizer.clone(), &import_callback)?;
|
||||
}
|
||||
|
||||
Ok(LoadYomitanZipDirResult {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::path::Path;
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
|
||||
use serde::Serialize;
|
||||
use vibrato_rkyv::CacheStrategy;
|
||||
|
||||
use crate::CJDicError;
|
||||
|
||||
@@ -28,8 +27,9 @@ pub struct Tokenizer {
|
||||
|
||||
impl Tokenizer {
|
||||
pub fn new(vibrato_dict: impl AsRef<Path>) -> Result<Self, CJDicError> {
|
||||
let dictionary =
|
||||
vibrato_rkyv::Dictionary::from_zstd(vibrato_dict, CacheStrategy::GlobalCache)?;
|
||||
let file = BufReader::new(File::open(vibrato_dict)?);
|
||||
let reader = zstd::Decoder::new(file)?;
|
||||
let dictionary = vibrato_rkyv::Dictionary::read(reader)?;
|
||||
Ok(Self {
|
||||
ja_tokenizer: vibrato_rkyv::Tokenizer::new(dictionary),
|
||||
})
|
||||
|
||||
@@ -46,6 +46,8 @@ function LoadingDialog() {
|
||||
if (isInit.current) return;
|
||||
isInit.current = true;
|
||||
|
||||
document.body.style.pointerEvents = "none";
|
||||
downloadAssets().finally(() => {
|
||||
// empty query warmup
|
||||
// no need to await
|
||||
invoke("search_yomitan", {
|
||||
@@ -55,8 +57,6 @@ function LoadingDialog() {
|
||||
offset: 0,
|
||||
});
|
||||
|
||||
document.body.style.pointerEvents = "none";
|
||||
downloadAssets().finally(() => {
|
||||
document.body.style.pointerEvents = "";
|
||||
const elFirstInput = document.querySelector(
|
||||
'input[type="text"]',
|
||||
|
||||
@@ -29,7 +29,7 @@ pub fn run() {
|
||||
let bytes = app.fs().read(&resource_path)?;
|
||||
|
||||
// Write to app's cache dir, which IS a real writable filesystem path on Android
|
||||
let cache_dir = app.path().cache_dir()?;
|
||||
let cache_dir = app.path().app_cache_dir()?.join("vibrato");
|
||||
create_dir_all(&cache_dir)?;
|
||||
let dict_path = cache_dir.join("system.dic.zst");
|
||||
fs::write(&dict_path, &bytes)?;
|
||||
|
||||
Reference in new issue
Block a user