From d91999a1ac5ca82e1a73de4790d5fc7b136a745c Mon Sep 17 00:00:00 2001 From: mebtte Date: Thu, 30 Nov 2023 14:01:38 +0800 Subject: [PATCH 1/6] remove unused code --- shared/utils/async_queue.ts | 82 ------------------------------------- 1 file changed, 82 deletions(-) delete mode 100644 shared/utils/async_queue.ts diff --git a/shared/utils/async_queue.ts b/shared/utils/async_queue.ts deleted file mode 100644 index f69c439d..00000000 --- a/shared/utils/async_queue.ts +++ /dev/null @@ -1,82 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import generateRandomString from './generate_random_string'; -import sleep from './sleep'; -import timeout from './timeout'; - -interface Task { - id: string; - task: () => Promise; - resolve: (...params: any[]) => void; - reject: (...params: any[]) => void; -} - -class AsyncQueue { - minimalTaskDuration: number; - - taskTimeout: number; - - taskTimeoutErrorGenerator?: (ms: number) => Error; - - running: boolean; - - taskQueue: Task[]; - - constructor({ - minimalTaskDuration = 500, - taskTimeout = 10 * 1000, - taskTimeoutErrorGenerator, - }: { - minimalTaskDuration?: number; - taskTimeout?: number; - taskTimeoutErrorGenerator?: (ms: number) => Error; - } = {}) { - this.minimalTaskDuration = minimalTaskDuration; - this.taskTimeout = taskTimeout; - this.taskTimeoutErrorGenerator = taskTimeoutErrorGenerator; - - this.running = false; - this.taskQueue = []; - } - - run(task: () => Promise) { - const id = generateRandomString(); - return new Promise((resolve, reject) => { - this.taskQueue.push({ - id, - task, - resolve, - reject, - }); - return this.nextTask(); - }); - } - - clear() { - this.taskQueue = []; - } - - private async nextTask() { - if (this.running || !this.taskQueue.length) { - return; - } - - this.running = true; - - const [{ task, resolve, reject }] = this.taskQueue.splice(0, 1); - try { - const [result] = await Promise.race([ - Promise.all([task(), sleep(this.minimalTaskDuration)]), - timeout(this.taskTimeout, this.taskTimeoutErrorGenerator), - ]); - resolve(result as Result); - } catch (error) { - reject(error); - } - - this.running = false; - - globalThis.setTimeout(this.nextTask.bind(this), 0); - } -} - -export default AsyncQueue; From 53e21edc1b98cf84315211f7b9458377a29a5ec6 Mon Sep 17 00:00:00 2001 From: mebtte Date: Fri, 8 Dec 2023 18:13:12 +0800 Subject: [PATCH 2/6] improve i18n --- apps/pwa/src/pages/player/pages/search/input.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/pwa/src/pages/player/pages/search/input.tsx b/apps/pwa/src/pages/player/pages/search/input.tsx index 89941442..f3fe9840 100644 --- a/apps/pwa/src/pages/player/pages/search/input.tsx +++ b/apps/pwa/src/pages/player/pages/search/input.tsx @@ -5,6 +5,7 @@ import parseSearch from '@/utils/parse_search'; import { useState } from 'react'; import { useLocation } from 'react-router-dom'; import { t } from '@/i18n'; +import upperCaseFirstLetter from '#/utils/upper_case_first_letter'; function Wrapper() { const navigate = useNavigate(); @@ -17,7 +18,7 @@ function Wrapper() { setKeyword(e.target.value)} From 17cc83ae4f6d216fcff04ed1949d01c201f90a1d Mon Sep 17 00:00:00 2001 From: mebtte Date: Tue, 19 Dec 2023 15:36:09 +0800 Subject: [PATCH 3/6] add wakelock --- apps/pwa/src/index.tsx | 2 +- .../pages/player/lyric_panel/lyric_panel.tsx | 2 + .../pages/player/lyric_panel/wake_lock.tsx | 42 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 apps/pwa/src/pages/player/lyric_panel/wake_lock.tsx diff --git a/apps/pwa/src/index.tsx b/apps/pwa/src/index.tsx index 8e97970a..28ed34be 100644 --- a/apps/pwa/src/index.tsx +++ b/apps/pwa/src/index.tsx @@ -1,4 +1,4 @@ -import './polyfill'; // 需要保证 polyfill 在第一个 +import './polyfill'; // make sure that polyfill is first import './updater'; import './devtool'; import { createRoot } from 'react-dom/client'; diff --git a/apps/pwa/src/pages/player/lyric_panel/lyric_panel.tsx b/apps/pwa/src/pages/player/lyric_panel/lyric_panel.tsx index 05379dc3..3aaa1ca2 100644 --- a/apps/pwa/src/pages/player/lyric_panel/lyric_panel.tsx +++ b/apps/pwa/src/pages/player/lyric_panel/lyric_panel.tsx @@ -7,6 +7,7 @@ import Context from '../context'; import Backdrop from './backdrop'; import Controller from './controller'; import Lyric from './lyric'; +import WakeLock from './wake_lock'; const Style = styled(animated.div)` z-index: ${ZIndex.LYRIC_PANEL}; @@ -31,6 +32,7 @@ function LyricPanel({ style }: { style: unknown }) { return ( // @ts-expect-error