Skip to content

Commit

Permalink
feat: 移动缓存添加提示
Browse files Browse the repository at this point in the history
  • Loading branch information
gizmo-ds committed Oct 11, 2022
1 parent 89f9110 commit d2d2035
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 23 deletions.
19 changes: 6 additions & 13 deletions src-tauri/src/vrchat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn total_cache() -> Option<String> {
}

#[tauri::command]
pub fn move_cache(new_path: &str) -> Result<(), tauri::InvokeError> {
pub async fn move_cache(new_path: &str) -> Result<(), tauri::InvokeError> {
match vrchat_path() {
Some(_vrchat_path) => {
let cache_path = Path::new(_vrchat_path.as_str()).join("Cache-WindowsPlayer");
Expand All @@ -67,18 +67,11 @@ pub fn move_cache(new_path: &str) -> Result<(), tauri::InvokeError> {
return Err(err);
}
let _new_path = new_path.to_string();
std::thread::spawn(move || {
fs_extra::dir::move_dir_with_progress(
cache_path,
_new_path,
&fs_extra::dir::CopyOptions::new(),
|process_info| {
println!("{}", process_info.total_bytes);
fs_extra::dir::TransitProcessResult::ContinueOrAbort
},
)
.unwrap();
});
if let Err(err) =
fs_extra::dir::move_dir(cache_path, _new_path, &fs_extra::dir::CopyOptions::new())
{
return Err(tauri::InvokeError::from(err.to_string()));
}
Ok(())
}
None => Err(tauri::InvokeError::from("vrchat-path-notfound")),
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"windows": [
{
"title": "VRChat Cache Mover",
"width": 850,
"width": 880,
"height": 300,
"resizable": true,
"fullscreen": false,
Expand Down
28 changes: 21 additions & 7 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ app.getVersion().then((version) => (appVersion = version));
let totalCacheSize = $ref("0 B");
let vrchatConfig: cache_directory = $ref({ cache_directory: "" });
let showAdvanced = $ref(false);
let moving = $ref(false);
// 监听 tauri 的文件拖拽事件
listen<string[]>("tauri:https://file-drop", (event) => {
Expand Down Expand Up @@ -58,12 +59,24 @@ const totalCache = () =>
);
totalCache();
const moveCache = () => {
const nh = ElNotification({
message: t("messages.cache-moving"),
type: "info",
showClose: false,
duration: 0,
position: "bottom-right",
});
moving = true;
invoke("move_cache", { newPath: vrchatConfig.cache_directory })
.then(() => {
notification(t("messages.success"), "success", 1500);
.then(() => notification(t("messages.success"), "success", 1500))
.catch((err: string) =>
notification(err.indexOf(" ") > -1 ? err : t(`messages.${err}`), "error")
)
.finally(() => {
moving = false;
totalCache();
})
.catch((err) => notification(t(`messages.${err}`), "error"));
nh.close();
});
};
const removeCache = () => {
invoke("remove_cache")
Expand Down Expand Up @@ -121,7 +134,7 @@ const configChange = () => {
</script>

<template>
<el-config-provider>
<el-config-provider :button="{ autoInsertSpace: true }">
<use-dark v-slot="{ isDark, toggleDark }">
<app-header />

Expand Down Expand Up @@ -176,17 +189,18 @@ const configChange = () => {

<el-button
@click="moveCache"
:disabled="!vrchatConfig.cache_directory || disabled"
:disabled="!vrchatConfig.cache_directory || disabled || moving"
type="warning"
:icon="SwitchHorizontal"
:loading="moving"
>
{{ t("move-cache-button") }}
</el-button>
<el-button
@click="removeCache"
type="danger"
:icon="TrashX"
:disabled="disabled"
:disabled="disabled || moving"
>
{{ t("delete-cache-button") }}
</el-button>
Expand Down
1 change: 1 addition & 0 deletions src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"copy-config-content-button": "Copy Config Content",
"delete-cache-button": "Delete Cache",
"messages.cache-directory-notfound": "Could not find cache directory",
"messages.cache-moving": "Cache is moving, please wait...",
"messages.success": "Success",
"messages.target-directory-not-directory": "Target directory is not a directory",
"messages.target-directory-not-exist": "Target directory does not exist",
Expand Down
1 change: 1 addition & 0 deletions src/locales/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"copy-config-content-button": "構成コンテンツのコピー",
"delete-cache-button": "キャッシュを削除",
"messages.cache-directory-notfound": "キャッシュディレクトリが見つかりませんでした",
"messages.cache-moving": "キャッシュを移動しています。お待ちください...",
"messages.success": "成功",
"messages.target-directory-not-directory": "ターゲットディレクトリはディレクトリではありません",
"messages.target-directory-not-exist": "ターゲットディレクトリが存在しません",
Expand Down
1 change: 1 addition & 0 deletions src/locales/ko-KR.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"copy-config-content-button": "구성 콘텐츠 복사",
"delete-cache-button": "캐시 삭제",
"messages.cache-directory-notfound": "캐시 디렉토리를 찾을 수 없습니다",
"messages.cache-moving": "캐시가 이동 중입니다. 잠시만 기다려 주십시오...",
"messages.success": "성공",
"messages.target-directory-not-directory": "대상 디렉토리가 디렉토리가 아닙니다.",
"messages.target-directory-not-exist": "대상 디렉토리가 존재하지 않습니다",
Expand Down
5 changes: 3 additions & 2 deletions src/locales/zh-CN.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"advanced": "高级。",
"advanced.cache-expiry-delay": "缓存有效期",
"advanced.cache-expiry-delay.suffix": "",
"advanced.cache-expiry-delay.placeholder": "默认: 30",
"advanced.cache-expiry-delay.suffix": "",
"advanced.cache-size": "缓存大小",
"advanced.cache-size.suffix": "GB",
"advanced.cache-size.placeholder": "默认: 20",
"advanced.cache-size.suffix": "GB",
"apply-button": "应用",
"cache-directory": "缓存目录",
"cache-placeholder": "默认位置 (%AppData%\\..\\LocalLow\\VRChat\\VRChat)",
Expand All @@ -14,6 +14,7 @@
"copy-config-content-button": "复制配置内容",
"delete-cache-button": "删除缓存",
"messages.cache-directory-notfound": "未找到原缓存目录",
"messages.cache-moving": "缓存移动中, 请稍后",
"messages.success": "操作成功",
"messages.target-directory-not-directory": "目标目录不是目录",
"messages.target-directory-not-exist": "目标目录不存在",
Expand Down

0 comments on commit d2d2035

Please sign in to comment.