backend
TODO: sql loading/parsing from frontend
This commit is contained in:
1 parent
ecd5f6b34e
commit
ac92453685
13 files changed
+463
-8
No files matched your search
+57
-3
@@ -1,4 +1,17 @@
|
||||
mod core;
|
||||
use std::fs::{create_dir_all, File};
|
||||
use tauri::Manager;
|
||||
use tauri_plugin_fs::FsExt;
|
||||
|
||||
use crate::command::*;
|
||||
use crate::service::AppService;
|
||||
use crate::yomitan::search::YomitanSearch;
|
||||
|
||||
mod tokenizer;
|
||||
mod yomitan;
|
||||
|
||||
mod command;
|
||||
mod error;
|
||||
mod service;
|
||||
|
||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||
#[tauri::command]
|
||||
@@ -11,10 +24,51 @@ pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_clipboard_manager::init())
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.plugin(tauri_plugin_sql::Builder::new().build())
|
||||
.plugin(
|
||||
tauri_plugin_sql::Builder::default()
|
||||
.add_migrations("sqlite:search.db", YomitanSearch::migrations())
|
||||
.build(),
|
||||
)
|
||||
.plugin(tauri_plugin_http::init())
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.invoke_handler(tauri::generate_handler![greet])
|
||||
.setup(|app| {
|
||||
let config_dir = app.path().app_config_dir()?;
|
||||
create_dir_all(&config_dir)?;
|
||||
|
||||
let data_dir = app.path().app_data_dir()?;
|
||||
create_dir_all(&data_dir.join("yomitan/ja"))?;
|
||||
|
||||
let cache_dir = app.path().app_cache_dir()?;
|
||||
let vibrato_dic_dir = cache_dir.join("vibrato");
|
||||
create_dir_all(&vibrato_dic_dir)?;
|
||||
|
||||
let vibrato_dic_path = vibrato_dic_dir.join("system.dic");
|
||||
if !vibrato_dic_path.exists() {
|
||||
let zst_path = app.path().resolve(
|
||||
"resources/mecab-ipadic/system.dic.zst",
|
||||
tauri::path::BaseDirectory::Resource,
|
||||
)?;
|
||||
|
||||
// Use Tauri's fs abstraction — works on both Android and desktop
|
||||
let bytes = app.fs().read(&zst_path)?;
|
||||
|
||||
let mut decoder = zstd::Decoder::new(bytes.as_slice())?;
|
||||
let mut out = File::create(&vibrato_dic_path)?;
|
||||
std::io::copy(&mut decoder, &mut out)?;
|
||||
}
|
||||
|
||||
// db_path is at config_dir;
|
||||
let service = AppService::new(&vibrato_dic_path)?;
|
||||
app.manage(service);
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
greet,
|
||||
tokenize,
|
||||
normalize,
|
||||
download_url
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
Reference in new issue
Block a user