mirror of
https://github.com/patarapolw/cjdic2.git
synced 2026-11-09 17:39:35 +00:00
expose to Tauri to ensure it works
This commit is contained in:
1 parent
62cb1e5902
commit
098ee45b81
12 files changed
+108
-53
No files matched your search
@@ -1,2 +0,0 @@
|
||||
*.zip
|
||||
# Pixiv_*.zip => Pixiv.zip from https://github.com/MarvNC/pixiv-yomitan/releases
|
||||
@@ -1,5 +1,5 @@
|
||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||
use cjdic2_core::{AppService, Entry};
|
||||
use cjdic2_core::{AppService, Entry, db::YomitanRow};
|
||||
|
||||
#[tauri::command]
|
||||
pub fn add_entry(name: &str, state: tauri::State<AppService>) -> Result<(), String> {
|
||||
@@ -12,3 +12,16 @@ pub fn add_entry(name: &str, state: tauri::State<AppService>) -> Result<(), Stri
|
||||
pub fn list_entries(state: tauri::State<AppService>) -> Result<Vec<Entry>, String> {
|
||||
state.list_entries().map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn search_yomitan(
|
||||
q_term: &str,
|
||||
q_reading: &str,
|
||||
limit: u32,
|
||||
offset: u32,
|
||||
state: tauri::State<AppService>,
|
||||
) -> Result<Vec<YomitanRow>, String> {
|
||||
state
|
||||
.search_yomitan(q_term, q_reading, limit, offset)
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
+11
-7
@@ -1,3 +1,5 @@
|
||||
use std::{fs::create_dir_all, path::Path};
|
||||
|
||||
use crate::command::*;
|
||||
use cjdic2_core::*;
|
||||
use tauri::Manager;
|
||||
@@ -9,19 +11,21 @@ pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.setup(|app| {
|
||||
let cfg_dir = app.path().app_config_dir();
|
||||
let app_dir = cfg_dir.unwrap_or_else(|_| {
|
||||
std::env::current_dir().unwrap_or_else(|_| std::path::PathBuf::from("."))
|
||||
});
|
||||
std::fs::create_dir_all(&app_dir)?;
|
||||
let app_dir = app.path().app_config_dir()?;
|
||||
create_dir_all(&app_dir)?;
|
||||
|
||||
let db_path = app_dir.join("cjdic.db");
|
||||
// let db_path = app_dir.join("cjdic.db");
|
||||
let db_path = Path::new(r"D:\Projects\cjdic2\test.db");
|
||||
let service = AppService::new(&db_path)?;
|
||||
app.manage(service);
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![add_entry, list_entries])
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
add_entry,
|
||||
list_entries,
|
||||
search_yomitan
|
||||
])
|
||||
.build(tauri::generate_context!())
|
||||
.expect("error while running tauri application")
|
||||
.run(|_app_handle, event| match event {
|
||||
|
||||
Reference in new issue
Block a user