feat: updates

This commit is contained in:
qier222 2023-01-24 16:29:33 +08:00
parent c6c59b2cd9
commit 7ce516877e
No known key found for this signature in database
63 changed files with 6591 additions and 1107 deletions

View file

@ -12,7 +12,6 @@ import { Thumbar } from './windowsTaskbar'
import fastFolderSize from 'fast-folder-size'
import path from 'path'
import prettyBytes from 'pretty-bytes'
import { getArtist, getAlbum } from './appleMusic'
const on = <T extends keyof IpcChannelsParams>(
channel: T,
@ -23,10 +22,7 @@ const on = <T extends keyof IpcChannelsParams>(
const handle = <T extends keyof IpcChannelsParams>(
channel: T,
listener: (
event: Electron.IpcMainInvokeEvent,
params: IpcChannelsParams[T]
) => void
listener: (event: Electron.IpcMainInvokeEvent, params: IpcChannelsParams[T]) => void
) => {
return ipcMain.handle(channel, listener)
}
@ -162,49 +158,46 @@ function initOtherIpcMain() {
*
*/
on(IpcChannels.GetAudioCacheSize, event => {
fastFolderSize(
path.join(app.getPath('userData'), './audio_cache'),
(error, bytes) => {
if (error) throw error
fastFolderSize(path.join(app.getPath('userData'), './audio_cache'), (error, bytes) => {
if (error) throw error
event.returnValue = prettyBytes(bytes ?? 0)
}
)
event.returnValue = prettyBytes(bytes ?? 0)
})
})
/**
* Apple Music获取专辑信息
*/
handle(
IpcChannels.GetAlbumFromAppleMusic,
async (event, { id, name, artist }) => {
const fromCache = cache.get(APIs.AppleMusicAlbum, { id })
if (fromCache) {
return fromCache === 'no' ? undefined : fromCache
}
// handle(
// IpcChannels.GetAlbumFromAppleMusic,
// async (event, { id, name, artist }) => {
// const fromCache = cache.get(APIs.AppleMusicAlbum, { id })
// if (fromCache) {
// return fromCache === 'no' ? undefined : fromCache
// }
const fromApple = await getAlbum({ name, artist })
cache.set(APIs.AppleMusicAlbum, { id, album: fromApple })
return fromApple
}
)
// const fromApple = await getAlbum({ name, artist })
// cache.set(APIs.AppleMusicAlbum, { id, album: fromApple })
// return fromApple
// }
// )
/**
* Apple Music获取歌手信息
**/
handle(IpcChannels.GetArtistFromAppleMusic, async (event, { id, name }) => {
const fromApple = await getArtist(name)
cache.set(APIs.AppleMusicArtist, { id, artist: fromApple })
return fromApple
})
// /**
// * 从Apple Music获取歌手信息
// **/
// handle(IpcChannels.GetArtistFromAppleMusic, async (event, { id, name }) => {
// const fromApple = await getArtist(name)
// cache.set(APIs.AppleMusicArtist, { id, artist: fromApple })
// return fromApple
// })
/**
* Apple Music歌手信息
*/
on(IpcChannels.GetArtistFromAppleMusic, (event, { id }) => {
const artist = cache.get(APIs.AppleMusicArtist, id)
event.returnValue = artist === 'no' ? undefined : artist
})
// /**
// * 从缓存读取Apple Music歌手信息
// */
// on(IpcChannels.GetArtistFromAppleMusic, (event, { id }) => {
// const artist = cache.get(APIs.AppleMusicArtist, id)
// event.returnValue = artist === 'no' ? undefined : artist
// })
/**
* 退