From 5f8cc5a01312b95bd177509b824f1f2c7a8a531e Mon Sep 17 00:00:00 2001 From: viarotel Date: Wed, 8 Nov 2023 14:59:47 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E2=99=BB=EF=B8=8F=20Optimize=20configu?= =?UTF-8?q?ration=20file=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/preference/helpers/index.js | 13 ++++------ src/store/preference/index.js | 30 ++++++++++------------ src/store/preference/model/audio/index.js | 14 +++++----- src/store/preference/model/camera/index.js | 10 ++++---- src/store/preference/model/common/index.js | 8 +++--- src/store/preference/model/device/index.js | 12 ++++----- src/store/preference/model/otg/index.js | 6 ++--- src/store/preference/model/record/index.js | 12 ++++----- src/store/preference/model/video/index.js | 24 ++++++++--------- src/store/preference/model/window/index.js | 8 +++--- 10 files changed, 64 insertions(+), 73 deletions(-) diff --git a/src/store/preference/helpers/index.js b/src/store/preference/helpers/index.js index 19a10184..5a8fe289 100644 --- a/src/store/preference/helpers/index.js +++ b/src/store/preference/helpers/index.js @@ -98,21 +98,18 @@ export function setStoreData(data, scope) { }) } -export function mergeConfig(object, sources, { debug = false } = {}) { +export function mergeConfig(object, sources) { const cloneObject = cloneDeep(object) const cloneSources = cloneDeep(sources) const customizer = (objValue, srcValue, key) => { - let value = srcValue || objValue + let value - if (typeof srcValue === 'boolean') { + if (srcValue) { value = srcValue } - - if (debug) { - console.log(`srcValue.${key}`, srcValue) - console.log(`objValue.${key}`, objValue) - console.log(key, value) + else if (objValue) { + value = objValue } return value diff --git a/src/store/preference/index.js b/src/store/preference/index.js index ea12f901..0f8a608b 100644 --- a/src/store/preference/index.js +++ b/src/store/preference/index.js @@ -1,5 +1,5 @@ import { defineStore } from 'pinia' -import { cloneDeep, get, set } from 'lodash-es' +import { cloneDeep, get, pickBy, set } from 'lodash-es' import model from './model/index.js' import { @@ -13,7 +13,7 @@ import { import { replaceIP, restoreIP } from '@/utils/index.js' -const { adbPath, scrcpyPath } = window.electron?.configs || {} +const { adbPath, scrcpyPath, gnirehtetPath } = window.electron?.configs || {} export const usePreferenceStore = defineStore({ id: 'app-preference', @@ -54,15 +54,10 @@ export const usePreferenceStore = defineStore({ actions: { getDefaultData, init(scope = this.deviceScope) { - const globalData = mergeConfig(getDefaultData(), getStoreData()) + let data = mergeConfig(getDefaultData(), getStoreData()) - let data = {} - - if (scope === 'global') { - data = globalData - } - else { - data = mergeConfig(globalData, getStoreData(replaceIP(scope))) + if (scope !== 'global') { + data = mergeConfig(data, getStoreData(replaceIP(scope))) } this.data = data @@ -75,20 +70,21 @@ export const usePreferenceStore = defineStore({ this.init() }, setData(data, scope = this.deviceScope) { - const cloneData = cloneDeep(data) - - // console.log('adbPath', adbPath) - // console.log('scrcpyPath', scrcpyPath) + const pickData = pickBy(data, value => !!value) if (data.adbPath === adbPath) { - delete cloneData.adbPath + delete pickData.adbPath } if (data.scrcpyPath === scrcpyPath) { - delete cloneData.scrcpyPath + delete pickData.scrcpyPath + } + + if (data.gnirehtetPath === gnirehtetPath) { + delete pickData.gnirehtetPath } - setStoreData(cloneData, replaceIP(scope)) + setStoreData(pickData, replaceIP(scope)) this.init(scope) }, diff --git a/src/store/preference/model/audio/index.js b/src/store/preference/model/audio/index.js index 596cd977..70a4c142 100644 --- a/src/store/preference/model/audio/index.js +++ b/src/store/preference/model/audio/index.js @@ -7,7 +7,7 @@ export default { label: 'preferences.audio.audio-source.name', field: '--audio-source', type: 'Select', - value: '', + value: undefined, placeholder: 'preferences.audio.audio-source.placeholder', tips: 'preferences.audio.audio-source.tips', options: [ @@ -19,7 +19,7 @@ export default { label: 'preferences.audio.audio-code.name', field: '--audio-code', type: 'AudioCodecSelect', - value: '', + value: undefined, placeholder: 'preferences.audio.audio-code.placeholder', options: [ { @@ -40,18 +40,18 @@ export default { audioCodec: { hidden: true, field: '--audio-codec', - value: '', + value: undefined, }, audioEncoder: { hidden: true, field: '--audio-encoder', - value: '', + value: undefined, }, audioBitRate: { label: 'preferences.audio.audio-bit-rate.name', field: '--audio-bit-rate', type: 'Input.number', - value: '', + value: undefined, placeholder: 'preferences.audio.audio-bit-rate.placeholder', append: 'bps', }, @@ -59,7 +59,7 @@ export default { label: 'preferences.audio.audio-buffer.name', field: '--audio-buffer', type: 'Input.number', - value: '', + value: undefined, placeholder: 'preferences.audio.audio-buffer.placeholder', append: 'ms', }, @@ -67,7 +67,7 @@ export default { label: 'preferences.audio.audio-output-buffer.name', field: '--audio-output-buffer', type: 'Input.number', - value: '', + value: undefined, placeholder: 'preferences.audio.audio-output-buffer.placeholder', append: 'ms', }, diff --git a/src/store/preference/model/camera/index.js b/src/store/preference/model/camera/index.js index 119a6981..abbc1f01 100644 --- a/src/store/preference/model/camera/index.js +++ b/src/store/preference/model/camera/index.js @@ -6,7 +6,7 @@ export default { label: 'preferences.camera.enable.name', field: '--camera', type: 'CameraSwitch', - value: null, + value: undefined, placeholder: 'preferences.camera.enable.placeholder', tips: 'preferences.camera.enable.tips', }, @@ -14,7 +14,7 @@ export default { label: 'preferences.camera.camera-facing.name', field: '--camera-facing', type: 'Select', - value: '', + value: undefined, placeholder: 'preferences.camera.camera-facing.placeholder', options: [ { label: 'preferences.camera.camera-facing.front', value: 'front' }, @@ -29,21 +29,21 @@ export default { label: 'preferences.camera.camera-size.name', field: '--camera-size', type: 'Input', - value: '', + value: undefined, placeholder: 'preferences.camera.camera-size.placeholder', }, cameraAr: { label: 'preferences.camera.camera-ar.name', field: '--camera-ar', type: 'Input', - value: '', + value: undefined, placeholder: 'preferences.camera.camera-ar.placeholder', }, cameraFps: { label: 'preferences.camera.camera-fps.name', field: '--camera-fps', type: 'Input.number', - value: '', + value: undefined, placeholder: 'preferences.camera.camera-fps.placeholder', append: 'fps', }, diff --git a/src/store/preference/model/common/index.js b/src/store/preference/model/common/index.js index 86b396fe..45416050 100644 --- a/src/store/preference/model/common/index.js +++ b/src/store/preference/model/common/index.js @@ -14,7 +14,6 @@ export default { type: 'Select', value: 'system', placeholder: 'preferences.common.theme.placeholder', - tips: '', options: [ { label: 'preferences.common.theme.options[0]', @@ -36,7 +35,6 @@ export default { type: 'LanguageSelect', value: defaultLanguage, placeholder: 'preferences.common.language.placeholder', - tips: '', options: [ { label: 'preferences.common.language.chinese', @@ -92,7 +90,7 @@ export default { scrcpyAppend: { label: 'preferences.common.scrcpy.append.name', field: 'scrcpyAppend', - value: '', + value: undefined, type: 'Input', placeholder: 'preferences.common.scrcpy.append.placeholder', tips: 'preferences.common.scrcpy.append.tips', @@ -106,7 +104,7 @@ export default { label: 'preferences.common.gnirehtet.fix.name', field: 'gnirehtetFix', type: 'Switch', - value: false, + value: undefined, placeholder: 'preferences.common.gnirehtet.fix.placeholder', tips: 'preferences.common.gnirehtet.fix.tips', }, @@ -114,7 +112,7 @@ export default { label: 'preferences.common.debug.name', field: 'debug', type: 'Switch', - value: false, + value: undefined, placeholder: 'preferences.common.debug.placeholder', tips: 'preferences.common.debug.tips', }, diff --git a/src/store/preference/model/device/index.js b/src/store/preference/model/device/index.js index 013cae64..4654b03f 100644 --- a/src/store/preference/model/device/index.js +++ b/src/store/preference/model/device/index.js @@ -6,7 +6,7 @@ export default { label: 'preferences.device.show-touch.name', field: '--show-touches', type: 'Switch', - value: null, + value: undefined, placeholder: 'preferences.device.show-touch.placeholder', tips: 'preferences.device.show-touch.tips', }, @@ -14,7 +14,7 @@ export default { label: 'preferences.device.stay-awake.name', field: '--stay-awake', type: 'Switch', - value: null, + value: undefined, placeholder: 'preferences.device.stay-awake.placeholder', tips: 'preferences.device.stay-awake.tips', }, @@ -22,21 +22,21 @@ export default { label: 'preferences.device.control-in-close-screen.name', field: '--turn-screen-off', type: 'Switch', - value: null, + value: undefined, placeholder: 'preferences.device.control-in-close-screen.placeholder', }, powerOffOnClose: { label: 'preferences.device.control-end-video.name', field: '--power-off-on-close', type: 'Switch', - value: null, + value: undefined, placeholder: 'preferences.device.control-end-video.placeholder', }, noPowerOn: { label: 'preferences.device.control-in-stop-charging.name', field: '--no-power-on', type: 'Switch', - value: null, + value: undefined, placeholder: 'preferences.device.control-in-stop-charging.placeholder', tips: 'preferences.device.control-in-stop-charging.tips', }, @@ -44,7 +44,7 @@ export default { label: 'preferences.device.display-overlay.name', field: '--display-overlay', type: 'Input', - value: '', + value: undefined, placeholder: 'preferences.device.display-overlay.placeholder', tips: 'preferences.device.display-overlay.tips', }, diff --git a/src/store/preference/model/otg/index.js b/src/store/preference/model/otg/index.js index 746537b7..532f7db9 100644 --- a/src/store/preference/model/otg/index.js +++ b/src/store/preference/model/otg/index.js @@ -7,7 +7,7 @@ export default { label: 'preferences.otg.enable.name', field: '--otg', type: 'Switch', - value: null, + value: undefined, placeholder: 'preferences.otg.enable.placeholder', tips: 'preferences.otg.enable.tips', }, @@ -15,7 +15,7 @@ export default { label: 'preferences.otg.only-keyboard.name', field: '--hid-keyboard', type: 'Switch', - value: null, + value: undefined, placeholder: 'preferences.otg.only-keyboard.placeholder', tips: 'preferences.otg.only-keyboard.tips', }, @@ -23,7 +23,7 @@ export default { label: 'preferences.otg.only-mouse.name', field: '--hid-mouse', type: 'Switch', - value: null, + value: undefined, placeholder: 'preferences.otg.only-mouse.placeholder', tips: 'preferences.otg.only-mouse.tips', }, diff --git a/src/store/preference/model/record/index.js b/src/store/preference/model/record/index.js index ae615d30..8afcaba6 100644 --- a/src/store/preference/model/record/index.js +++ b/src/store/preference/model/record/index.js @@ -23,7 +23,7 @@ export default { label: 'preferences.record.lock-video-orientation.name', field: '--lock-video-orientation', type: 'Select', - value: '', + value: undefined, placeholder: 'preferences.record.lock-video-orientation.placeholder', options: [ { label: '0°', value: '0' }, @@ -36,7 +36,7 @@ export default { label: 'preferences.record.time-limit.name', field: '--time-limit', type: 'Input.number', - value: '', + value: undefined, placeholder: 'preferences.record.time-limit.placeholder', append: 's', span: 24, @@ -45,21 +45,21 @@ export default { label: 'preferences.record.disable-video.name', field: '--no-video', type: 'Switch', - value: null, + value: undefined, placeholder: 'preferences.record.disable-video.placeholder', }, noAudio: { label: 'preferences.record.disable-audio.name', field: '--no-audio', type: 'Switch', - value: null, + value: undefined, placeholder: 'preferences.record.disable-audio.placeholder', }, noVideoPlayback: { label: 'preferences.record.no-video-playback.name', field: '--no-video-playback', type: 'Switch', - value: null, + value: undefined, placeholder: 'preferences.record.no-video-playback.placeholder', tips: 'preferences.record.no-video-playback.tips', }, @@ -67,7 +67,7 @@ export default { label: 'preferences.record.no-audio-playback.name', field: '--no-audio-playback', type: 'Switch', - value: null, + value: undefined, placeholder: 'preferences.record.no-audio-playback.placeholder', tips: 'preferences.record.no-audio-playback.tips', }, diff --git a/src/store/preference/model/video/index.js b/src/store/preference/model/video/index.js index 300d2677..b21a1314 100644 --- a/src/store/preference/model/video/index.js +++ b/src/store/preference/model/video/index.js @@ -8,7 +8,7 @@ export default { label: 'preferences.video.video-source.name', field: '--video-source', type: 'Select', - value: '', + value: undefined, placeholder: 'preferences.video.video-source.placeholder', options: [ { @@ -25,14 +25,14 @@ export default { label: 'preferences.video.resolution.name', field: '--max-size', type: 'Input.number', - value: '', + value: undefined, placeholder: 'preferences.video.resolution.placeholder', }, videoBitRate: { label: 'preferences.video.bit.name', field: '--video-bit-rate', type: 'Input.number', - value: '', + value: undefined, placeholder: 'preferences.video.bit.placeholder', append: 'bps', }, @@ -40,7 +40,7 @@ export default { label: 'preferences.video.refresh-rate.name', field: '--max-fps', type: 'Input.number', - value: '', + value: undefined, placeholder: 'preferences.video.refresh-rate.placeholder', append: 'fps', }, @@ -48,7 +48,7 @@ export default { label: 'preferences.video.video-code.name', field: '--video-code', type: 'VideoCodecSelect', - value: '', + value: undefined, placeholder: 'preferences.video.video-code.placeholder', options: [ { @@ -76,18 +76,18 @@ export default { videoCodec: { hidden: true, field: '--video-codec', - value: '', + value: undefined, }, videoEncoder: { hidden: true, field: '--video-encoder', - value: '', + value: undefined, }, rotation: { label: 'preferences.video.screen-rotation.name', field: '--rotation', type: 'Select', - value: '', + value: undefined, placeholder: 'preferences.video.screen-rotation.placeholder', options: [ { label: '0°', value: '0' }, @@ -100,14 +100,14 @@ export default { label: 'preferences.video.screen-cropping.name', field: '--crop', type: 'Input', - value: '', + value: undefined, placeholder: 'preferences.video.screen-cropping.placeholder', }, displayId: { label: 'preferences.video.display.name', field: '--display-id', type: 'DisplaySelect', - value: '', + value: undefined, placeholder: 'preferences.video.display.placeholder', options: [ { label: '0', value: '0' }, @@ -123,7 +123,7 @@ export default { label: 'preferences.video.video-buffer.name', field: '--display-buffer', type: 'Input.number', - value: '', + value: undefined, placeholder: 'preferences.video.video-buffer.placeholder', append: 'ms', }, @@ -131,7 +131,7 @@ export default { label: 'preferences.video.receiver-buffer.name', field: '--v4l2-buffer', type: 'Input.number', - value: '', + value: undefined, placeholder: 'preferences.video.receiver-buffer.placeholder', append: 'ms', }, diff --git a/src/store/preference/model/window/index.js b/src/store/preference/model/window/index.js index 552223e4..1957b14c 100644 --- a/src/store/preference/model/window/index.js +++ b/src/store/preference/model/window/index.js @@ -7,28 +7,28 @@ export default { label: 'preferences.window.borderless.name', field: '--window-borderless', type: 'Switch', - value: null, + value: undefined, placeholder: 'preferences.window.borderless.placeholder', }, fullscreen: { label: 'preferences.window.full-screen.name', field: '--fullscreen', type: 'Switch', - value: null, + value: undefined, placeholder: 'preferences.window.full-screen.placeholder', }, alwaysOnTop: { label: 'preferences.window.always-top.name', field: '--always-on-top', type: 'Switch', - value: null, + value: undefined, placeholder: 'preferences.window.always-top.placeholder', }, disableScreensaver: { label: 'preferences.window.disable-screen-saver.name', field: '--disable-screensaver', type: 'Switch', - value: null, + value: undefined, placeholder: 'preferences.window.disable-screen-saver.placeholder', }, },