This commit is contained in:
2026-04-12 23:55:54 +08:00
parent cc4ccac5b1
commit 3f180729b3
8 changed files with 72 additions and 9 deletions

View File

@@ -12,6 +12,7 @@
"dependencies": {
"@ant-design/icons": "^6.1.1",
"@tauri-apps/api": "^2",
"@tauri-apps/plugin-fs": "^2.5.0",
"@tauri-apps/plugin-opener": "^2",
"antd": "^6.3.5",
"react": "^18.3.1",

26
src-tauri/Cargo.lock generated
View File

@@ -1815,6 +1815,7 @@ dependencies = [
"serde_json",
"tauri",
"tauri-build",
"tauri-plugin-fs",
"tauri-plugin-opener",
]
@@ -3457,6 +3458,7 @@ checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272"
dependencies = [
"bitflags 2.11.0",
"block2",
"libc",
"objc2",
"objc2-core-foundation",
]
@@ -5190,6 +5192,30 @@ dependencies = [
"walkdir",
]
[[package]]
name = "tauri-plugin-fs"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36e1ec28b79f3d0683f4507e1615c36292c0ea6716668770d4396b9b39871ed8"
dependencies = [
"anyhow",
"dunce",
"glob",
"log",
"objc2-foundation",
"percent-encoding",
"schemars 0.8.22",
"serde",
"serde_json",
"serde_repr",
"tauri",
"tauri-plugin",
"tauri-utils",
"thiserror 2.0.18",
"toml 0.9.12+spec-1.1.0",
"url",
]
[[package]]
name = "tauri-plugin-opener"
version = "2.5.3"

View File

@@ -27,4 +27,5 @@ tauri = { version = "2", features = [] }
tauri-plugin-opener = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tauri-plugin-fs = "2.5.0"

View File

@@ -5,6 +5,20 @@
"windows": ["main"],
"permissions": [
"core:default",
"opener:default"
"opener:default",
"fs:default",
{
"identifier": "fs:allow-read",
"allow": [{ "path": "**" }]
},
{
"identifier": "fs:allow-write",
"allow": [{ "path": "**" }]
},
{
"identifier": "fs:allow-mkdir",
"allow": [{ "path": "**" }]
},
"fs:allow-exists"
]
}

View File

@@ -202,7 +202,13 @@ fn detect_file_type(filename: &str, data: &[u8]) -> (EntryType, Option<ScriptTyp
fn list_fs_directory(path: &Path) -> Result<Vec<Entry>> {
let mut result = Vec::new();
for entry in std::fs::read_dir(path)? {
let entry = entry?;
let entry = match entry {
Ok(e) => e,
Err(e) => {
eprintln!("无法读取目录项: {}", e);
continue;
}
};
let metadata = entry.metadata()?;
let is_dir = metadata.is_dir();
let name = entry.file_name().to_string_lossy().to_string();
@@ -372,9 +378,13 @@ fn list_archive_directory_in_archive<'a>(
Ok(result)
}
fn set_last_directory(app: &AppHandle, dir: &str) -> Result<()> {
let path = app.path().app_data_dir()?.join("last_directory.txt");
std::fs::write(path, dir)?;
fn set_last_directory(app: &AppHandle, data: &str) -> Result<()> {
let dir = app.path().app_data_dir()?;
if !dir.exists() {
std::fs::create_dir_all(&dir)?;
}
let path = dir.join("last_directory.txt");
std::fs::write(path, data)?;
Ok(())
}

View File

@@ -4,6 +4,7 @@ mod backend;
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_fs::init())
.invoke_handler(tauri::generate_handler![
backend::get_start_directory,
backend::get_xp3_supported_games,

View File

@@ -131,15 +131,18 @@ export function ImagePreviewPanel({ path, options }: ImagePreviewPanelProps) {
const rw = cw / w;
const rh = ch / h;
const dpr = window.devicePixelRatio || 1;
const scale100 = 1 / dpr;
if (mode === 'fit') return Math.min(1, rw, rh); // 只缩小不放大
if (mode === 'fit') return Math.min(scale100, rw, rh); // 只缩小不放大 (基于物理像素的100%)
if (mode === 'fill') return Math.max(rw, rh); // 可以放大超过100%
if (mode === '100%') return 1;
if (mode === '100%') return scale100;
return cScale;
};
const currentScale = getScale();
const stateRef = useRef({ imageSize, containerSize, scaleMode, customScale, position });
stateRef.current = { imageSize, containerSize, scaleMode, customScale, position };
@@ -253,7 +256,7 @@ export function ImagePreviewPanel({ path, options }: ImagePreviewPanelProps) {
{/* Info Status */}
<div style={infoContainerStyle}>
<span style={{ fontSize: 12, color: 'rgba(0,0,0,0.7)', fontWeight: 'bold', fontFamily: 'monospace' }}>
{Math.round(currentScale * 100)}%
{Math.round(currentScale * (window.devicePixelRatio || 1) * 100)}%
{imageSize && ` | ${imageSize.w} x ${imageSize.h}`}
</span>
</div>

View File

@@ -919,7 +919,7 @@
resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.60.1.tgz#23b860113e9f87eea015d1fa3a4240a52b42fcd4"
integrity sha512-lWMnixq/QzxyhTV6NjQJ4SFo1J6PvOX8vUx5Wb4bBPsEb+8xZ89Bz6kOXpfXj9ak9AHTQVQzlgzBEc1SyM27xQ==
"@tauri-apps/api@^2", "@tauri-apps/api@^2.8.0":
"@tauri-apps/api@^2", "@tauri-apps/api@^2.10.1", "@tauri-apps/api@^2.8.0":
version "2.10.1"
resolved "https://registry.yarnpkg.com/@tauri-apps/api/-/api-2.10.1.tgz#57c1bae6114ec33d977eb2b50dfefc25fa84fc93"
integrity sha512-hKL/jWf293UDSUN09rR69hrToyIXBb8CjGaWC7gfinvnQrBVvnLr08FeFi38gxtugAVyVcTa5/FD/Xnkb1siBw==
@@ -996,6 +996,13 @@
"@tauri-apps/cli-win32-ia32-msvc" "2.10.1"
"@tauri-apps/cli-win32-x64-msvc" "2.10.1"
"@tauri-apps/plugin-fs@^2.5.0":
version "2.5.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/plugin-fs/-/plugin-fs-2.5.0.tgz#977d31ceb6aad600817aaa5233e0d86aee500aad"
integrity sha512-c83kbz61AK+rKjhS+je9+stIO27nXj7p9cqeg36TwkIUtxpCFTttlHHtqon6h6FN54cXjyAjlMPOJcW3mwE5XQ==
dependencies:
"@tauri-apps/api" "^2.10.1"
"@tauri-apps/plugin-opener@^2":
version "2.5.3"
resolved "https://registry.yarnpkg.com/@tauri-apps/plugin-opener/-/plugin-opener-2.5.3.tgz#09f8fe143567839cc491f4f8fde21caa0f1a8b89"