feat: updates

This commit is contained in:
qier222 2022-10-28 20:29:04 +08:00
parent a1b0bcf4d3
commit 884f3df41a
No known key found for this signature in database
198 changed files with 4572 additions and 5336 deletions

View file

@ -4,6 +4,7 @@ import duration from 'dayjs/plugin/duration'
import { APIs } from '@/shared/CacheAPIs'
import { average } from 'color.js'
import { colord } from 'colord'
import { supportedLanguages } from '../i18n/i18n'
/**
* @description
@ -71,7 +72,7 @@ export function formatDate(
*/
export function formatDuration(
milliseconds: number,
locale: 'en' | 'zh-TW' | 'zh-CN' = 'zh-CN',
locale: typeof supportedLanguages[number] = 'zh-CN',
format: 'hh:mm:ss' | 'hh[hr] mm[min]' = 'hh:mm:ss'
): string {
dayjs.extend(duration)
@ -87,7 +88,7 @@ export function formatDuration(
: `${mins}:${seconds}`
} else {
const units = {
en: {
'en-US': {
hours: 'hr',
mins: 'min',
},
@ -99,7 +100,7 @@ export function formatDuration(
hours: '小時',
mins: '分鐘',
},
}
} as const
return hours !== '0'
? `${hours} ${units[locale].hours}${
@ -129,15 +130,15 @@ export async function getCoverColor(coverUrl: string) {
return
}
const colorFromCache = window.ipcRenderer?.sendSync(
IpcChannels.GetApiCacheSync,
const colorFromCache: string | undefined = await window.ipcRenderer?.invoke(
IpcChannels.GetApiCache,
{
api: APIs.CoverColor,
query: {
id,
},
}
) as string | undefined
)
return colorFromCache || calcCoverColor(coverUrl)
}