From 2fff8652ca65f7e4887bf419868bc189e8c79e27 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Wed, 30 Aug 2023 14:30:47 +0800 Subject: [PATCH] lint code --- .eslintrc.base.cjs | 2 +- build-config/build-after-pack.js | 2 +- src/common/mainIpc.ts | 4 ++-- src/common/rendererIpc.ts | 2 +- src/common/utils/nodejs.ts | 8 +++---- src/main/app.ts | 2 +- .../commonRenderers/common/rendererEvent.ts | 2 +- .../commonRenderers/list/rendererEvent.ts | 8 +++---- src/main/modules/sync/client/data.ts | 2 ++ .../server/modules/list/sync/localEvent.ts | 1 + src/main/modules/sync/server/user/data.ts | 2 ++ src/main/modules/userApi/index.ts | 2 +- src/main/modules/userApi/main.ts | 1 + src/main/modules/winMain/main.ts | 6 ++--- src/main/modules/winMain/rendererEvent/app.ts | 6 ++--- .../modules/winMain/rendererEvent/download.ts | 2 +- .../winMain/rendererEvent/kw_decodeLyric.ts | 2 +- .../modules/winMain/rendererEvent/music.ts | 18 +++++++-------- .../modules/winMain/rendererEvent/userApi.ts | 4 ++-- src/renderer-lyric/utils/ipc.ts | 2 +- src/renderer/components/base/MusicList.vue | 2 +- .../components/base/useVirtualizedList.ts | 6 ++--- .../components/layout/Toolbar/SearchInput.vue | 2 +- src/renderer/core/music/download.ts | 6 ++--- src/renderer/core/music/index.ts | 18 +++++++-------- src/renderer/core/music/local.ts | 8 +++---- src/renderer/core/music/online.ts | 12 +++++----- src/renderer/core/music/utils.ts | 8 +++---- src/renderer/core/useApp/useInitUserApi.ts | 2 +- src/renderer/store/leaderboard/action.ts | 2 +- .../list/listManage/rendererListManage.ts | 4 ++-- src/renderer/store/search/action.ts | 2 +- src/renderer/store/search/music/action.ts | 2 +- src/renderer/store/search/songlist/action.ts | 2 +- src/renderer/store/songList/action.ts | 2 +- src/renderer/store/soundEffect.ts | 5 +++++ src/renderer/utils/data.ts | 6 +++++ src/renderer/utils/index.ts | 2 +- src/renderer/utils/ipc.ts | 22 +++++++++---------- src/renderer/utils/music.ts | 12 +++++----- src/renderer/utils/musicSdk/kg/lyric.js | 6 ++--- src/renderer/utils/musicSdk/kg/pic.js | 4 ++-- src/renderer/utils/musicSdk/mg/lyric.js | 6 ++--- src/renderer/utils/musicSdk/mg/pic.js | 2 +- src/renderer/utils/musicSdk/mg/songList.js | 2 +- src/renderer/utils/musicSdk/tx/musicInfo.js | 2 +- src/renderer/utils/musicSdk/wy/musicInfo.js | 2 +- src/renderer/utils/update.js | 2 +- 48 files changed, 123 insertions(+), 106 deletions(-) diff --git a/.eslintrc.base.cjs b/.eslintrc.base.cjs index 47220c26..5544e8e9 100644 --- a/.eslintrc.base.cjs +++ b/.eslintrc.base.cjs @@ -5,8 +5,8 @@ const baseRule = { 'space-before-function-paren': ['error', 'never'], 'no-var': 'error', 'no-fallthrough': 'off', - 'prefer-promise-reject-errors': 'off', eqeqeq: 'off', + 'require-atomic-updates': ['error', { allowProperties: true }], 'no-multiple-empty-lines': [1, { max: 2 }], 'comma-dangle': [2, 'always-multiline'], 'standard/no-callback-literal': 'off', diff --git a/build-config/build-after-pack.js b/build-config/build-after-pack.js index 62859545..f95afba5 100644 --- a/build-config/build-after-pack.js +++ b/build-config/build-after-pack.js @@ -16,7 +16,7 @@ module.exports = async(context) => { const resPath = `${appOutDir}/${productFilename}.app/Contents/Resources` // 创建APP语言包文件 - return await Promise.all( + return Promise.all( Object.entries(macLanguagesInfoPlistStrings).map(([lang, config]) => { let infos = Object.entries(config).map(([k, v]) => `"${k}" = "${v}";`).join('\n') return fs.writeFile(`${resPath}/${lang}.lproj/InfoPlist.strings`, infos) diff --git a/src/common/mainIpc.ts b/src/common/mainIpc.ts index 48a02d9e..e8157208 100644 --- a/src/common/mainIpc.ts +++ b/src/common/mainIpc.ts @@ -30,7 +30,7 @@ export function mainHandle(name: string, listener: LX.IpcMainInvokeEventListe export function mainHandle(name: string, listener: LX.IpcMainInvokeEventListenerParamsValue): void export function mainHandle(name: string, listener: LX.IpcMainInvokeEventListenerParamsValue): void { ipcMain.handle(name, async(event, params) => { - return await listener({ event, params }) + return listener({ event, params }) }) } @@ -40,7 +40,7 @@ export function mainHandleOnce(name: string, listener: LX.IpcMainInvokeEventL export function mainHandleOnce(name: string, listener: LX.IpcMainInvokeEventListenerParamsValue): void export function mainHandleOnce(name: string, listener: LX.IpcMainInvokeEventListenerParamsValue): void { ipcMain.handleOnce(name, async(event, params) => { - return await listener({ event, params }) + return listener({ event, params }) }) } export const mainHandleRemove = (name: string) => { diff --git a/src/common/rendererIpc.ts b/src/common/rendererIpc.ts index cec09736..5b662206 100644 --- a/src/common/rendererIpc.ts +++ b/src/common/rendererIpc.ts @@ -17,7 +17,7 @@ export async function rendererInvoke(name: string): Promise export async function rendererInvoke(name: string, params: T): Promise export async function rendererInvoke(name: string, params: T): Promise export async function rendererInvoke (name: string, params?: T): Promise { - return await ipcRenderer.invoke(name, params) + return ipcRenderer.invoke(name, params) } export function rendererOn(name: string, listener: LX.IpcRendererEventListener): void diff --git a/src/common/utils/nodejs.ts b/src/common/utils/nodejs.ts index a4bc5ca8..0417a9fd 100644 --- a/src/common/utils/nodejs.ts +++ b/src/common/utils/nodejs.ts @@ -15,7 +15,7 @@ export const dirname = (p: string): string => path.dirname(p) * @param {*} path 路径 */ export const checkPath = async(path: string): Promise => { - return await new Promise(resolve => { + return new Promise(resolve => { if (!path) { resolve(false) return @@ -31,7 +31,7 @@ export const checkPath = async(path: string): Promise => { } export const getFileStats = async(path: string): Promise => { - return await new Promise(resolve => { + return new Promise(resolve => { if (!path) { resolve(null) return @@ -97,7 +97,7 @@ export const readFile = async(path: string) => fs.promises.readFile(path) export const toMD5 = (str: string) => crypto.createHash('md5').update(str).digest('hex') export const gzipData = async(str: string): Promise => { - return await new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { gzip(str, (err, result) => { if (err) { reject(err) @@ -109,7 +109,7 @@ export const gzipData = async(str: string): Promise => { } export const gunzipData = async(buf: Buffer): Promise => { - return await new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { gunzip(buf, (err, result) => { if (err) { reject(err) diff --git a/src/main/app.ts b/src/main/app.ts index ac042962..3ae9f3eb 100644 --- a/src/main/app.ts +++ b/src/main/app.ts @@ -253,7 +253,7 @@ export const initAppSetting = async() => { } // global.lx.theme = getTheme() - isInitialized = true + isInitialized ||= true } export const quitApp = () => { diff --git a/src/main/modules/commonRenderers/common/rendererEvent.ts b/src/main/modules/commonRenderers/common/rendererEvent.ts index 1529bb07..35ed0530 100644 --- a/src/main/modules/commonRenderers/common/rendererEvent.ts +++ b/src/main/modules/commonRenderers/common/rendererEvent.ts @@ -20,7 +20,7 @@ export default () => { }) mainHandle(CMMON_EVENT_NAME.get_system_fonts, async() => { - return await getFonts() + return getFonts() }) } diff --git a/src/main/modules/commonRenderers/list/rendererEvent.ts b/src/main/modules/commonRenderers/list/rendererEvent.ts index 0c8ae9ae..185b38a5 100644 --- a/src/main/modules/commonRenderers/list/rendererEvent.ts +++ b/src/main/modules/commonRenderers/list/rendererEvent.ts @@ -4,7 +4,7 @@ import { PLAYER_EVENT_NAME } from '@common/ipcNames' // 列表操作事件(公共,只注册一次) export default () => { mainHandle(PLAYER_EVENT_NAME.list_get, async() => { - return await global.lx.worker.dbService.getAllUserList() + return global.lx.worker.dbService.getAllUserList() }) mainHandle(PLAYER_EVENT_NAME.list_data_overwire, async({ params: listData }) => { await global.lx.event_list.list_data_overwrite(listData, false) @@ -22,7 +22,7 @@ export default () => { await global.lx.event_list.list_update_position(position, ids, false) }) mainHandle(PLAYER_EVENT_NAME.list_music_get, async({ params: listId }) => { - return await global.lx.worker.dbService.getListMusics(listId) + return global.lx.worker.dbService.getListMusics(listId) }) mainHandle(PLAYER_EVENT_NAME.list_music_add, async({ params: { id, musicInfos, addMusicLocationType } }) => { await global.lx.event_list.list_music_add(id, musicInfos, addMusicLocationType, false) @@ -46,9 +46,9 @@ export default () => { await global.lx.event_list.list_music_clear(listId, false) }) mainHandle(PLAYER_EVENT_NAME.list_music_check_exist, async({ params: { listId, musicInfoId } }) => { - return await global.lx.worker.dbService.checkListExistMusic(listId, musicInfoId) + return global.lx.worker.dbService.checkListExistMusic(listId, musicInfoId) }) mainHandle(PLAYER_EVENT_NAME.list_music_get_list_ids, async({ params: musicInfoId }) => { - return await global.lx.worker.dbService.getMusicExistListIds(musicInfoId) + return global.lx.worker.dbService.getMusicExistListIds(musicInfoId) }) } diff --git a/src/main/modules/sync/client/data.ts b/src/main/modules/sync/client/data.ts index f6ac0b4d..487eff88 100644 --- a/src/main/modules/sync/client/data.ts +++ b/src/main/modules/sync/client/data.ts @@ -16,8 +16,10 @@ export const initClientInfo = async() => { if (syncAuthKeys != null) return const syncAuthKeysFilePath = path.join(global.lxDataPath, File.clientDataPath, File.syncAuthKeysJSON) if (await fs.promises.stat(syncAuthKeysFilePath).then(() => true).catch(() => false)) { + // eslint-disable-next-line require-atomic-updates syncAuthKeys = JSON.parse((await fs.promises.readFile(syncAuthKeysFilePath)).toString()) } else { + // eslint-disable-next-line require-atomic-updates syncAuthKeys = {} const syncDataPath = path.join(global.lxDataPath, File.clientDataPath) if (!await exists(syncDataPath)) { diff --git a/src/main/modules/sync/server/modules/list/sync/localEvent.ts b/src/main/modules/sync/server/modules/list/sync/localEvent.ts index 9c193b7c..c55df3f6 100644 --- a/src/main/modules/sync/server/modules/list/sync/localEvent.ts +++ b/src/main/modules/sync/server/modules/list/sync/localEvent.ts @@ -12,6 +12,7 @@ const sendListAction = async(wss: LX.Sync.Server.SocketServer, action: LX.Sync.L let key = '' for (const client of wss.clients) { if (!client.moduleReadys?.list) continue + // eslint-disable-next-line require-atomic-updates if (!key) key = await userSpace.listManage.createSnapshot() void client.remoteQueueList.onListSyncAction(action).then(async() => { return userSpace.listManage.updateDeviceSnapshotKey(client.keyInfo.clientId, key) diff --git a/src/main/modules/sync/server/user/data.ts b/src/main/modules/sync/server/user/data.ts index 4b7e80d4..276d4897 100644 --- a/src/main/modules/sync/server/user/data.ts +++ b/src/main/modules/sync/server/user/data.ts @@ -25,8 +25,10 @@ export const initServerInfo = async() => { if (serverInfo != null) return const serverInfoFilePath = path.join(global.lxDataPath, File.serverDataPath, File.serverInfoJSON) if (await exists(serverInfoFilePath)) { + // eslint-disable-next-line require-atomic-updates serverInfo = JSON.parse((await fs.promises.readFile(serverInfoFilePath)).toString()) } else { + // eslint-disable-next-line require-atomic-updates serverInfo = { serverId: randomBytes(4 * 4).toString('base64'), version: 2, diff --git a/src/main/modules/userApi/index.ts b/src/main/modules/userApi/index.ts index c4a11d9b..c3ee6165 100644 --- a/src/main/modules/userApi/index.ts +++ b/src/main/modules/userApi/index.ts @@ -28,7 +28,7 @@ export const setApi = async(id: string) => { } const apiList = getUserApis() if (!apiList.some(a => a.id === id)) return - userApiId = id + userApiId ||= id await loadApi(id) } diff --git a/src/main/modules/userApi/main.ts b/src/main/modules/userApi/main.ts index 3b95d488..fd6a40f4 100644 --- a/src/main/modules/userApi/main.ts +++ b/src/main/modules/userApi/main.ts @@ -30,6 +30,7 @@ export const createWindow = async(userApi: LX.UserApi.UserApiInfo) => { dir ??= process.env.NODE_ENV !== 'production' ? webpackUserApiPath : path.join(encodePath(__dirname), 'userApi') if (!html) { + // eslint-disable-next-line require-atomic-updates html = await fs.promises.readFile(path.join(dir, 'renderer/user-api.html'), 'utf8') } const preloadUrl = process.env.NODE_ENV !== 'production' diff --git a/src/main/modules/winMain/main.ts b/src/main/modules/winMain/main.ts index a034a872..b9a95580 100644 --- a/src/main/modules/winMain/main.ts +++ b/src/main/modules/winMain/main.ts @@ -128,7 +128,7 @@ export const sendEvent = (name: string, params?: T) => { export const showSelectDialog = async(options: Electron.OpenDialogOptions) => { if (!browserWindow) throw new Error('main window is undefined') - return await dialog.showOpenDialog(browserWindow, options) + return dialog.showOpenDialog(browserWindow, options) } export const showDialog = ({ type, message, detail }: Electron.MessageBoxSyncOptions) => { if (!browserWindow) return @@ -140,7 +140,7 @@ export const showDialog = ({ type, message, detail }: Electron.MessageBoxSyncOpt } export const showSaveDialog = async(options: Electron.SaveDialogOptions) => { if (!browserWindow) throw new Error('main window is undefined') - return await dialog.showSaveDialog(browserWindow, options) + return dialog.showSaveDialog(browserWindow, options) } export const minimize = () => { if (!browserWindow) return @@ -256,7 +256,7 @@ export const clearCache = async() => { export const getCacheSize = async() => { if (!browserWindow) throw new Error('main window is undefined') - return await browserWindow.webContents.session.getCacheSize() + return browserWindow.webContents.session.getCacheSize() } export const getWebContents = (): Electron.WebContents => { diff --git a/src/main/modules/winMain/rendererEvent/app.ts b/src/main/modules/winMain/rendererEvent/app.ts index 631b7dc6..17c06a29 100644 --- a/src/main/modules/winMain/rendererEvent/app.ts +++ b/src/main/modules/winMain/rendererEvent/app.ts @@ -70,7 +70,7 @@ export default () => { // 选择目录 mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.show_select_dialog, async({ params: options }) => { - return await showSelectDialog(options) + return showSelectDialog(options) }) // 显示弹窗信息 mainOn(WIN_MAIN_RENDERER_EVENT_NAME.show_dialog, ({ params }) => { @@ -78,7 +78,7 @@ export default () => { }) // 显示保存弹窗 mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.show_save_dialog, async({ params }) => { - return await showSaveDialog(params) + return showSaveDialog(params) }) @@ -87,7 +87,7 @@ export default () => { }) mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.get_cache_size, async() => { - return await getCacheSize() + return getCacheSize() }) mainOn(WIN_MAIN_RENDERER_EVENT_NAME.open_dev_tools, () => { diff --git a/src/main/modules/winMain/rendererEvent/download.ts b/src/main/modules/winMain/rendererEvent/download.ts index 6a2b6cca..46ef026c 100644 --- a/src/main/modules/winMain/rendererEvent/download.ts +++ b/src/main/modules/winMain/rendererEvent/download.ts @@ -4,7 +4,7 @@ import { mainHandle } from '@common/mainIpc' export default () => { mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.download_list_get, async() => { - return await global.lx.worker.dbService.getDownloadList() + return global.lx.worker.dbService.getDownloadList() }) mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.download_list_add, async({ params: { list, addMusicLocationType } }) => { await global.lx.worker.dbService.downloadInfoSave(list, addMusicLocationType) diff --git a/src/main/modules/winMain/rendererEvent/kw_decodeLyric.ts b/src/main/modules/winMain/rendererEvent/kw_decodeLyric.ts index e4d965eb..dde53a83 100644 --- a/src/main/modules/winMain/rendererEvent/kw_decodeLyric.ts +++ b/src/main/modules/winMain/rendererEvent/kw_decodeLyric.ts @@ -4,7 +4,7 @@ import { mainHandle } from '@common/mainIpc' import { WIN_MAIN_RENDERER_EVENT_NAME } from '@common/ipcNames' const handleInflate = async(data: Buffer) => { - return await new Promise((resolve: (result: Buffer) => void, reject) => { + return new Promise((resolve: (result: Buffer) => void, reject) => { inflate(data, (err, result) => { if (err) { reject(err) diff --git a/src/main/modules/winMain/rendererEvent/music.ts b/src/main/modules/winMain/rendererEvent/music.ts index 112ef347..92bef88c 100644 --- a/src/main/modules/winMain/rendererEvent/music.ts +++ b/src/main/modules/winMain/rendererEvent/music.ts @@ -7,12 +7,12 @@ export default () => { mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.get_palyer_lyric, async({ params: id }) => { // return (getStore(LRC_EDITED, true, false).get(id) as LX.Music.LyricInfo | undefined) ?? // getStore(LRC_RAW, true, false).get(id, {}) as LX.Music.LyricInfo - return await global.lx.worker.dbService.getPlayerLyric(id) + return global.lx.worker.dbService.getPlayerLyric(id) }) // 原始歌词 mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.get_lyric_raw, async({ params: id }) => { - return await global.lx.worker.dbService.getRawLyric(id) + return global.lx.worker.dbService.getRawLyric(id) }) mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.save_lyric_raw, async({ params: { id, lyrics } }) => { await global.lx.worker.dbService.rawLyricAdd(id, lyrics) @@ -21,12 +21,12 @@ export default () => { await global.lx.worker.dbService.rawLyricClear() }) mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.get_lyric_raw_count, async() => { - return await global.lx.worker.dbService.rawLyricCount() + return global.lx.worker.dbService.rawLyricCount() }) // 已编辑的歌词 mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.get_lyric_edited, async({ params: id }) => { - return await global.lx.worker.dbService.getEditedLyric(id) + return global.lx.worker.dbService.getEditedLyric(id) }) mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.save_lyric_edited, async({ params: { id, lyrics } }) => { await global.lx.worker.dbService.editedLyricUpdateAddAndUpdate(id, lyrics) @@ -38,13 +38,13 @@ export default () => { await global.lx.worker.dbService.editedLyricClear() }) mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.get_lyric_edited_count, async() => { - return await global.lx.worker.dbService.editedLyricCount() + return global.lx.worker.dbService.editedLyricCount() }) // =========================歌曲URL========================= mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.get_music_url, async({ params: id }) => { - return await global.lx.worker.dbService.getMusicUrl(id) ?? '' + return (await global.lx.worker.dbService.getMusicUrl(id)) ?? '' }) mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.save_music_url, async({ params: { id, url } }) => { await global.lx.worker.dbService.musicUrlSave([{ id, url }]) @@ -53,12 +53,12 @@ export default () => { await global.lx.worker.dbService.musicUrlClear() }) mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.get_music_url_count, async() => { - return await global.lx.worker.dbService.musicUrlCount() + return global.lx.worker.dbService.musicUrlCount() }) // =========================换源歌曲========================= mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.get_other_source, async({ params: id }) => { - return await global.lx.worker.dbService.getMusicInfoOtherSource(id) + return global.lx.worker.dbService.getMusicInfoOtherSource(id) }) mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.save_other_source, async({ params: { id, list } }) => { await global.lx.worker.dbService.musicInfoOtherSourceAdd(id, list) @@ -67,7 +67,7 @@ export default () => { await global.lx.worker.dbService.musicInfoOtherSourceClear() }) mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.get_other_source_count, async() => { - return await global.lx.worker.dbService.musicInfoOtherSourceCount() + return global.lx.worker.dbService.musicInfoOtherSourceCount() }) diff --git a/src/main/modules/winMain/rendererEvent/userApi.ts b/src/main/modules/winMain/rendererEvent/userApi.ts index a4c737b5..06f9e6cf 100644 --- a/src/main/modules/winMain/rendererEvent/userApi.ts +++ b/src/main/modules/winMain/rendererEvent/userApi.ts @@ -18,7 +18,7 @@ export default () => { }) mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.remove_user_api, async({ params: apiIds }) => { - return await removeApi(apiIds) + return removeApi(apiIds) }) mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.set_user_api, async({ params: apiId }) => { @@ -38,7 +38,7 @@ export default () => { }) mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.request_user_api, async({ params }) => { - return await request(params) + return request(params) }) mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.request_user_api_cancel, async({ params: requestKey }) => { cancelRequest(requestKey) diff --git a/src/renderer-lyric/utils/ipc.ts b/src/renderer-lyric/utils/ipc.ts index ef70677b..346dfa1e 100644 --- a/src/renderer-lyric/utils/ipc.ts +++ b/src/renderer-lyric/utils/ipc.ts @@ -4,7 +4,7 @@ import { CMMON_EVENT_NAME, WIN_LYRIC_RENDERER_EVENT_NAME } from '@common/ipcName type RemoveListener = () => void export const getSetting = async() => { - return await rendererInvoke(WIN_LYRIC_RENDERER_EVENT_NAME.get_config) + return rendererInvoke(WIN_LYRIC_RENDERER_EVENT_NAME.get_config) } export const updateSetting = async(setting: Partial) => { await rendererInvoke(WIN_LYRIC_RENDERER_EVENT_NAME.set_config, setting) diff --git a/src/renderer/components/base/MusicList.vue b/src/renderer/components/base/MusicList.vue index 129d178b..51b45c3f 100644 --- a/src/renderer/components/base/MusicList.vue +++ b/src/renderer/components/base/MusicList.vue @@ -215,7 +215,7 @@ export default { }, () => { cancelScroll = null isScrolling = false - reject('canceled') + reject(new Error('canceled')) }) } else { dom_scrollContainer.value.scrollTop = scrollTop diff --git a/src/renderer/components/base/useVirtualizedList.ts b/src/renderer/components/base/useVirtualizedList.ts index 0187d1ea..daa3dfa0 100644 --- a/src/renderer/components/base/useVirtualizedList.ts +++ b/src/renderer/components/base/useVirtualizedList.ts @@ -141,14 +141,14 @@ // } // const scrollTo = async(scrollTop, animate = false) => { -// return await new Promise(resolve => { +// return new Promise(resolve => { // if (cancelScroll) { // cancelScroll(resolve) // } else { // resolve() // } // }).then(async() => { -// return await new Promise((resolve, reject) => { +// return new Promise((resolve, reject) => { // if (animate) { // isScrolling = true // scrollToValue = scrollTop @@ -169,7 +169,7 @@ // } // const scrollToIndex = async(index, offset = 0, animate = false) => { -// return await scrollTo(Math.max(index * props.itemHeight + offset, 0), animate) +// return scrollTo(Math.max(index * props.itemHeight + offset, 0), animate) // } // const getScrollTop = () => { diff --git a/src/renderer/components/layout/Toolbar/SearchInput.vue b/src/renderer/components/layout/Toolbar/SearchInput.vue index 48f1602c..172b4f5b 100644 --- a/src/renderer/components/layout/Toolbar/SearchInput.vue +++ b/src/renderer/components/layout/Toolbar/SearchInput.vue @@ -52,7 +52,7 @@ export default { return } const { temp_source } = await getSearchSetting() - prevTempSearchSource = temp_source + prevTempSearchSource ||= temp_source music[prevTempSearchSource].tipSearch.search(searchText.value).then(list => { tipList.value = list }).catch(() => {}) diff --git a/src/renderer/core/music/download.ts b/src/renderer/core/music/download.ts index c0e6cdda..9c183a2a 100644 --- a/src/renderer/core/music/download.ts +++ b/src/renderer/core/music/download.ts @@ -18,7 +18,7 @@ export const getMusicUrl = async({ musicInfo, isRefresh, onToggleSource = () => if (path) return path } - return await getOnlineMusicUrl({ musicInfo: musicInfo.metadata.musicInfo, isRefresh, onToggleSource }) + return getOnlineMusicUrl({ musicInfo: musicInfo.metadata.musicInfo, isRefresh, onToggleSource }) } export const getPicUrl = async({ musicInfo, isRefresh, listId, onToggleSource = () => {} }: { @@ -38,7 +38,7 @@ export const getPicUrl = async({ musicInfo, isRefresh, listId, onToggleSource = if (onlineMusicInfo.meta.picUrl) return onlineMusicInfo.meta.picUrl } - return await getOnlinePicUrl({ musicInfo: musicInfo.metadata.musicInfo, isRefresh, onToggleSource }).then((url) => { + return getOnlinePicUrl({ musicInfo: musicInfo.metadata.musicInfo, isRefresh, onToggleSource }).then((url) => { // TODO: when listId required save url (update downloadInfo) return url @@ -52,7 +52,7 @@ export const getLyricInfo = async({ musicInfo, isRefresh, onToggleSource = () => }): Promise => { if (!isRefresh) { const lyricInfo = await getCachedLyricInfo(musicInfo.metadata.musicInfo) - if (lyricInfo) return await buildLyricInfo(lyricInfo) + if (lyricInfo) return buildLyricInfo(lyricInfo) } return getOnlineLyricInfo({ diff --git a/src/renderer/core/music/index.ts b/src/renderer/core/music/index.ts index 45b79b55..a103a12b 100644 --- a/src/renderer/core/music/index.ts +++ b/src/renderer/core/music/index.ts @@ -31,11 +31,11 @@ export const getMusicUrl = async({ onToggleSource?: (musicInfo?: LX.Music.MusicInfoOnline) => void }): Promise => { if ('progress' in musicInfo) { - return await getDownloadMusicUrl({ musicInfo, isRefresh, onToggleSource }) + return getDownloadMusicUrl({ musicInfo, isRefresh, onToggleSource }) } else if (musicInfo.source == 'local') { - return await getLocalMusicUrl({ musicInfo, isRefresh, onToggleSource }) + return getLocalMusicUrl({ musicInfo, isRefresh, onToggleSource }) } else { - return await getOnlineMusicUrl({ musicInfo, isRefresh, quality, onToggleSource }) + return getOnlineMusicUrl({ musicInfo, isRefresh, quality, onToggleSource }) } } @@ -51,11 +51,11 @@ export const getPicPath = async({ onToggleSource?: (musicInfo?: LX.Music.MusicInfoOnline) => void }): Promise => { if ('progress' in musicInfo) { - return await getDownloadPicUrl({ musicInfo, isRefresh, listId, onToggleSource }) + return getDownloadPicUrl({ musicInfo, isRefresh, listId, onToggleSource }) } else if (musicInfo.source == 'local') { - return await getLocalPicUrl({ musicInfo, isRefresh, listId, onToggleSource }) + return getLocalPicUrl({ musicInfo, isRefresh, listId, onToggleSource }) } else { - return await getOnlinePicUrl({ musicInfo, isRefresh, listId, onToggleSource }) + return getOnlinePicUrl({ musicInfo, isRefresh, listId, onToggleSource }) } } @@ -69,10 +69,10 @@ export const getLyricInfo = async({ onToggleSource?: (musicInfo?: LX.Music.MusicInfoOnline) => void }): Promise => { if ('progress' in musicInfo) { - return await getDownloadLyricInfo({ musicInfo, isRefresh, onToggleSource }) + return getDownloadLyricInfo({ musicInfo, isRefresh, onToggleSource }) } else if (musicInfo.source == 'local') { - return await getLocalLyricInfo({ musicInfo, isRefresh, onToggleSource }) + return getLocalLyricInfo({ musicInfo, isRefresh, onToggleSource }) } else { - return await getOnlineLyricInfo({ musicInfo, isRefresh, onToggleSource }) + return getOnlineLyricInfo({ musicInfo, isRefresh, onToggleSource }) } } diff --git a/src/renderer/core/music/local.ts b/src/renderer/core/music/local.ts index 59325c99..fde798e9 100644 --- a/src/renderer/core/music/local.ts +++ b/src/renderer/core/music/local.ts @@ -25,7 +25,7 @@ export const getMusicUrl = async({ musicInfo, isRefresh, onToggleSource = () => onToggleSource() const otherSource = await getOtherSource(musicInfo) if (!otherSource.length) throw new Error('source not found') - return await getOnlineOtherSourceMusicUrl({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ url, quality: targetQuality, musicInfo: targetMusicInfo, isFromCache }) => { + return getOnlineOtherSourceMusicUrl({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ url, quality: targetQuality, musicInfo: targetMusicInfo, isFromCache }) => { // saveLyric(musicInfo, data.lyricInfo) if (!isFromCache) void saveMusicUrl(targetMusicInfo, targetQuality, url) @@ -50,7 +50,7 @@ export const getPicUrl = async({ musicInfo, listId, isRefresh, onToggleSource = onToggleSource() const otherSource = await getOtherSource(musicInfo) if (!otherSource.length) throw new Error('source not found') - return await getOnlineOtherSourcePicUrl({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ url, musicInfo: targetMusicInfo, isFromCache }) => { + return getOnlineOtherSourcePicUrl({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ url, musicInfo: targetMusicInfo, isFromCache }) => { if (listId) { musicInfo.meta.picUrl = url void updateListMusics([{ id: listId, musicInfo }]) @@ -69,7 +69,7 @@ export const getLyricInfo = async({ musicInfo, isRefresh, onToggleSource = () => const lyricInfo = await getCachedLyricInfo(musicInfo) if (lyricInfo) { // 存在已编辑、原始歌词 - if (lyricInfo.rawlrcInfo.lyric) return await buildLyricInfo(lyricInfo) + if (lyricInfo.rawlrcInfo.lyric) return buildLyricInfo(lyricInfo) } // 尝试读取文件内歌词 @@ -81,7 +81,7 @@ export const getLyricInfo = async({ musicInfo, isRefresh, onToggleSource = () => const otherSource = await getOtherSource(musicInfo) if (!otherSource.length) throw new Error('source not found') // eslint-disable-next-line @typescript-eslint/promise-function-async - return await getOnlineOtherSourceLyricInfo({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ lyricInfo, musicInfo: targetMusicInfo, isFromCache }) => { + return getOnlineOtherSourceLyricInfo({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ lyricInfo, musicInfo: targetMusicInfo, isFromCache }) => { void saveLyric(musicInfo, lyricInfo) if (isFromCache) return buildLyricInfo(lyricInfo) diff --git a/src/renderer/core/music/online.ts b/src/renderer/core/music/online.ts index 521ff1ac..7d38f99a 100644 --- a/src/renderer/core/music/online.ts +++ b/src/renderer/core/music/online.ts @@ -55,7 +55,7 @@ export const getMusicUrl = async({ musicInfo, quality, isRefresh, allowToggleSou const cachedUrl = await getStoreMusicUrl(musicInfo, targetQuality) if (cachedUrl && !isRefresh) return cachedUrl - return await handleGetOnlineMusicUrl({ musicInfo, quality, onToggleSource, isRefresh, allowToggleSource }).then(({ url, quality: targetQuality, musicInfo: targetMusicInfo, isFromCache }) => { + return handleGetOnlineMusicUrl({ musicInfo, quality, onToggleSource, isRefresh, allowToggleSource }).then(({ url, quality: targetQuality, musicInfo: targetMusicInfo, isFromCache }) => { if (targetMusicInfo.id != musicInfo.id && !isFromCache) void saveMusicUrl(targetMusicInfo, targetQuality, url) void saveMusicUrl(musicInfo, targetQuality, url) return url @@ -70,7 +70,7 @@ export const getPicUrl = async({ musicInfo, listId, isRefresh, allowToggleSource onToggleSource?: (musicInfo?: LX.Music.MusicInfoOnline) => void }): Promise => { if (musicInfo.meta.picUrl && !isRefresh) return musicInfo.meta.picUrl - return await handleGetOnlinePicUrl({ musicInfo, onToggleSource, isRefresh, allowToggleSource }).then(({ url, musicInfo: targetMusicInfo, isFromCache }) => { + return handleGetOnlinePicUrl({ musicInfo, onToggleSource, isRefresh, allowToggleSource }).then(({ url, musicInfo: targetMusicInfo, isFromCache }) => { // picRequest = null if (listId) { musicInfo.meta.picUrl = url @@ -88,16 +88,16 @@ export const getLyricInfo = async({ musicInfo, isRefresh, allowToggleSource = tr }): Promise => { if (!isRefresh) { const lyricInfo = await getCachedLyricInfo(musicInfo) - if (lyricInfo) return await buildLyricInfo(lyricInfo) + if (lyricInfo) return buildLyricInfo(lyricInfo) } // lrcRequest = music[musicInfo.source].getLyric(musicInfo) - return await handleGetOnlineLyricInfo({ musicInfo, onToggleSource, isRefresh, allowToggleSource }).then(async({ lyricInfo, musicInfo: targetMusicInfo, isFromCache }) => { + return handleGetOnlineLyricInfo({ musicInfo, onToggleSource, isRefresh, allowToggleSource }).then(async({ lyricInfo, musicInfo: targetMusicInfo, isFromCache }) => { // lrcRequest = null - if (isFromCache) return await buildLyricInfo(lyricInfo) + if (isFromCache) return buildLyricInfo(lyricInfo) if (targetMusicInfo.id == musicInfo.id) void saveLyric(musicInfo, lyricInfo) else void saveLyric(targetMusicInfo, lyricInfo) - return await buildLyricInfo(lyricInfo) + return buildLyricInfo(lyricInfo) }) } diff --git a/src/renderer/core/music/utils.ts b/src/renderer/core/music/utils.ts index 82413e3e..e678ec31 100644 --- a/src/renderer/core/music/utils.ts +++ b/src/renderer/core/music/utils.ts @@ -81,7 +81,7 @@ export const buildLyricInfo = async(lyricInfo: MakeOptional { + return Promise.all(tasks).then(([lyric, tlyric, rlyric, lxlyric, lyric_raw, tlyric_raw, rlyric_raw, lxlyric_raw]) => { const rawlrcInfo = lyric_raw ? { lyric: lyric_raw, tlyric: tlyric_raw, @@ -225,7 +225,7 @@ export const handleGetOnlineMusicUrl = async({ musicInfo, quality, onToggleSourc if (!allowToggleSource || err.message == requestMsg.tooManyRequests) throw err onToggleSource() // eslint-disable-next-line @typescript-eslint/promise-function-async - return await getOtherSource(musicInfo).then(otherSource => { + return getOtherSource(musicInfo).then(otherSource => { console.log('find otherSource', otherSource) if (otherSource.length) { return getOnlineOtherSourceMusicUrl({ @@ -309,7 +309,7 @@ export const handleGetOnlinePicUrl = async({ musicInfo, isRefresh, onToggleSourc if (!allowToggleSource) throw err onToggleSource() // eslint-disable-next-line @typescript-eslint/promise-function-async - return await getOtherSource(musicInfo).then(otherSource => { + return getOtherSource(musicInfo).then(otherSource => { console.log('find otherSource', otherSource) if (otherSource.length) { return getOnlineOtherSourcePicUrl({ @@ -408,7 +408,7 @@ export const handleGetOnlineLyricInfo = async({ musicInfo, onToggleSource, isRef onToggleSource() // eslint-disable-next-line @typescript-eslint/promise-function-async - return await getOtherSource(musicInfo).then(otherSource => { + return getOtherSource(musicInfo).then(otherSource => { console.log('find otherSource', otherSource) if (otherSource.length) { return getOnlineOtherSourceLyricInfo({ diff --git a/src/renderer/core/useApp/useInitUserApi.ts b/src/renderer/core/useApp/useInitUserApi.ts index d00d4e6b..631c6f6a 100644 --- a/src/renderer/core/useApp/useInitUserApi.ts +++ b/src/renderer/core/useApp/useInitUserApi.ts @@ -49,7 +49,7 @@ export default () => { return { type, url: res.data.url } }).catch(async err => { console.log(err.message) - return await Promise.reject(err) + return Promise.reject(err) }), } } diff --git a/src/renderer/store/leaderboard/action.ts b/src/renderer/store/leaderboard/action.ts index bc0e9343..d07e3050 100644 --- a/src/renderer/store/leaderboard/action.ts +++ b/src/renderer/store/leaderboard/action.ts @@ -82,7 +82,7 @@ export const getListDetailAll = async(id: string, isRefresh = false): Promise { + return loadData(bangId, 1).then((result: ListDetailInfo) => { if (result.total <= result.limit) return result.list let maxPage = Math.ceil(result.total / result.limit) diff --git a/src/renderer/store/list/listManage/rendererListManage.ts b/src/renderer/store/list/listManage/rendererListManage.ts index fea0a5ae..c1d88dd0 100644 --- a/src/renderer/store/list/listManage/rendererListManage.ts +++ b/src/renderer/store/list/listManage/rendererListManage.ts @@ -155,7 +155,7 @@ export const overwriteListFull = async(data: LX.List.ListActionDataOverwrite) => * @param musicInfoId */ export const checkListExistMusic = async(listId: string, musicInfoId: string): Promise => { - return await rendererInvoke(PLAYER_EVENT_NAME.list_music_check_exist, { listId, musicInfoId }) + return rendererInvoke(PLAYER_EVENT_NAME.list_music_check_exist, { listId, musicInfoId }) } /** @@ -163,7 +163,7 @@ export const checkListExistMusic = async(listId: string, musicInfoId: string): P * @param musicInfoId */ export const getMusicExistListIds = async(musicInfoId: string): Promise => { - return await rendererInvoke(PLAYER_EVENT_NAME.list_music_get_list_ids, musicInfoId) + return rendererInvoke(PLAYER_EVENT_NAME.list_music_get_list_ids, musicInfoId) } diff --git a/src/renderer/store/search/action.ts b/src/renderer/store/search/action.ts index f6ff4539..ad76b5b7 100644 --- a/src/renderer/store/search/action.ts +++ b/src/renderer/store/search/action.ts @@ -22,7 +22,7 @@ const saveSearchHistoryListThrottle = throttle((list: LX.List.SearchHistoryList) export const getHistoryList = async() => { if (isInitedSearchHistory || historyList.length) return historyList.push(...(await getSearchHistoryList() ?? [])) - isInitedSearchHistory = true + isInitedSearchHistory ||= true } export const addHistoryWord = async(word: string) => { if (!appSetting['search.isShowHistorySearch']) return diff --git a/src/renderer/store/search/music/action.ts b/src/renderer/store/search/music/action.ts index 5537a2b8..0155c97d 100644 --- a/src/renderer/store/search/music/action.ts +++ b/src/renderer/store/search/music/action.ts @@ -104,7 +104,7 @@ export const search = async(text: string, page: number, sourceId: LX.OnlineSourc } })) } - return await Promise.all(task).then((results: SearchResult[]) => { + return Promise.all(task).then((results: SearchResult[]) => { if (key != listInfo!.key) return [] return setLists(results, page, text) }) diff --git a/src/renderer/store/search/songlist/action.ts b/src/renderer/store/search/songlist/action.ts index d00ca72f..d8855588 100644 --- a/src/renderer/store/search/songlist/action.ts +++ b/src/renderer/store/search/songlist/action.ts @@ -105,7 +105,7 @@ export const search = async(text: string, page: number, sourceId: LX.OnlineSourc } })) } - return await Promise.all(task).then((results: SearchResult[]) => { + return Promise.all(task).then((results: SearchResult[]) => { if (key != listInfo.key) return [] return setLists(results, page, text) }) diff --git a/src/renderer/store/songList/action.ts b/src/renderer/store/songList/action.ts index b218a9d7..ddd5847c 100644 --- a/src/renderer/store/songList/action.ts +++ b/src/renderer/store/songList/action.ts @@ -161,7 +161,7 @@ export const getListDetailAll = async(id: string, source: LX.OnlineSource, isRef }) ?? Promise.reject(new Error('source not found' + source)) } // eslint-disable-next-line @typescript-eslint/promise-function-async - return await loadData(id, 1).then((result: ListDetailInfo) => { + return loadData(id, 1).then((result: ListDetailInfo) => { if (result.total <= result.limit) return result.list let maxPage = Math.ceil(result.total / result.limit) diff --git a/src/renderer/store/soundEffect.ts b/src/renderer/store/soundEffect.ts index 72d0cdfa..b2c98424 100644 --- a/src/renderer/store/soundEffect.ts +++ b/src/renderer/store/soundEffect.ts @@ -12,12 +12,14 @@ let userEqPresetList: LX.SoundEffect.EQPreset[] | null = null export const getUserEQPresetList = async() => { if (userEqPresetList == null) { + // eslint-disable-next-line require-atomic-updates userEqPresetList = reactive(await getUserSoundEffectEQPresetList()) } return userEqPresetList } export const saveUserEQPreset = async(preset: LX.SoundEffect.EQPreset) => { if (userEqPresetList == null) { + // eslint-disable-next-line require-atomic-updates userEqPresetList = reactive(await getUserSoundEffectEQPresetList()) } const target = userEqPresetList.find(p => p.id == preset.id) @@ -27,6 +29,7 @@ export const saveUserEQPreset = async(preset: LX.SoundEffect.EQPreset) => { } export const removeUserEQPreset = async(id: string) => { if (userEqPresetList == null) { + // eslint-disable-next-line require-atomic-updates userEqPresetList = reactive(await getUserSoundEffectEQPresetList()) } const index = userEqPresetList.findIndex(p => p.id == id) @@ -45,6 +48,7 @@ export const getUserConvolutionPresetList = async() => { } export const saveUserConvolutionPreset = async(preset: LX.SoundEffect.ConvolutionPreset) => { if (userConvolutionPresetList == null) { + // eslint-disable-next-line require-atomic-updates userConvolutionPresetList = reactive(await getUserSoundEffectConvolutionPresetList()) } const target = userConvolutionPresetList.find(p => p.id == preset.id) @@ -54,6 +58,7 @@ export const saveUserConvolutionPreset = async(preset: LX.SoundEffect.Convolutio } export const removeUserConvolutionPreset = async(id: string) => { if (userConvolutionPresetList == null) { + // eslint-disable-next-line require-atomic-updates userConvolutionPresetList = reactive(await getUserSoundEffectConvolutionPresetList()) } const index = userConvolutionPresetList.findIndex(p => p.id == id) diff --git a/src/renderer/utils/data.ts b/src/renderer/utils/data.ts index 88b8f773..3c041550 100644 --- a/src/renderer/utils/data.ts +++ b/src/renderer/utils/data.ts @@ -44,6 +44,7 @@ const saveViewPrevStateThrottle = throttle((state) => { }, 1000) const initPosition = async() => { + // eslint-disable-next-line require-atomic-updates listPosition ??= await getListPositionInfoFromData() ?? {} } export const getListPosition = async(id: string): Promise => { @@ -74,6 +75,7 @@ const saveListPrevSelectIdThrottle = throttle(() => { saveListPrevSelectIdFromData(listPrevSelectId) }, 200) export const getListPrevSelectId = async() => { + // eslint-disable-next-line require-atomic-updates listPrevSelectId ??= await getListPrevSelectIdFromData() ?? LIST_IDS.DEFAULT return listPrevSelectId ?? LIST_IDS.DEFAULT } @@ -88,6 +90,7 @@ const saveListUpdateInfo = throttle(() => { const initListUpdateInfo = async() => { if (listUpdateInfo == null) { + // eslint-disable-next-line require-atomic-updates listUpdateInfo = await getListUpdateInfoFromData() ?? {} for (const [id, info] of Object.entries(listUpdateInfo)) { setUpdateTime(id, info.updateTime ? dateFormat(info.updateTime) : '') @@ -138,6 +141,7 @@ export const overwriteListUpdateInfo = async(ids: string[]) => { export const getSearchSetting = async() => { + // eslint-disable-next-line require-atomic-updates searchSetting ??= await getSearchSettingFromData() return { ...searchSetting } } @@ -154,6 +158,7 @@ export const setSearchSetting = async(setting: Partial { + // eslint-disable-next-line require-atomic-updates songListSetting ??= await getSongListSettingFromData() return { ...songListSetting } } @@ -164,6 +169,7 @@ export const setSongListSetting = async(setting: Partial { + // eslint-disable-next-line require-atomic-updates leaderboardSetting ??= await getLeaderboardSettingFromData() return { ...leaderboardSetting } } diff --git a/src/renderer/utils/index.ts b/src/renderer/utils/index.ts index fe4adf76..93513b20 100644 --- a/src/renderer/utils/index.ts +++ b/src/renderer/utils/index.ts @@ -73,5 +73,5 @@ export const deduplicationList = (list: T[]): T[] } export const langS2T = async(str: string) => { - return await window.lx.worker.main.langS2t(Buffer.from(str).toString('base64')).then(b64 => Buffer.from(b64, 'base64').toString()) + return window.lx.worker.main.langS2t(Buffer.from(str).toString('base64')).then(b64 => Buffer.from(b64, 'base64').toString()) } diff --git a/src/renderer/utils/ipc.ts b/src/renderer/utils/ipc.ts index f1d794db..5c06374d 100644 --- a/src/renderer/utils/ipc.ts +++ b/src/renderer/utils/ipc.ts @@ -37,7 +37,7 @@ export const clearOtherSource = async() => { await rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.clear_other_source) } export const getOtherSourceCount = async() => { - return await rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_other_source_count) + return rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_other_source_count) } @@ -254,7 +254,7 @@ export const saveLeaderboardSetting = (source: typeof DEFAULT_SETTING['leaderboa }) } export const getLeaderboardSetting = async() => { - return await rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_data, DATA_KEYS.leaderboardSetting) ?? { ...DEFAULT_SETTING.leaderboard } + return (await rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_data, DATA_KEYS.leaderboardSetting)) ?? { ...DEFAULT_SETTING.leaderboard } } export const saveSongListSetting = (setting: typeof DEFAULT_SETTING['songList']) => { rendererSend(WIN_MAIN_RENDERER_EVENT_NAME.save_data, { @@ -263,7 +263,7 @@ export const saveSongListSetting = (setting: typeof DEFAULT_SETTING['songList']) }) } export const getSongListSetting = async() => { - return await rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_data, DATA_KEYS.songListSetting) ?? { ...DEFAULT_SETTING.songList } + return (await rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_data, DATA_KEYS.songListSetting)) ?? { ...DEFAULT_SETTING.songList } } export const saveSearchSetting = (setting: typeof DEFAULT_SETTING['search']) => { rendererSend(WIN_MAIN_RENDERER_EVENT_NAME.save_data, { @@ -272,7 +272,7 @@ export const saveSearchSetting = (setting: typeof DEFAULT_SETTING['search']) => }) } export const getSearchSetting = async() => { - return await rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_data, DATA_KEYS.searchSetting) ?? { ...DEFAULT_SETTING.search } + return (await rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_data, DATA_KEYS.searchSetting)) ?? { ...DEFAULT_SETTING.search } } export const saveViewPrevState = (state: typeof DEFAULT_SETTING['viewPrevState']) => { rendererSend(WIN_MAIN_RENDERER_EVENT_NAME.save_data, { @@ -281,7 +281,7 @@ export const saveViewPrevState = (state: typeof DEFAULT_SETTING['viewPrevState'] }) } export const getViewPrevState = async() => { - return await rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_data, DATA_KEYS.viewPrevState) ?? { ...DEFAULT_SETTING.viewPrevState } + return (await rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_data, DATA_KEYS.viewPrevState)) ?? { ...DEFAULT_SETTING.viewPrevState } } @@ -292,7 +292,7 @@ export const getSystemFonts = async() => { } export const getUserSoundEffectEQPresetList = async() => { - return await rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_sound_effect_eq_preset) + return rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_sound_effect_eq_preset) } export const saveUserSoundEffectEQPresetList = (list: LX.SoundEffect.EQPreset[]) => { @@ -300,7 +300,7 @@ export const saveUserSoundEffectEQPresetList = (list: LX.SoundEffect.EQPreset[]) } export const getUserSoundEffectConvolutionPresetList = async() => { - return await rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_sound_effect_convolution_preset) + return rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_sound_effect_convolution_preset) } export const saveUserSoundEffectConvolutionPresetList = (list: LX.SoundEffect.ConvolutionPreset[]) => { @@ -308,7 +308,7 @@ export const saveUserSoundEffectConvolutionPresetList = (list: LX.SoundEffect.Co } // export const getUserSoundEffectPitchShifterPresetList = async() => { -// return await rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_sound_effect_pitch_shifter_preset) +// return rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_sound_effect_pitch_shifter_preset) // } // export const saveUserSoundEffectPitchShifterPresetList = (list: LX.SoundEffect.PitchShifterPreset[]) => { @@ -507,7 +507,7 @@ export const clearLyricRaw = async() => { } export const getLyricRawCount = async() => { - return await rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_lyric_raw_count) + return rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_lyric_raw_count) } @@ -559,7 +559,7 @@ export const clearLyricEdited = async() => { } export const getLyricEditedCount = async() => { - return await rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_lyric_edited_count) + return rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_lyric_edited_count) } @@ -603,7 +603,7 @@ export const clearMusicUrl = async() => { } export const getMusicUrlCount = async() => { - return await rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_music_url_count) + return rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.get_music_url_count) } /** diff --git a/src/renderer/utils/music.ts b/src/renderer/utils/music.ts index 5507c4a4..2e3a53c5 100644 --- a/src/renderer/utils/music.ts +++ b/src/renderer/utils/music.ts @@ -7,7 +7,7 @@ export const checkDownloadFileAvailable = async(musicInfo: LX.Download.ListItem, } export const checkLocalFileAvailable = async(musicInfo: LX.Music.MusicInfoLocal): Promise => { - return await checkPath(musicInfo.meta.filePath) + return checkPath(musicInfo.meta.filePath) } /** @@ -17,9 +17,9 @@ export const checkLocalFileAvailable = async(musicInfo: LX.Music.MusicInfoLocal) */ export const checkMusicFileAvailable = async(musicInfo: LX.Music.MusicInfo | LX.Download.ListItem, savePath: string): Promise => { if ('progress' in musicInfo) { - return await checkDownloadFileAvailable(musicInfo, savePath) + return checkDownloadFileAvailable(musicInfo, savePath) } else if (musicInfo.source == 'local') { - return await checkLocalFileAvailable(musicInfo) + return checkLocalFileAvailable(musicInfo) } else return true } @@ -33,7 +33,7 @@ export const getDownloadFilePath = async(musicInfo: LX.Download.ListItem, savePa } export const getLocalFilePath = async(musicInfo: LX.Music.MusicInfoLocal): Promise => { - return await checkPath(musicInfo.meta.filePath) ? musicInfo.meta.filePath : '' + return (await checkPath(musicInfo.meta.filePath)) ? musicInfo.meta.filePath : '' } @@ -45,9 +45,9 @@ export const getLocalFilePath = async(musicInfo: LX.Music.MusicInfoLocal): Promi */ export const getMusicFilePath = async(musicInfo: LX.Music.MusicInfo | LX.Download.ListItem, savePath: string): Promise => { if ('progress' in musicInfo) { - return await getDownloadFilePath(musicInfo, savePath) + return getDownloadFilePath(musicInfo, savePath) } else if (musicInfo.source == 'local') { - return await getLocalFilePath(musicInfo) + return getLocalFilePath(musicInfo) } return '' } diff --git a/src/renderer/utils/musicSdk/kg/lyric.js b/src/renderer/utils/musicSdk/kg/lyric.js index 3e16e2a7..ab6d341e 100644 --- a/src/renderer/utils/musicSdk/kg/lyric.js +++ b/src/renderer/utils/musicSdk/kg/lyric.js @@ -76,7 +76,7 @@ export default { // }) // requestObj.promise = requestObj.promise.then(({ body, statusCode }) => { // if (statusCode !== 200) { - // if (tryNum > 5) return Promise.reject('歌词获取失败') + // if (tryNum > 5) return Promise.reject(new Error('歌词获取失败')) // let tryRequestObj = this.getLyric(songInfo, ++tryNum) // requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj) // return tryRequestObj.promise @@ -98,7 +98,7 @@ export default { }) requestObj.promise = requestObj.promise.then(({ body, statusCode }) => { if (statusCode !== 200) { - if (tryNum > 5) return Promise.reject('歌词获取失败') + if (tryNum > 5) return Promise.reject(new Error('歌词获取失败')) let tryRequestObj = this.searchLyric(name, hash, time, ++tryNum) requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj) return tryRequestObj.promise @@ -121,7 +121,7 @@ export default { }) requestObj.promise = requestObj.promise.then(({ body, statusCode }) => { if (statusCode !== 200) { - if (tryNum > 5) return Promise.reject('歌词获取失败') + if (tryNum > 5) return Promise.reject(new Error('歌词获取失败')) let tryRequestObj = this.getLyric(id, accessKey, ++tryNum) requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj) return tryRequestObj.promise diff --git a/src/renderer/utils/musicSdk/kg/pic.js b/src/renderer/utils/musicSdk/kg/pic.js index fdb40175..9b28b935 100644 --- a/src/renderer/utils/musicSdk/kg/pic.js +++ b/src/renderer/utils/musicSdk/kg/pic.js @@ -38,10 +38,10 @@ export default { }, ) return requestObj.promise.then(({ body }) => { - if (body.error_code !== 0) return Promise.reject('图片获取失败') + if (body.error_code !== 0) return Promise.reject(new Error('图片获取失败')) let info = body.data[0].info const img = info.imgsize ? info.image.replace('{size}', info.imgsize[0]) : info.image - if (!img) return Promise.reject('Pic get failed') + if (!img) return Promise.reject(new Error('Pic get failed')) return img }) }, diff --git a/src/renderer/utils/musicSdk/mg/lyric.js b/src/renderer/utils/musicSdk/mg/lyric.js index 8511cdb0..7500f143 100644 --- a/src/renderer/utils/musicSdk/mg/lyric.js +++ b/src/renderer/utils/musicSdk/mg/lyric.js @@ -57,7 +57,7 @@ const mrcTools = { }) return requestObj.promise.then(({ statusCode, body }) => { if (statusCode == 200) return body - if (tryNum > 5 || statusCode == 404) return Promise.reject('歌词获取失败') + if (tryNum > 5 || statusCode == 404) return Promise.reject(new Error('歌词获取失败')) return this.getText(url, ++tryNum) }) }, @@ -84,7 +84,7 @@ const mrcTools = { let p if (info.mrcUrl) p = this.getMrc(info.mrcUrl) else if (info.lrcUrl) p = this.getLrc(info.lrcUrl) - if (p == null) return Promise.reject('获取歌词失败') + if (p == null) return Promise.reject(new Error('获取歌词失败')) return Promise.all([p, this.getTrc(info.trcUrl)]).then(([lrcInfo, tlyric]) => { lrcInfo.tlyric = tlyric return lrcInfo @@ -102,7 +102,7 @@ export default { let requestObj = httpFetch(songInfo.lrcUrl) requestObj.promise = requestObj.promise.then(({ body, statusCode }) => { if (statusCode !== 200) { - if (tryNum > 5) return Promise.reject('歌词获取失败') + if (tryNum > 5) return Promise.reject(new Error('歌词获取失败')) let tryRequestObj = this.getLyricWeb(songInfo, ++tryNum) requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj) return tryRequestObj.promise diff --git a/src/renderer/utils/musicSdk/mg/pic.js b/src/renderer/utils/musicSdk/mg/pic.js index 046eba08..cf819ca8 100644 --- a/src/renderer/utils/musicSdk/mg/pic.js +++ b/src/renderer/utils/musicSdk/mg/pic.js @@ -10,7 +10,7 @@ export default { }) requestObj.promise.then(({ body }) => { if (body.returnCode !== '000000') { - if (tryNum > 5) return Promise.reject('图片获取失败') + if (tryNum > 5) return Promise.reject(new Error('图片获取失败')) let tryRequestObj = this.getPic(songId, ++tryNum) requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj) return tryRequestObj.promise diff --git a/src/renderer/utils/musicSdk/mg/songList.js b/src/renderer/utils/musicSdk/mg/songList.js index 841e449b..d811e82e 100644 --- a/src/renderer/utils/musicSdk/mg/songList.js +++ b/src/renderer/utils/musicSdk/mg/songList.js @@ -168,7 +168,7 @@ export default { // return this._requestObj_list.promise.then(({ statusCode, body }) => { // if (statusCode !== 200) return this.getList(sortId, tagId, page) // let list = body.replace(/[\r\n]/g, '').match(this.regExps.list) - // if (!list) return Promise.reject('获取列表失败') + // if (!list) return Promise.reject(new Error('获取列表失败')) // return list.map(item => { // let info = item.match(this.regExps.listInfo) // return { diff --git a/src/renderer/utils/musicSdk/tx/musicInfo.js b/src/renderer/utils/musicSdk/tx/musicInfo.js index 970b8f64..b490a3c1 100644 --- a/src/renderer/utils/musicSdk/tx/musicInfo.js +++ b/src/renderer/utils/musicSdk/tx/musicInfo.js @@ -33,7 +33,7 @@ export default (songmid) => { }) return requestObj.promise.then(({ body }) => { // console.log(body) - if (body.code != 0 || body.req.code != 0) return Promise.reject('获取歌曲信息失败') + if (body.code != 0 || body.req.code != 0) return Promise.reject(new Error('获取歌曲信息失败')) const item = body.req.data.track_info if (!item.file?.media_mid) return null diff --git a/src/renderer/utils/musicSdk/wy/musicInfo.js b/src/renderer/utils/musicSdk/wy/musicInfo.js index 88a5da5b..b9ff0948 100644 --- a/src/renderer/utils/musicSdk/wy/musicInfo.js +++ b/src/renderer/utils/musicSdk/wy/musicInfo.js @@ -17,7 +17,7 @@ export default songmid => { }) requestObj.promise = requestObj.promise.then(({ body }) => { // console.log(body) - if (body.code !== 200 || !body.songs.length) return Promise.reject('获取歌曲信息失败') + if (body.code !== 200 || !body.songs.length) return Promise.reject(new Error('获取歌曲信息失败')) return body.songs[0] }) return requestObj diff --git a/src/renderer/utils/update.js b/src/renderer/utils/update.js index e4630d69..ff83800b 100644 --- a/src/renderer/utils/update.js +++ b/src/renderer/utils/update.js @@ -18,7 +18,7 @@ const address = [ ] const request = async(url, retryNum = 0) => { - return await new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { httpGet(url, { timeout: 10000, }, (err, resp, body) => {