perf: ♻️ Optimize configuration file logic

This commit is contained in:
viarotel 2023-11-08 14:59:47 +08:00
parent 0605a81807
commit 5f8cc5a013
10 changed files with 64 additions and 73 deletions

View File

@ -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

View File

@ -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
}
setStoreData(cloneData, replaceIP(scope))
if (data.gnirehtetPath === gnirehtetPath) {
delete pickData.gnirehtetPath
}
setStoreData(pickData, replaceIP(scope))
this.init(scope)
},

View File

@ -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',
},

View File

@ -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',
},

View File

@ -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',
},

View File

@ -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',
},

View File

@ -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',
},

View File

@ -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',
},

View File

@ -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',
},

View File

@ -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',
},
},