Skip to content

Commit

Permalink
feat:完善自定义缓存路径
Browse files Browse the repository at this point in the history
  • Loading branch information
VirtualHotBar committed Aug 24, 2024
1 parent e757c26 commit 4604065
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "netmount-gui",
"private": true,
"version": "1.1.1",
"version": "1.1.2",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "netmount"
description = "NetMount"
version = "1.1.1"
version = "1.1.2"
authors = ["VirtualHotBar"]
license = "AGPL-3.0"
repository = ""
Expand Down Expand Up @@ -31,7 +31,8 @@ flate2 = { version = "1.0.30", features = ["zlib"] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "2.0.0-rc.0", features = [ "macos-private-api",
tauri = { version = "2.0.0-rc.6", features = [
"macos-private-api",
"devtools",
"tray-icon",
] }
Expand All @@ -42,13 +43,13 @@ rand = "0.8"
reqwest = { version = "0.11", features = ["json", "stream"] }
tokio = { version = "1", features = ["full"] }
futures-util = "0.3"
tauri-plugin-shell = "2.0.0-rc.0"
tauri-plugin-shell = "2.0.0-rc.2"
tauri-plugin-os = "2.0.0-rc.0"
tauri-plugin-fs = "2.0.0-rc.0"
tauri-plugin-process = "2.0.0-rc.0"
tauri-plugin-autostart = "2.0.0-rc.0"
tauri-plugin-single-instance = "2.0.0-rc.0"
tauri-plugin-dialog = "2.0.0-rc.0"
tauri-plugin-dialog = "2.0.0-rc.2"

[target.'cfg(windows)'.dependencies]
winreg = "0.10.1"
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/capabilities/migrated.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
"fs:default",
"shell:default",
"process:default",
"os:default"
"os:default",
"dialog:allow-open"
]
}
6 changes: 5 additions & 1 deletion src-tauri/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -490,5 +490,9 @@
"unable_to_obtain_transmission_speed":"The specific transmission speed may not be available at present, but the transmission is still in progress.",

"temp_path":"Temporary path",
"cache_path":"Cache path"
"cache_path":"Cache path",
"please_select_cache_dir":"Please select a cache directory",
"select":"Select",
"ask_restartself":"Do you want to restart the software?",
"after_changing_the_cache_directory_tips":"After changing the cache directory, please manually clear the old cache directory and restart the software for it to take effect."
}
6 changes: 5 additions & 1 deletion src-tauri/locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -559,5 +559,9 @@
"unable_to_obtain_transmission_speed": "当前可能无法获取具体传输速度,但传输仍在进行。",

"temp_path": "临时路径",
"cache_path": "缓存路径"
"cache_path": "缓存路径",
"please_select_cache_dir": "请选择缓存目录",
"select":"选择",
"ask_restartself":"是否重启软件?",
"after_changing_the_cache_directory_tips":"更改缓存目录后,请手动清理旧缓存目录,重启软件以生效。"
}
6 changes: 5 additions & 1 deletion src-tauri/locales/zh-hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -559,5 +559,9 @@
"unable_to_obtain_transmission_speed":"當前可能無法獲取具體傳送速率,但傳輸仍在進行。",

