fix for Android

This commit is contained in:
polv committed 2026-03-09 19:31:26 +07:00
1 parent 7b75d6302e
commit 653eacf8d4
5 files changed
+23 -29

No files matched your search

+12 -20
View File
@@ -83,7 +83,6 @@ impl YomitanWriter {
pub fn create_schema( pub fn create_schema(
&mut self, &mut self,
tokenizer: Tokenizer,
progress_callback: impl Fn(YomitanProgress), progress_callback: impl Fn(YomitanProgress),
) -> Result<(), CJDicError> { ) -> Result<(), CJDicError> {
self.conn.execute_batch( self.conn.execute_batch(
@@ -176,25 +175,6 @@ impl YomitanWriter {
self.attach_db(DbChild::YomitanGlossary)?; self.attach_db(DbChild::YomitanGlossary)?;
self.attach_db(DbChild::Search)?; 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 schema_version = "2026-03-08";
let current_schema_version = { let current_schema_version = {
let mut stmt = self let mut stmt = self
@@ -807,6 +787,18 @@ impl YomitanWriter {
Ok(()) 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( fn intern(
+4 -2
View File
@@ -121,7 +121,7 @@ impl AppService {
progress_callback: impl Fn(YomitanProgress), progress_callback: impl Fn(YomitanProgress),
) -> Result<YomitanWriter, CJDicError> { ) -> Result<YomitanWriter, CJDicError> {
let mut writer = YomitanWriter::new(self.db.dir.clone())?; let mut writer = YomitanWriter::new(self.db.dir.clone())?;
writer.create_schema(self.tokenizer.clone(), &progress_callback)?; writer.create_schema(&progress_callback)?;
Ok(writer) Ok(writer)
} }
@@ -187,7 +187,7 @@ impl AppService {
{ {
let mut writer = YomitanWriter::new(self.db.dir.clone())?; 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)?; Self::import_yomitan_zip_file(&mut writer, *zip_file, lang, &import_callback)?;
} }
} }
writer.make_search_db(self.tokenizer.clone(), &import_callback)?;
} }
Ok(LoadYomitanZipDirResult { Ok(LoadYomitanZipDirResult {
+4 -4
View File
@@ -1,7 +1,6 @@
use std::path::Path; use std::{fs::File, io::BufReader, path::Path};
use serde::Serialize; use serde::Serialize;
use vibrato_rkyv::CacheStrategy;
use crate::CJDicError; use crate::CJDicError;
@@ -28,8 +27,9 @@ pub struct Tokenizer {
impl Tokenizer { impl Tokenizer {
pub fn new(vibrato_dict: impl AsRef<Path>) -> Result<Self, CJDicError> { pub fn new(vibrato_dict: impl AsRef<Path>) -> Result<Self, CJDicError> {
let dictionary = let file = BufReader::new(File::open(vibrato_dict)?);
vibrato_rkyv::Dictionary::from_zstd(vibrato_dict, CacheStrategy::GlobalCache)?; let reader = zstd::Decoder::new(file)?;
let dictionary = vibrato_rkyv::Dictionary::read(reader)?;
Ok(Self { Ok(Self {
ja_tokenizer: vibrato_rkyv::Tokenizer::new(dictionary), ja_tokenizer: vibrato_rkyv::Tokenizer::new(dictionary),
}) })
+2 -2
View File
@@ -46,6 +46,8 @@ function LoadingDialog() {
if (isInit.current) return; if (isInit.current) return;
isInit.current = true; isInit.current = true;
document.body.style.pointerEvents = "none";
downloadAssets().finally(() => {
// empty query warmup // empty query warmup
// no need to await // no need to await
invoke("search_yomitan", { invoke("search_yomitan", {
@@ -55,8 +57,6 @@ function LoadingDialog() {
offset: 0, offset: 0,
}); });
document.body.style.pointerEvents = "none";
downloadAssets().finally(() => {
document.body.style.pointerEvents = ""; document.body.style.pointerEvents = "";
const elFirstInput = document.querySelector( const elFirstInput = document.querySelector(
'input[type="text"]', 'input[type="text"]',
+1 -1
View File
@@ -29,7 +29,7 @@ pub fn run() {
let bytes = app.fs().read(&resource_path)?; let bytes = app.fs().read(&resource_path)?;
// Write to app's cache dir, which IS a real writable filesystem path on Android // 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)?; create_dir_all(&cache_dir)?;
let dict_path = cache_dir.join("system.dic.zst"); let dict_path = cache_dir.join("system.dic.zst");
fs::write(&dict_path, &bytes)?; fs::write(&dict_path, &bytes)?;