Compare commits
2 Commits
d7aeb00212
...
c63da5222e
Author | SHA1 | Date | |
---|---|---|---|
|
c63da5222e | ||
|
32e797f35d |
@ -48,8 +48,12 @@ pub async fn scan_directory(target: String) -> Result<Vec<FileItem>, String> {
|
|||||||
if !entry.path().is_file() {
|
if !entry.path().is_file() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let (width, height) = image::image_dimensions(entry.path())
|
let image_detect_result = image::image_dimensions(entry.path());
|
||||||
.map_err(|_e| format!("读取图片文件 {} 元信息失败。", entry.path().display()))?;
|
if image_detect_result.is_err() {
|
||||||
|
println!("读取图片文件 {} 元信息失败。", entry.path().display());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let (width, height) = image_detect_result.unwrap();
|
||||||
let file_hash_id = entry
|
let file_hash_id = entry
|
||||||
.path()
|
.path()
|
||||||
.to_str()
|
.to_str()
|
||||||
@ -60,20 +64,27 @@ pub async fn scan_directory(target: String) -> Result<Vec<FileItem>, String> {
|
|||||||
let filename = entry
|
let filename = entry
|
||||||
.path()
|
.path()
|
||||||
.file_name()
|
.file_name()
|
||||||
.ok_or(String::from("不能获取到文件名。"))?
|
.ok_or(String::from("不能获取到文件名。"))
|
||||||
.to_owned()
|
.map(ToOwned::to_owned)
|
||||||
.into_string()
|
.map(|s| s.into_string().unwrap());
|
||||||
.unwrap();
|
if filename.is_err() {
|
||||||
|
println!("不能获取到文件 {} 文件名。", entry.path().display());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let path = entry
|
let path = entry
|
||||||
.path()
|
.path()
|
||||||
.clone()
|
.clone()
|
||||||
.to_str()
|
.to_str()
|
||||||
.ok_or(String::from("不能获取到文件路径。"))?
|
.ok_or(String::from("不能获取到文件路径。"))
|
||||||
.to_string();
|
.map(ToString::to_string);
|
||||||
|
if path.is_err() {
|
||||||
|
println!("不能获取到文件 {} 路径。", entry.path().display());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
file_items.push(FileItem {
|
file_items.push(FileItem {
|
||||||
id: file_hash_id,
|
id: file_hash_id,
|
||||||
filename,
|
filename: filename.unwrap(),
|
||||||
path,
|
path: path.unwrap(),
|
||||||
height,
|
height,
|
||||||
width,
|
width,
|
||||||
});
|
});
|
||||||
|
@ -4,7 +4,7 @@ import { ActionIcon, Box, Flex, Stack, Text, Tooltip } from '@mantine/core';
|
|||||||
import { notifications } from '@mantine/notifications';
|
import { notifications } from '@mantine/notifications';
|
||||||
import { IconEye, IconSquareMinus, IconSquarePlus } from '@tabler/icons-react';
|
import { IconEye, IconSquareMinus, IconSquarePlus } from '@tabler/icons-react';
|
||||||
import { invoke } from '@tauri-apps/api';
|
import { invoke } from '@tauri-apps/api';
|
||||||
import { equals, isEmpty, isNil, length, map, not } from 'ramda';
|
import { equals, isEmpty, isNil, map, not } from 'ramda';
|
||||||
import { FC, PropsWithChildren, useCallback, useContext, useState } from 'react';
|
import { FC, PropsWithChildren, useCallback, useContext, useState } from 'react';
|
||||||
import { useMeasure, useMount } from 'react-use';
|
import { useMeasure, useMount } from 'react-use';
|
||||||
import { EventBusContext } from '../EventBus';
|
import { EventBusContext } from '../EventBus';
|
||||||
@ -69,7 +69,6 @@ const Branch: FC<PropsWithChildren<{ current: DirItem; expanded: boolean }>> = (
|
|||||||
try {
|
try {
|
||||||
selectDir(current.id);
|
selectDir(current.id);
|
||||||
const files = await invoke('scan_directory', { target: current.path });
|
const files = await invoke('scan_directory', { target: current.path });
|
||||||
console.log('[debug]获取到文件个数:', length(files));
|
|
||||||
storeFiles(files);
|
storeFiles(files);
|
||||||
ebus.emit('reset_views');
|
ebus.emit('reset_views');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -122,7 +121,6 @@ export const DirTree: FC = () => {
|
|||||||
const [viewRef, { width }] = useMeasure();
|
const [viewRef, { width }] = useMeasure();
|
||||||
|
|
||||||
const handleFocusAction = useCallback(() => {
|
const handleFocusAction = useCallback(() => {
|
||||||
console.log('[debug]focus action: ', focused, selected);
|
|
||||||
if (isNil(focused) && not(isNil(selected))) {
|
if (isNil(focused) && not(isNil(selected))) {
|
||||||
focus(selected);
|
focus(selected);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user