Skip to content

Commit d83c142

Browse files
committed
chore: 调整和升级配置面板
1 parent ade97f1 commit d83c142

File tree

5 files changed

+36
-27
lines changed

5 files changed

+36
-27
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"dependencies": {
7272
"@ant-design/icons": "^4.3.0",
7373
"@apad/rc-slider": "^10.5.0",
74-
"@apad/setting-panel": "^0.3.1",
74+
"@apad/setting-panel": "^0.4.4",
7575
"ahooks": "^3.7.8",
7676
"ass-compiler": "^0.1.11",
7777
"bilibili-live-ws": "^6.3.1",

Diff for: pnpm-lock.yaml

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/store/config/danmaku.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ const config_danmaku = {
4343
opacity: config({
4444
defaultValue: 1,
4545
label: t('settingPanel.opacity'),
46-
desc: t('settingPanel.opacityDesc'),
46+
type: 'range',
47+
range: [0, 1],
4748
}),
4849
fontSize: config({
4950
defaultValue: 16,
5051
label: t('settingPanel.fontSize'),
52+
type: 'range',
53+
range: [12, 32],
54+
rangeStep: 1,
5155
}),
5256
fontWeight: config({
5357
defaultValue: 600,

Diff for: src/store/config/index.ts

+16-20
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import {
66
setBrowserSyncStorage,
77
useBrowserSyncStorage,
88
} from '@root/utils/storage'
9-
import { autorun, makeAutoObservable, observe as mobxObserve } from 'mobx'
9+
import {
10+
autorun,
11+
makeAutoObservable,
12+
observe as mobxObserve,
13+
configure,
14+
} from 'mobx'
1015
import { observer } from 'mobx-react'
1116
import { docPIPConfig } from './docPIP'
1217
import zh from '@apad/setting-panel/i18n/zh_cn.json'
@@ -30,7 +35,13 @@ import isPluginEnv from '@root/shared/isPluginEnv'
3035
import config_floatButton from './floatButton'
3136
import { isUndefined } from 'lodash-es'
3237
import { DEFAULT_EVENT_INJECT_SITE } from '@root/shared/config'
38+
import isDev from '@root/shared/isDev'
3339

40+
if (isDev) {
41+
configure({
42+
enforceActions: 'never',
43+
})
44+
}
3445
export { DocPIPRenderType } from './docPIP'
3546

3647
export enum videoBorderType {
@@ -212,9 +223,10 @@ export const baseConfigMap = {
212223

213224
export const {
214225
configStore,
215-
openSettingPanel: _openSettingPanel,
226+
openSettingPanel,
216227
closeSettingPanel,
217228
observe,
229+
updateConfig: _updateConfig,
218230
} = initSetting({
219231
settings: baseConfigMap,
220232
saveInLocal: !isPluginEnv,
@@ -275,12 +287,7 @@ let oldConfig: typeof configStore
275287
const updateConfig = async (config?: typeof configStore) => {
276288
config ??= await getBrowserSyncStorage(DM_MINI_PLAYER_CONFIG)
277289
if (!config) return
278-
Object.entries(config).forEach(([key, value]) => {
279-
;(configStore as any)[key] = value
280-
})
281-
if (window.__spSetSavedConfig) {
282-
window.__spSetSavedConfig(config)
283-
}
290+
_updateConfig(config)
284291
}
285292

286293
// 同步多个tab的config
@@ -298,11 +305,6 @@ if (isPluginEnv) {
298305
}
299306
}
300307

301-
export function openSettingPanel(renderTarget?: HTMLElement) {
302-
_openSettingPanel(renderTarget)
303-
setTimeout(updateConfig, 50)
304-
}
305-
306308
window.configStore = configStore
307309
window.openSettingPanel = openSettingPanel
308310

@@ -319,13 +321,7 @@ autorun(() => {
319321
})
320322
useBrowserSyncStorage(FLOAT_BTN_HIDDEN, async (val) => {
321323
if (isUndefined(val)) return
322-
const config = await getBrowserSyncStorage(DM_MINI_PLAYER_CONFIG)
323-
324-
if (!config) return
325-
configStore.floatButtonVisible = !val
326-
if (window.__spSetSavedConfig) {
327-
window.__spSetSavedConfig({ ...config, floatButtonVisible: !val })
328-
}
324+
updateConfig()
329325
})
330326

331327
export default configStore

Diff for: src/store/config/subtitle.ts

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const config_subtitle = {
88
subtitle_opacity: config({
99
label: t('settingPanel.subtitleOpacity'),
1010
defaultValue: 1,
11+
type: 'range',
12+
range: [0, 1],
1113
}),
1214
subtitle_bg: config({
1315
label: t('settingPanel.subtitleBg'),
@@ -17,10 +19,15 @@ const config_subtitle = {
1719
subtitle_bgOpacity: config({
1820
label: t('settingPanel.subtitleBgOpacity'),
1921
defaultValue: 0.3,
22+
type: 'range',
23+
range: [0, 1],
2024
}),
2125
subtitle_fontSize: config({
2226
label: t('settingPanel.subtitleFontSize'),
2327
defaultValue: 16,
28+
type: 'range',
29+
range: [12, 32],
30+
rangeStep: 1,
2431
}),
2532
subtitle_fontColor: config({
2633
label: t('settingPanel.subtitleFontColor'),
@@ -34,6 +41,8 @@ const config_subtitle = {
3441
subtitle_fontOpacity: config({
3542
label: t('settingPanel.subtitleFontOpacity'),
3643
defaultValue: 1,
44+
type: 'range',
45+
range: [0, 1],
3746
}),
3847
subtitle_fontFamily: config({
3948
label: t('settingPanel.subtitleFontFamily'),

0 commit comments

Comments
 (0)