feat: 计算缓存文件夹大小

This commit is contained in:
qier222 2022-05-13 18:18:28 +08:00
parent c3ae012d06
commit ca4725a46e
No known key found for this signature in database
GPG Key ID: 9C85007ED905F14D
4 changed files with 46 additions and 18 deletions

View File

@ -9,6 +9,9 @@ import { TypedElectronStore } from './index'
import { APIs } from '../shared/CacheAPIs'
import { YPMTray } from './tray'
import { Thumbar } from './windowsTaskbar'
import fastFolderSize from 'fast-folder-size'
import path from 'path'
import prettyBytes from 'pretty-bytes'
const on = <T extends keyof IpcChannelsParams>(
channel: T,
@ -121,6 +124,20 @@ function initOtherIpcMain() {
cache.set(APIs.CoverColor, { id, color })
})
/**
*
*/
on(IpcChannels.GetAudioCacheSize, event => {
fastFolderSize(
path.join(app.getPath('userData'), './audio_cache'),
(error, bytes) => {
if (error) throw error
event.returnValue = prettyBytes(bytes ?? 0)
}
)
})
/**
* tables到json文件便table大小dev环境
*/

View File

@ -26,7 +26,8 @@
"electron-log": "^4.4.6",
"electron-store": "^8.0.1",
"express": "^4.18.1",
"fast-folder-size": "^1.6.1"
"fast-folder-size": "^1.6.1",
"pretty-bytes": "^6.0.0"
},
"devDependencies": {
"@electron/universal": "1.2.1",

View File

@ -3,24 +3,25 @@ import { RepeatMode } from './playerDataTypes'
import { Store } from '@/shared/store'
export const enum IpcChannels {
ClearAPICache = 'clear-api-cache',
Minimize = 'minimize',
MaximizeOrUnmaximize = 'maximize-or-unmaximize',
Close = 'close',
IsMaximized = 'is-maximized',
GetApiCacheSync = 'get-api-cache-sync',
DevDbExportJson = 'dev-db-export-json',
CacheCoverColor = 'cache-cover-color',
SetTrayTooltip = 'set-tray-tooltip',
ClearAPICache = 'ClearAPICache',
Minimize = 'Minimize',
MaximizeOrUnmaximize = 'MaximizeOrUnmaximize',
Close = 'Close',
IsMaximized = 'IsMaximized',
GetApiCacheSync = 'GetApiCacheSync',
DevDbExportJson = 'DevDbExportJson',
CacheCoverColor = 'CacheCoverColor',
SetTrayTooltip = 'SetTrayTooltip',
// 准备三个播放相关channel, 为 mpris 预留接口
Play = 'play',
Pause = 'pause',
PlayOrPause = 'play-or-pause',
Next = 'next',
Previous = 'previous',
Like = 'like',
Repeat = 'repeat',
SyncSettings = 'sync-settings',
Play = 'Play',
Pause = 'Pause',
PlayOrPause = 'PlayOrPause',
Next = 'Next',
Previous = 'Previous',
Like = 'Like',
Repeat = 'Repeat',
SyncSettings = 'SyncSettings',
GetAudioCacheSize = 'GetAudioCacheSize',
}
// ipcMain.on params
@ -54,6 +55,7 @@ export interface IpcChannelsParams {
mode: RepeatMode
}
[IpcChannels.SyncSettings]: Store['settings']
[IpcChannels.GetAudioCacheSize]: void
}
// ipcRenderer.on params
@ -74,4 +76,5 @@ export interface IpcChannelsReturns {
[IpcChannels.Previous]: void
[IpcChannels.Like]: void
[IpcChannels.Repeat]: RepeatMode
[IpcChannels.GetAudioCacheSize]: void
}

View File

@ -54,6 +54,7 @@ importers:
picocolors: ^1.0.0
prettier: '*'
prettier-plugin-tailwindcss: ^0.1.10
pretty-bytes: ^6.0.0
typescript: '*'
wait-on: ^6.0.1
dependencies:
@ -69,6 +70,7 @@ importers:
express: 4.18.1
fast-folder-size: 1.6.2
NeteaseCloudMusicApi: 4.5.14
pretty-bytes: 6.0.0
devDependencies:
'@electron/universal': 1.2.1
'@types/better-sqlite3': 7.5.0
@ -6890,6 +6892,11 @@ packages:
hasBin: true
dev: true
/pretty-bytes/6.0.0:
resolution: {integrity: sha512-6UqkYefdogmzqAZWzJ7laYeJnaXDy2/J+ZqiiMtS7t7OfpXWTlaeGMwX8U6EFvPV/YWWEKRkS8hKS4k60WHTOg==}
engines: {node: ^14.13.1 || >=16.0.0}
dev: false
/pretty-format/27.5.1:
resolution: {integrity: sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==}
engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}