Skip to content

Commit

Permalink
perf: ⚡️ Optimize the stability of options that need to dynamically o…
Browse files Browse the repository at this point in the history
…btain parameters in preference settings
  • Loading branch information
viarotel committed Nov 5, 2024
1 parent 9800980 commit 39bbc98
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 42 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"version": "1.25.4",
"private": true,
"packageManager": "pnpm@9.4.0+sha1.9217c800d4ab947a7aee520242a7b70d64fc7638",
"packageManager": "pnpm@9.12.3",
"description": "Scrcpy Powered by Electron",
"author": "viarotel",
"homepage": "https://github.com/viarotel-org/escrcpy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
v-bind="{
collapseProps: { accordion: true },
excludes: ['common'],
deviceScope: device.id,
}"
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
v-bind="{ clearable: true, ...(data.props || {}) }"
v-model="selectValue"
class="!w-full"
@click="getDeviceOptions"
>
<el-option
v-for="(item, index) in options"
Expand All @@ -15,6 +16,8 @@
</template>

<script>
import { getDeviceId } from '../helper.js'
export default {
props: {
modelValue: {
Expand Down Expand Up @@ -56,21 +59,16 @@ export default {
},
},
},
watch: {
deviceScope: {
handler(value) {
if (value === 'global') {
this.deviceOptions = []
return
}
this.getDeviceOptions()
},
},
},
methods: {
async getDeviceOptions() {
const res = await this.$scrcpy.getEncoders(this.deviceScope)
const deviceId = getDeviceId(this.deviceScope)
if (!deviceId) {
this.deviceOptions = []
return false
}
const res = await this.$scrcpy.getEncoders(deviceId)
this.deviceOptions = res?.audio?.map((item) => {
const value = `${item.decoder} & ${item.encoder}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
}"
v-model="selectValue"
class="!w-full"
@click="getDeviceOptions"
>
<el-option
v-for="(item, index) in options"
Expand All @@ -18,6 +19,8 @@
</template>

<script>
import { getDeviceId } from '../helper.js'
export default {
props: {
modelValue: {
Expand Down Expand Up @@ -56,21 +59,16 @@ export default {
},
},
},
watch: {
deviceScope: {
handler(value) {
if (value === 'global') {
this.deviceOptions = []
return
}
this.getDeviceOptions()
},
},
},
methods: {
async getDeviceOptions() {
const res = await this.$adb.display(this.deviceScope)
const deviceId = getDeviceId(this.deviceScope)
if (!deviceId) {
this.deviceOptions = []
return false
}
const res = await this.$adb.display(deviceId)
this.deviceOptions
= res?.map((item) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
v-bind="{ clearable: true, ...(data.props || {}) }"
v-model="selectValue"
class="!w-full"
@click="getDeviceOptions"
>
<el-option
v-for="(item, index) in options"
Expand All @@ -15,6 +16,8 @@
</template>

<script>
import { getDeviceId } from '../helper.js'
export default {
props: {
modelValue: {
Expand Down Expand Up @@ -56,21 +59,16 @@ export default {
},
},
},
watch: {
deviceScope: {
handler(value) {
if (value === 'global') {
this.deviceOptions = []
return
}
this.getDeviceOptions()
},
},
},
methods: {
async getDeviceOptions() {
const res = await this.$scrcpy.getEncoders(this.deviceScope)
const deviceId = getDeviceId(this.deviceScope)
if (!deviceId) {
this.deviceOptions = []
return false
}
const res = await this.$scrcpy.getEncoders(deviceId)
this.deviceOptions = res?.video?.map((item) => {
const value = `${item.decoder} & ${item.encoder}`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useDeviceStore } from '$/store/device/index.js'

/**
* 获取设备ID
* @param {*} scope
* @returns
*/
export function getDeviceId(scope) {
let value = scope

if (value === 'global') {
value = useDeviceStore().list[0]?.id
}

return value
}
2 changes: 0 additions & 2 deletions src/store/preference/model/video/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ export default {
placeholder: 'preferences.video.display.placeholder',
options: [
{ label: '0', value: '0' },
{ label: '1', value: '1' },
{ label: '2', value: '2' },
],
props: {
filterable: true,
Expand Down

0 comments on commit 39bbc98

Please sign in to comment.