"temp_path":"臨時路徑",
"cache_path":"緩存路徑"
"cache_path":"緩存路徑",
"please_select_cache_dir":"請選擇緩存路徑",
"select":"選擇",
"ask_restartself":"是否重啓軟件?",
"after_changing_the_cache_directory_tips":"更改緩存目錄後,請手動清理舊緩存目錄,重啓軟件以生效。"
}
11 changes: 8 additions & 3 deletions src/controller/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { nmConfig, readNmConfig, roConfig, saveNmConfig, setNmConfig } from "../services/config"
import { nmConfig, osInfo, readNmConfig, roConfig, saveNmConfig, setNmConfig } from "../services/config"
import { rcloneInfo } from "../services/rclone"
import { rclone_api_post } from "../utils/rclone/request"
import { startUpdateCont } from "./stats/continue"
import { reupMount } from "./storage/mount/mount"
import { reupStorage } from "./storage/storage"
import { listenWindow, windowsHide } from "./window"
import { NMConfig } from "../type/config"
import { randomString, restartSelf, sleep } from "../utils/utils"
import { formatPath, randomString, restartSelf, sleep } from "../utils/utils"
import { t } from "i18next"
import { startRclone, stopRclone } from "../utils/rclone/process"
import { getOsInfo } from "../utils/tauri/osInfo"
Expand Down Expand Up @@ -35,11 +35,11 @@ async function init(setStartStr: Function) {
setStartStr(t('read_config'))
await readNmConfig()


if (nmConfig.settings.startHide) {
windowsHide()
}

//设置语言
if (nmConfig.settings.language) {
await setLocalized(nmConfig.settings.language);
} else {
Expand All @@ -50,6 +50,11 @@ async function init(setStartStr: Function) {
await setLocalized(nmConfig.settings.language);
}

//设置缓存路径
if (!nmConfig.settings.path.cacheDir) {
nmConfig.settings.path.cacheDir=formatPath(roConfig.env.path.homeDir+'/.cache/netmount', osInfo.platform === "windows")
}

setThemeMode(nmConfig.settings.themeMode)

setStartStr(t('start_framework'))
Expand Down
1 change: 0 additions & 1 deletion src/page/other/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { t } from "i18next"

const showLog = (modal: ModalHookReturnType, log: string) => {
modal.info!({

title: t('log'),
content: <div style={{ width: '100%' }}>
<div style={{ height: '15rem', overflowY: 'auto', textAlign: 'justify', margin: '0 auto' }}>
Expand Down
38 changes: 28 additions & 10 deletions src/page/setting/setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import { getVersion } from '@tauri-apps/api/app';
import * as shell from '@tauri-apps/plugin-shell';
import { rcloneInfo } from '../../services/rclone';
import { setLocalized } from '../../controller/language/localized';
import { openUrlInBrowser, set_devtools_state } from '../../utils/utils';
import { formatPath, openUrlInBrowser, restartSelf, set_devtools_state } from '../../utils/utils';
import { showLog } from '../other/modal';
import { alistInfo } from '../../services/alist';
import * as dialog from '@tauri-apps/plugin-dialog';
import { exit } from '../../controller/main';

const CollapseItem = Collapse.Item;
const FormItem = Form.Item;
const Row = Grid.Row;
Expand Down Expand Up @@ -90,16 +93,31 @@ export default function Setting_page() {
}} />
</FormItem>
<FormItem label={t('cache_path')}>
<Input value={nmConfig.settings.path.cacheDir} onChange={(value) => {
nmConfig.settings.path.cacheDir = value
forceUpdate()
}
} onClick={
async () => {
<Input.Group compact>
<Input style={{ width: 'calc(100% - 4rem)' }} value={nmConfig.settings.path.cacheDir} />
<Button style={{ width: '4rem' }} onClick={async () => {
let dirPath = await dialog.open({
title: t('please_select_cache_dir'),
multiple: false,
directory: true,
defaultPath: nmConfig.settings.path.cacheDir
});
dirPath = dirPath ? formatPath(dirPath, osInfo.platform === 'windows') : dirPath
if (dirPath && dirPath !== nmConfig.settings.path.cacheDir) {
nmConfig.settings.path.cacheDir = dirPath
forceUpdate()

Modal.confirm({
title: t('ask_restartself'),
content: t('after_changing_the_cache_directory_tips'),
onOk: () => {
exit(true)
},
});
}
}}>{t('select')}</Button>
</Input.Group>


}
}/>
</FormItem>

<div style={{ width: '100%', textAlign: 'right' }}><Button type='primary' onClick={async () => {
Expand Down
9 changes: 5 additions & 4 deletions src/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ let nmConfig: NMConfig = {
settings: {
themeMode: roConfig.options.setting.themeMode.select[roConfig.options.setting.themeMode.defIndex],
startHide: false,
path:{
cacheDir:"C:/TEST-TEMP"
language: undefined,
path: {
cacheDir: undefined
}
},
framework: {
Expand All @@ -86,9 +87,9 @@ const setNmConfig = (config: NMConfig) => {
}

const readNmConfig = async () => {

await invoke('get_config').then(configData => {

setNmConfig(mergeObjects(nmConfig, configData as NMConfig))
}).catch(err => {
console.log(err);
Expand Down
2 changes: 1 addition & 1 deletion src/type/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface NMConfig {
startHide: boolean,
language?: string,
path: {
cacheDir:string
cacheDir?:string
}
},
notice?: Notice,
Expand Down

0 comments on commit 4604065

Please sign in to comment.