Compare commits

3 Commits
Author SHA1 Message Date
polv a0b2cf63d1 app icon, and remove android debug via .dev flavor
- debug .dev flavor doesn't work well with RUST-BACKTRACE and webview devtools
- tauri android run already install debug without dev server
2026-03-24 13:25:06 +07:00
polv 079fdd512c try spawn blocking 2026-03-22 21:46:47 +07:00
polv 413376d3f3 remove zipSource 2026-03-22 15:15:26 +07:00
79 changed files with 131 additions and 62 deletions

No files matched your search

+3
View File
@@ -6,3 +6,6 @@ resolver = "3"
lto = true
codegen-units = 1
strip = true
# debug = true # keep symbols
# lto = false # disable LTO
# opt-level = 1 # reduce but don't maximize optimization
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

+75
View File
@@ -0,0 +1,75 @@
import sharp from "sharp";
import { spawnSync } from "child_process";
async function resizeAndMakeWhiteTransparent(inputPath, outputPath) {
const whiteThreshold = 250; // treat >= as white
const img = sharp(inputPath).ensureAlpha();
// Get metadata to compute resize dimensions preserving aspect ratio
const meta = await img.metadata();
const origW = meta.width || 0;
const origH = meta.height || 0;
if (!origW || !origH) throw new Error("Unable to read image dimensions");
const targetW = Math.max(origW, origH);
const targetH = targetW;
// Resize and output raw RGBA buffer
const { data, info } = await img
.resize(targetW, targetH, { fit: "fill" })
.raw()
.toBuffer({ resolveWithObject: true });
const { width: w, height: h, channels } = info; // channels should be 4 (RGBA)
if (channels < 3) throw new Error("Unexpected channel count");
// Check if image already has any transparency
let hasTransparency = false;
for (let i = 0; i < data.length; i += channels) {
if (data[i + 3] < 255) {
hasTransparency = true;
break;
}
}
if (!hasTransparency) {
// Modify alpha for near-white pixels
for (let i = 0; i < data.length; i += channels) {
const r = data[i];
const g = data[i + 1];
const b = data[i + 2];
const a = channels === 4 ? data[i + 3] : 255;
if (
a > 0 &&
r >= whiteThreshold &&
g >= whiteThreshold &&
b >= whiteThreshold
) {
if (channels === 4) data[i + 3] = 0;
else {
// expand to RGBA if input lacked alpha
// create a new buffer would be required; throw for simplicity
throw new Error(
"Input image missing alpha channel; ensure ensureAlpha() was applied.",
);
}
}
}
}
// Recreate and save PNG
await sharp(data, { raw: { width: w, height: h, channels } })
.png({ compressionLevel: 9 })
.toFile(outputPath);
}
const [, , input] = process.argv;
if (!input) {
throw new Error(`Input is required: input=${input}`);
}
// Example usage
resizeAndMakeWhiteTransparent(input, "app-icon.png")
.then(() => spawnSync("pnpm tauri icon", { shell: true, stdio: "inherit" }))
.catch((err) => console.error(err));
+8 -7
View File
@@ -5,21 +5,22 @@
"scripts": {
"dev:desktop": "cross-env RUST_BACKTRACE=1 tauri dev",
"dev:mobile": "cross-env RUST_BACKTRACE=1 tauri dev -c src-tauri/tauri.mobile.conf.json",
"dev:android": "cross-env RUST_BACKTRACE=1 tauri android dev",
"log:android": "adb logcat -e \"RustStdoutStderr\"",
"dev:android": "cross-env RUST_BACKTRACE=1 tauri android run",
"dev:android:server": "cross-env RUST_BACKTRACE=1 tauri android dev",
"dev:android:install": "adb install -r src-tauri/gen/android/app/build/outputs/apk/arm64/debug/app-arm64-debug.apk",
"dev:android:build": "tauri android build --debug",
"dev:android:log": "adb logcat -e \"RustStdoutStderr\"",
"build:desktop": "tauri build",
"build:android": "tauri android build",
"install:android": "adb install -r src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release.apk",
"build:android:debug": "tauri android build --debug",
"install:android:debug": "adb install -r src-tauri/gen/android/app/build/outputs/apk/universal/debug/app-universal-debug.apk",
"run:desktop": ".\\target\\release\\cjdic2.exe",
"release": "node release.js",
"dev": "cd src-react && pnpm run dev",
"build": "cd src-react && pnpm run build",
"tauri": "tauri"
"build": "cd src-react && pnpm run build"
},
"devDependencies": {
"@tauri-apps/cli": "^2",
"cross-env": "^10.1.0"
"cross-env": "^10.1.0",
"sharp": "^0.34.5"
}
}
+3
View File
@@ -14,6 +14,9 @@ importers:
cross-env:
specifier: ^10.1.0
version: 10.1.0
sharp:
specifier: ^0.34.5
version: 0.34.5
js-server:
dependencies:
+1 -1
View File
@@ -16,7 +16,7 @@ mod yomitan;
pub use yomitan::YomitanRow;
mod yomitan_writer;
pub use yomitan_writer::{YomitanProgress, YomitanWriter, YomitanZipImportResult, ZipSource};
pub use yomitan_writer::{YomitanProgress, YomitanWriter, YomitanZipImportResult};
use crate::{CJDicError, tokenizer::Tokenizer};
+6 -23
View File
@@ -4,11 +4,10 @@ use rusqlite::{Connection, OptionalExtension, Result, Transaction, params};
use serde::Serialize;
use serde_json::Value;
use std::{
borrow::Cow,
collections::HashMap,
env::current_dir,
fs::{File, create_dir_all},
io::{self, Cursor, Read},
io::{self, Read},
path::{Path, PathBuf},
};
use zip::ZipArchive;
@@ -30,21 +29,6 @@ pub(super) fn normalize_term(s: &str) -> String {
.collect()
}
pub trait ZipSource {
fn file_name(&self) -> &str;
fn bytes(&self) -> std::io::Result<Cow<'_, [u8]>>;
}
impl ZipSource for PathBuf {
fn file_name(&self) -> &str {
Path::file_name(self).and_then(|n| n.to_str()).unwrap_or("")
}
fn bytes(&self) -> std::io::Result<Cow<'_, [u8]>> {
std::fs::read(self).map(Cow::Owned)
}
}
#[derive(Serialize, Debug, Clone)]
pub struct YomitanProgress {
pub message: String,
@@ -446,24 +430,23 @@ impl YomitanWriter {
Ok(())
}
pub fn import_dictionary_zip_file<Z, Callback>(
pub fn import_dictionary_zip_file<Callback>(
&mut self,
zip_file: &Z,
zip_file: &PathBuf,
asset_dir: &PathBuf,
lang: &str,
progress_callback: Callback,
) -> anyhow::Result<YomitanZipImportResult, CJDicError>
where
Z: ZipSource,
Callback: Fn(YomitanProgress),
{
let bundle_name = zip_file.file_name();
let bundle_name = zip_file.file_name().and_then(|n| n.to_str()).unwrap_or("");
let _timer = Timer::new(format!("Importing {}", bundle_name));
self.conn.execute_batch("PRAGMA foreign_keys = off")?;
let cursor = Cursor::new(zip_file.bytes()?);
let mut archive = ZipArchive::new(cursor)?;
let file = File::open(&zip_file)?;
let mut archive = ZipArchive::new(file)?;
let mut asset_count = 0;
+1 -1
View File
@@ -7,7 +7,7 @@ mod service;
mod tokenizer;
mod util;
pub use db::{YomitanProgress, YomitanRow, YomitanZipImportResult, ZipSource};
pub use db::{YomitanProgress, YomitanRow, YomitanZipImportResult};
pub use error::CJDicError;
pub use service::{AppService, SqlParam, YomitanDictEntry};
pub use tokenizer::TokenizeSegment;
+8 -9
View File
@@ -7,7 +7,7 @@ use rusqlite::{Connection, params_from_iter};
use serde::{Deserialize, Serialize};
use crate::{
Timer, ZipSource,
Timer,
db::{
DBFILE, Database, DbChild, YomitanProgress, YomitanRow, YomitanWriter,
YomitanZipImportResult,
@@ -40,6 +40,7 @@ pub enum SqlParam {
Bool(bool),
}
#[derive(Clone)]
pub struct AppService {
db: Database,
tokenizer: Tokenizer,
@@ -163,24 +164,23 @@ impl AppService {
Ok(out)
}
pub fn load_yomitan_zip_dir<Z, LoadCallback, ImportCallback>(
pub fn load_yomitan_zip_dir<LoadCallback, ImportCallback>(
&self,
zip_dir: Vec<Z>,
zip_dir: Vec<PathBuf>,
asset_dir: &PathBuf,
lang: &str,
load_callback: LoadCallback,
import_callback: ImportCallback,
) -> Result<LoadYomitanZipDirResult, CJDicError>
where
Z: ZipSource,
LoadCallback: Fn(LoadYomitanZipDirResult),
ImportCallback: Fn(YomitanProgress),
{
let mut dir_zip_map: HashMap<String, &Z> = HashMap::new();
let mut dir_zip_map: HashMap<String, &PathBuf> = HashMap::new();
let mut zip_dir_ord: HashMap<String, usize> = HashMap::new();
for (i, entry) in zip_dir.iter().enumerate() {
let filename = entry.file_name();
let filename = entry.file_name().and_then(|n| n.to_str()).unwrap_or("");
dir_zip_map.insert(filename.to_string(), entry);
zip_dir_ord.insert(filename.to_string(), i);
}
@@ -276,15 +276,14 @@ impl AppService {
})
}
pub fn import_yomitan_zip_file<Z, Callback>(
pub fn import_yomitan_zip_file<Callback>(
writer: &mut YomitanWriter, // Reuse existing connection
zip_file: &Z,
zip_file: &PathBuf,
asset_dir: &PathBuf,
lang: &str,
progress_callback: Callback,
) -> Result<YomitanZipImportResult, CJDicError>
where
Z: ZipSource,
Callback: Fn(YomitanProgress),
{
Ok(writer.import_dictionary_zip_file(zip_file, asset_dir, lang, progress_callback)?)
+1 -1
View File
@@ -41,7 +41,7 @@ android {
}
buildTypes {
getByName("debug") {
applicationIdSuffix = ".dev"
// applicationIdSuffix = ".dev"
manifestPlaceholders["usesCleartextTraffic"] = "true"
isDebuggable = true
isJniDebuggable = true
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

@@ -1,4 +0,0 @@
<resources>
<string name="app_name">cjdic2 (debug)</string>
<string name="main_activity_title">cjdic2 (debug)</string>
</resources>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 163 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 974 B

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 903 B

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 232 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 961 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 937 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

+25 -16
View File
@@ -59,26 +59,35 @@ pub async fn init_yomitan(
.map(|d| data_dir.join(&d.filepath))
.collect();
let update_count = Cell::new(0usize);
let state = state.inner().clone();
let app_clone = app.clone();
state.load_yomitan_zip_dir(
zip_files,
&yomitan_assets,
lang.as_str(),
|r| {
update_count.set(update_count.get() + r.new_dicts.len() + r.to_be_removed_dicts.len());
app.emit("load-yomitan-dir", r).unwrap();
},
|r| {
update_count.set(update_count.get() + 1);
app.emit("yomitan-import-progress", r).unwrap();
},
)?;
let update_count = tokio::task::spawn_blocking(move || {
let update_count = Cell::new(0usize);
if update_count.get() > 0 {
state.load_yomitan_zip_dir(
zip_files,
&yomitan_assets,
lang.as_str(),
|r| {
update_count
.set(update_count.get() + r.new_dicts.len() + r.to_be_removed_dicts.len());
app.emit("load-yomitan-dir", r).unwrap();
},
|r| {
update_count.set(update_count.get() + 1);
app.emit("yomitan-import-progress", r).unwrap();
},
)?;
Ok::<usize, CJDicError>(update_count.get())
})
.await
.map_err(|e| CJDicError::Error(e.to_string()))??;
if update_count > 0 {
println!("Request app restart?",);
// Request app restart anyway
app.request_restart();
app_clone.request_restart();
}
Ok(())