mirror of
https://github.com/patarapolw/cjdic2.git
synced 2026-11-09 17:39:35 +00:00
minimal working on Android filesystem
This commit is contained in:
1 parent
8c9ad287eb
commit
164f7c95bd
9 files changed
+603
-15
No files matched your search
@@ -21,3 +21,6 @@ tauri-build = { version = "2", features = [] }
|
||||
tauri = { version = "2", features = [] }
|
||||
tauri-plugin-opener = "2"
|
||||
cjdic2-core = { path = "../src-core" }
|
||||
tauri-plugin-http = "2"
|
||||
anyhow = "1.0.102"
|
||||
tauri-plugin-fs = "2"
|
||||
@@ -2,9 +2,20 @@
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "default",
|
||||
"description": "Capability for the main window",
|
||||
"windows": ["main"],
|
||||
"windows": [
|
||||
"main"
|
||||
],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"opener:default"
|
||||
"opener:default",
|
||||
{
|
||||
"identifier": "http:default",
|
||||
"allow": [
|
||||
{
|
||||
"url": "https://api.github.com"
|
||||
}
|
||||
]
|
||||
},
|
||||
"fs:default"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<!-- AndroidTV support -->
|
||||
<uses-feature android:name="android.software.leanback" android:required="false" />
|
||||
|
||||
@@ -1,22 +1,63 @@
|
||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||
use cjdic2_core::{AppService, YomitanRow};
|
||||
use tauri::{AppHandle, Emitter, Manager, path::BaseDirectory};
|
||||
use tauri::{AppHandle, Emitter, Manager};
|
||||
#[cfg(target_os = "android")]
|
||||
use tauri_plugin_fs::FsExt;
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn init_yomitan(
|
||||
app: AppHandle,
|
||||
state: tauri::State<'_, AppService>,
|
||||
) -> Result<(), String> {
|
||||
let folder_name = "resources/yomitan";
|
||||
|
||||
// 1. Resolve the internal Asset URI
|
||||
let zip_dir = app
|
||||
.path()
|
||||
.resolve("resources/yomitan", BaseDirectory::Resource)
|
||||
.resolve(folder_name, tauri::path::BaseDirectory::Resource)
|
||||
.map_err(|e| {
|
||||
eprintln!("{:?}", e);
|
||||
e.to_string()
|
||||
})?;
|
||||
// println!("{:?}", zip_dir.as_path());
|
||||
|
||||
state
|
||||
let config = app.config();
|
||||
println!("{:#?}", app.asset_resolver());
|
||||
if let Some(r) = &config.bundle.resources {
|
||||
println!("{:?}", r);
|
||||
}
|
||||
|
||||
// Embedded files cannot be read with std fs directly, not to mention read_dir
|
||||
// It need to be copied with app.fs().read(...) one-by-one, and no read_dir here
|
||||
// @link https://v2.tauri.app/plugin/file-system/
|
||||
// app.config().bundle.resources don't seem to resolve **/*
|
||||
#[cfg(target_os = "android")]
|
||||
let zip_dir = {
|
||||
let filename = "PixivLight_2026-02-24.zip";
|
||||
|
||||
// 2. Define the physical destination in AppData
|
||||
let app_data_dir = app.path().app_data_dir().map_err(|e| e.to_string())?;
|
||||
let app_data_path = app_data_dir.join(filename);
|
||||
|
||||
if !app_data_path.exists() {
|
||||
// 3. IMPORTANT: Use app.fs().read() to read from the APK asset
|
||||
// std::fs::read will fail with "os error 2" on Android
|
||||
let data = app
|
||||
.fs()
|
||||
.read(&zip_dir.join(filename))
|
||||
.map_err(|e| format!("Failed to read asset from APK: {}", e))?;
|
||||
|
||||
// 4. Use std::fs to write to a real physical path in AppData
|
||||
if let Some(parent) = app_data_path.parent() {
|
||||
std::fs::create_dir_all(parent).map_err(|e| e.to_string())?;
|
||||
}
|
||||
std::fs::write(&app_data_path, data)
|
||||
.map_err(|e| format!("Failed to write to AppData: {}", e))?;
|
||||
}
|
||||
|
||||
app_data_dir
|
||||
};
|
||||
|
||||
let r = state
|
||||
.load_yomitan_zip_dir(
|
||||
zip_dir,
|
||||
"ja",
|
||||
@@ -32,6 +73,10 @@ pub async fn init_yomitan(
|
||||
e.to_string()
|
||||
})?;
|
||||
|
||||
if r.new_dicts.len() + r.to_be_removed_dicts.len() > 0 {
|
||||
app.request_restart();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ mod command;
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.plugin(tauri_plugin_http::init())
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.setup(|app| {
|
||||
let app_dir = app.path().app_config_dir()?;
|
||||
|
||||
Reference in new issue
Block a user