Skip to content

Commit

Permalink
perf: ♻️ Optimize custom startup performance
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Jul 14, 2024
1 parent ff0d1cc commit abd468b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,51 +1,50 @@
<template>
<TemplatePromise v-slot="{ resolve, reject }">
<el-dialog
v-model="visible"
:title="$t('device.actions.more.custom.name')"
class="w-[98%] el-dialog-flex el-dialog-beautify"
append-to-body
destroy-on-close
@close="close(reject)"
>
<div class="h-full overflow-auto -mx-2 pr-2">
<PreferenceForm
ref="preferenceFormRef"
v-model="preferenceData"
tag="el-collapse-item"
v-bind="{
collapseProps: { accordion: true },
excludes: ['common'],
}"
/>
</div>

<template #footer>
<el-button @click="close(reject)">
{{ $t('common.cancel') }}
</el-button>
<el-button type="primary" @click="submit(resolve)">
{{ $t('common.confirm') }}
</el-button>
</template>
</el-dialog>
</TemplatePromise>
<el-dialog
v-model="visible"
:title="$t('device.actions.more.custom.name')"
class="w-[98%] el-dialog-flex el-dialog-beautify"
append-to-body
destroy-on-close
@closed="onClosed"
>
<div class="h-full overflow-auto -mx-2 pr-2">
<PreferenceForm
ref="preferenceFormRef"
v-model="preferenceData"
tag="el-collapse-item"
v-bind="{
collapseProps: { accordion: true },
excludes: ['common'],
}"
/>
</div>

<template #footer>
<el-button @click="close">
{{ $t('common.cancel') }}
</el-button>
<el-button type="primary" :loading @click="submit">
{{ $t('common.confirm') }}
</el-button>
</template>
</el-dialog>
</template>

<script setup>
import { createTemplatePromise } from '@vueuse/core'
import { nextTick } from 'vue'
import { usePreferenceStore } from '$/store/index.js'
import PreferenceForm from '$/components/Preference/components/PreferenceForm/index.vue'
const TemplatePromise = createTemplatePromise()
import { sleep } from '$/utils'
const emit = defineEmits(['success'])
const preferenceStore = usePreferenceStore()
const visible = ref(false)
const loading = ref(false)
const preferenceFormRef = ref(null)
const preferenceData = ref({
Expand All @@ -56,29 +55,32 @@ const collapseValue = ref([])
const device = ref(null)
async function open(row) {
device.value = row
async function open(args = {}) {
device.value = args.row
visible.value = true
}
return TemplatePromise.start()
async function close() {
visible.value = false
}
async function submit(resolve) {
const data = await preferenceFormRef.value.generateCommand()
async function submit() {
loading.value = true
visible.value = false
const command = await preferenceFormRef.value.generateCommand()
resolve(data)
}
emit('success', command)
async function close(reject) {
visible.value = false
await sleep()
await nextTick()
loading.value = false
preferenceData.value = { ...getDefaultData() }
visible.value = false
}
reject(new Error('User cancel operation'))
function onClosed() {
preferenceData.value = { ...getDefaultData() }
}
function getDefaultData() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<slot :loading="loading" :trigger="handleClick" />

<DeployDialog ref="deployDialogRef" />
<DeployDialog ref="deployDialogRef" @success="handleScrcpy" />
</template>

<script>
Expand Down Expand Up @@ -31,18 +31,12 @@ export default {
async handleClick() {
const row = this.row
this.loading = true
let args = ''
this.$refs.deployDialogRef.open({ row })
},
async handleScrcpy(args) {
const row = this.row
try {
args = await this.$refs.deployDialogRef.open(row)
}
catch (error) {
this.loading = false
this.$message.warning(error.message)
return false
}
this.loading = true
/** TODO */
const isCamera = ['--camera-facing'].some(key => args.includes(key))
Expand Down

0 comments on commit abd468b

Please sign in to comment.