This commit is contained in:
qier222 2023-09-04 12:51:56 +08:00
parent 32050e4553
commit 6aee8ae38e
No known key found for this signature in database
41 changed files with 523 additions and 415 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 80 KiB

Before After
Before After

View file

@ -13,6 +13,7 @@ import fastFolderSize from 'fast-folder-size'
import path from 'path'
import prettyBytes from 'pretty-bytes'
import { db, Tables } from './db'
import { promisify } from 'util'
log.info('[electron] ipcMain.ts')
@ -137,15 +138,15 @@ function initOtherIpcMain() {
/**
* API缓存
*/
on(IpcChannels.ClearAPICache, () => {
// db.truncate(Tables.Track)
// db.truncate(Tables.Album)
// db.truncate(Tables.Artist)
// db.truncate(Tables.Playlist)
// db.truncate(Tables.ArtistAlbum)
// db.truncate(Tables.AccountData)
// db.truncate(Tables.Audio)
// db.vacuum()
handle(IpcChannels.ClearAPICache, async () => {
db.truncate(Tables.Track)
db.truncate(Tables.Album)
db.truncate(Tables.Artist)
db.truncate(Tables.Playlist)
db.truncate(Tables.ArtistAlbum)
db.truncate(Tables.AccountData)
db.truncate(Tables.Audio)
db.vacuum()
})
/**
@ -170,6 +171,31 @@ function initOtherIpcMain() {
}
})
// 获取缓存位置
handle(IpcChannels.GetCachePath, async () => {
return path.join(app.getPath('userData'), './audio_cache')
})
/**
*
*/
handle(IpcChannels.GetAudioCacheSize, async () => {
const fastFolderSizeAsync = promisify(fastFolderSize)
const bytes = await fastFolderSizeAsync(path.join(app.getPath('userData'), './audio_cache'))
return prettyBytes(bytes ?? 0)
})
handle(IpcChannels.ClearAudioCache, async () => {
try {
const audioCachePath = path.join(app.getPath('userData'), './audio_cache')
fs.rmdirSync(audioCachePath, { recursive: true })
fs.mkdirSync(audioCachePath)
return true
} catch (e) {
return false
}
})
/**
*
*/
@ -178,17 +204,6 @@ function initOtherIpcMain() {
cache.set(CacheAPIs.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)
})
})
/**
* Apple Music获取专辑信息
*/
@ -235,30 +250,26 @@ function initOtherIpcMain() {
* tables到json文件便table大小dev环境
*/
if (process.env.NODE_ENV === 'development') {
// on(IpcChannels.DevDbExportJson, () => {
// const tables = [
// Tables.ArtistAlbum,
// Tables.Playlist,
// Tables.Album,
// Tables.Track,
// Tables.Artist,
// Tables.Audio,
// Tables.AccountData,
// Tables.Lyric,
// ]
// tables.forEach(table => {
// const data = db.findAll(table)
// fs.writeFile(
// `./tmp/${table}.json`,
// JSON.stringify(data),
// function (err) {
// if (err) {
// return console.log(err)
// }
// console.log('The file was saved!')
// }
// )
// })
// })
on(IpcChannels.DevDbExportJson, () => {
const tables = [
Tables.ArtistAlbum,
Tables.Playlist,
Tables.Album,
Tables.Track,
Tables.Artist,
Tables.Audio,
Tables.AccountData,
Tables.Lyrics,
]
tables.forEach(table => {
const data = db.findAll(table)
fs.writeFile(`./tmp/${table}.json`, JSON.stringify(data), function (err) {
if (err) {
return console.log(err)
}
console.log('The file was saved!')
})
})
})
}
}

View file

@ -27,7 +27,7 @@
"@fastify/static": "^6.6.1",
"@sentry/electron": "^3.0.7",
"NeteaseCloudMusicApi": "^4.8.9",
"better-sqlite3": "8.1.0",
"better-sqlite3": "8.3.0",
"change-case": "^4.1.2",
"compare-versions": "^4.1.3",
"electron-log": "^4.4.8",
@ -39,12 +39,12 @@
"ytdl-core": "^4.11.2"
},
"devDependencies": {
"@types/better-sqlite3": "^7.6.3",
"@types/better-sqlite3": "^7.6.4",
"@vitest/ui": "^0.20.3",
"axios": "^1.3.4",
"cross-env": "^7.0.3",
"dotenv": "^16.0.3",
"electron": "^23.1.4",
"electron": "^24.1.3",
"electron-builder": "23.6.0",
"electron-devtools-installer": "^3.2.0",
"electron-rebuild": "^3.2.9",