Skip to content

Commit

Permalink
✨ feat: cache management & ncm default quality
Browse files Browse the repository at this point in the history
Signed-off-by: SimonShiki <[email protected]>
  • Loading branch information
SimonShiki committed Aug 13, 2024
1 parent 474045f commit f0a54e1
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 72 deletions.
15 changes: 14 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,63 @@
{
"+0X5KL": "Scanning...",
"+wbheR": "Hi-Res",
"/GCoTA": "Clear",
"/clOBU": "Weekly",
"0+uHjb": "A - Z",
"2/2yg+": "Add",
"3HBU/l": "Remote Songlist",
"47FYwb": "Cancel",
"4cTGtq": "Sync song lists",
"5sg7KC": "Password",
"5ztrr5": "Cache remote songs in local",
"6/NYCb": "Streaming does not currently support adjusting playback progress",
"A+Fjz9": "Use streaming (Experimental)",
"AbbGDv": "Each startup",
"AxMhQr": "High",
"AzGCoc": "Cicadas",
"D3idYv": "Settings",
"D9WUz8": "Albums",
"D9n+q2": "Random",
"DBiVK1": "Cache",
"DUIDEq": "Storage",
"F62y+K": "Sign Out",
"FpsJ5J": "163 Account",
"HAlOn1": "Name",
"J3ca41": "Play",
"MMDobX": "WebDAV",
"O95R3Z": "Phone",
"OI9isw": "NetEase Cloud Music",
"Pfa+Li": "Remote storages",
"Q//GSE": "{megabyte} MB",
"QOZT71": "Scan folders",
"QqmO+m": "{total} Songs",
"Ra3++g": "NCM",
"S4KbuN": "HD Surround",
"StcK67": "Library",
"Ub+AGc": "Sign In",
"W4SaxY": "Local",
"ZaKnsn": "Sign in to get the song list...",
"ZqtXuy": "Scan storages",
"bkZwUW": "Very High",
"cb2kY6": "Standard",
"cyR7Kh": "Back",
"du1laW": "Never",
"e0bM5J": "Use QRCode",
"eJzYtm": "Z - A",
"gjBiyj": "Loading...",
"gwY3ZA": "Default song quality",
"hP4Dbx": "Time (Reversed)",
"i+P3rZ": "Auto-scanning behavior",
"j+BR5t": "Songlists",
"j6k/s2": "Immersive Surround",
"lKv8ex": "Default",
"lw/ZSC": "Lossless",
"m6bUGd": "Sort By:",
"mOFG3K": "Start",
"pLEcFz": "Multiselect",
"pY1mMS": "Songs",
"sVX1a7": "Folders to scan",
"sm72ff": "Playlist ({total})",
"uDgZjf": "Ultra HD Mastering",
"ug01Mk": "Time",
"xMnH8F": "Load More",
"xmcVZ0": "Search",
Expand Down
15 changes: 14 additions & 1 deletion locales/zh-cn.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,61 @@
{
"+0X5KL": "扫描中...",
"+wbheR": "Hi-Res",
"/GCoTA": "清除",
"/clOBU": "每周",
"0+uHjb": "A - Z",
"2/2yg+": "添加",
"3HBU/l": "远程歌单",
"4cTGtq": "同步歌单",
"5sg7KC": "密码",
"47FYwb": "取消",
"5ztrr5": "在本地缓存远程歌曲",
"6/NYCb": "流式播放目前不支持调整播放进度",
"A+Fjz9": "流式播放 (实验性)",
"AbbGDv": "每次启动时",
"AxMhQr": "较高",
"AzGCoc": "知音",
"D3idYv": "设置",
"D9WUz8": "专辑",
"D9n+q2": "随机播放",
"DBiVK1": "缓存",
"DUIDEq": "存储",
"F62y+K": "登出",
"FpsJ5J": "网易账户",
"HAlOn1": "名字",
"J3ca41": "播放",
"MMDobX": "WebDAV",
"O95R3Z": "手机号",
"OI9isw": "网易云音乐",
"Ra3++g": "网易云音乐",
"Pfa+Li": "远程存储",
"Q//GSE": "{megabyte} MB",
"QOZT71": "扫描",
"QqmO+m": "{total} 首歌",
"StcK67": "音乐库",
"S4KbuN": "高清环绕声",
"Ub+AGc": "登录",
"W4SaxY": "本地",
"ZaKnsn": "登录以获取个人歌单...",
"ZqtXuy": "扫描",
"bkZwUW": "极高",
"cb2kY6": "标准",
"cyR7Kh": "返回",
"du1laW": "永不",
"e0bM5J": "扫码登录",
"eJzYtm": "Z - A",
"hP4Dbx": "时间倒序",
"gjBiyj": "加载中...",
"gwY3ZA": "默认音质",
"i+P3rZ": "自动扫描行为",
"m6bUGd": "排序方式",
"mOFG3K": "开始",
"pLEcFz": "多选",
"j6k/s2": "沉浸环绕声",
"lKv8ex": "默认",
"lw/ZSC": "无损",
"sVX1a7": "要扫描的文件夹",
"sm72ff": "播放列表 ({total})",
"uDgZjf": "超清母带",
"ug01Mk": "时间顺序",
"xMnH8F": "加载更多",
"y1Z3or": "语言",
Expand Down
31 changes: 27 additions & 4 deletions src-tauri/src/cache_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub struct CacheManager {
}

struct CacheItem {
id: u64,
path: PathBuf,
size: u64,
last_accessed: std::time::SystemTime,
Expand Down Expand Up @@ -55,7 +54,6 @@ impl CacheManager {
.unwrap_or(0);

let item = CacheItem {
id,
path: entry.path(),
size: metadata.len(),
last_accessed: metadata.modified().unwrap_or_else(|_| std::time::SystemTime::now()),
Expand Down Expand Up @@ -94,7 +92,6 @@ impl CacheManager {
items.insert(
id,
CacheItem {
id,
path: file_path,
size: data.len() as u64,
last_accessed: std::time::SystemTime::now(),
Expand Down Expand Up @@ -124,6 +121,22 @@ impl CacheManager {

Ok(())
}

pub fn get_cache_size(&self) -> u64 {
*self.current_cache_size.lock().unwrap()
}

pub fn clear_cache(&self) -> Result<(), String> {
let mut items = self.cache_items.lock().unwrap();
let mut current_size = self.current_cache_size.lock().unwrap();

for (_, item) in items.drain() {
fs::remove_file(&item.path).map_err(|e| e.to_string())?;
}

*current_size = 0;
Ok(())
}
}

#[tauri::command]
Expand All @@ -134,4 +147,14 @@ pub fn get_cached_song(id: u64, state: State<CacheManagerState>) -> Option<Vec<u
#[tauri::command]
pub fn cache_song(id: u64, data: Vec<u8>, state: State<CacheManagerState>) -> Result<(), String> {
state.0.cache_song(id, &data)
}
}

#[tauri::command]
pub fn get_cache_size(state: State<CacheManagerState>) -> u64 {
state.0.get_cache_size()
}

#[tauri::command]
pub fn clear_cache(state: State<CacheManagerState>) -> Result<(), String> {
state.0.clear_cache()
}
2 changes: 2 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ pub async fn run() {
local_scanner::scan_folder,
cache_manager::get_cached_song,
cache_manager::cache_song,
cache_manager::get_cache_size,
cache_manager::clear_cache,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
5 changes: 0 additions & 5 deletions src/pages/ncm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ import SonglistItem from '../components/songlist-item';
import { FormattedMessage, useIntl } from 'react-intl';
import Pagination from '../components/base/pagination';

interface NCMProfile {
nickname: string;
avatarUrl: string;
}

const ncmStorageConfigJotai = focusAtom(storagesConfigJotai, (optic) => optic.prop('ncm')) as unknown as WritableAtom<NCMConfig, [SetStateAction<NCMConfig>], void>;
const ncmStorageJotai = focusAtom(storagesJotai, (optic) => optic.prop('ncm'));
const profileJotai = focusAtom(ncmStorageConfigJotai, (optic) => optic.prop('profile'));
Expand Down
Loading

0 comments on commit f0a54e1

Please sign in to comment.