Skip to content

Commit

Permalink
perf: ✅ Support switching devices on the floating control bar
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Sep 12, 2024
1 parent 8807e50 commit 50440f5
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 19 deletions.
2 changes: 1 addition & 1 deletion control/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
></div>

<div class="flex-1 w-0 overflow-hidden h-full">
<ControlBar class="!h-full" :device="deviceInfo" />
<ControlBar class="!h-full" :device="deviceInfo" floating />
</div>

<div
Expand Down
34 changes: 28 additions & 6 deletions src/components/Device/components/ControlBar/Application/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@

<script>
import { allSettledWrapper } from '$/utils'
import { adaptiveMessage } from '$/utils/modal/index.js'
export default {
props: {
device: {
type: Object,
default: () => ({}),
},
floating: {
type: Boolean,
default: () => false,
},
},
data() {
return {}
Expand Down Expand Up @@ -41,18 +46,24 @@ export default {
if (error.message) {
const message
= error.message?.match(/Error: (.*)/)?.[1] || error.message
this.$message.warning(message)
adaptiveMessage(message, { type: 'warning', system: this.floating })
}
return false
}
}
let closeLoading = null
if (!silent) {
closeLoading = this.$message.loading(
closeLoading = adaptiveMessage(
this.$t('device.control.install.progress', {
deviceName: this.$store.device.getLabel(device),
}),
{
type: 'loading',
system: this.floating,
},
).close
}
Expand All @@ -69,33 +80,44 @@ export default {
return false
}
closeLoading()
closeLoading?.()
const totalCount = files.length
const successCount = totalCount - failCount
if (successCount) {
if (totalCount > 1) {
this.$message.success(
adaptiveMessage(
this.$t('device.control.install.success', {
deviceName: this.$store.device.getLabel(device),
totalCount,
successCount,
failCount,
}),
{
type: 'success',
system: this.floating,
},
)
}
else {
this.$message.success(
adaptiveMessage(
this.$t('device.control.install.success.single', {
deviceName: this.$store.device.getLabel(device),
}),
{
type: 'success',
system: this.floating,
},
)
}
return false
}
this.$message.warning(this.$t('device.control.install.error'))
adaptiveMessage(this.$t('device.control.install.error'), {
type: 'warning',
system: this.floating,
})
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ const props = defineProps({
type: Object,
default: () => ({}),
},
floating: {
type: Boolean,
default: false,
},
})
const { loading, invoke: handleClick } = useScreenshotAction()
const { loading, invoke: handleClick } = useScreenshotAction({
floating: props.floating,
})
</script>

<style></style>
30 changes: 25 additions & 5 deletions src/components/Device/components/ControlBar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
class="flex-none"
v-bind="{
device,
floating,
...(item.command
? {
onClick: () => handleShell(item),
Expand Down Expand Up @@ -94,36 +95,48 @@ export default {
type: Object,
default: () => ({}),
},
floating: {
type: Boolean,
default: false,
},
},
data() {
return {
controlModel: [
return {}
},
computed: {
controlModel() {
const value = [
{
label: 'device.control.switch',
elIcon: 'Switch',
command: 'input keyevent 187',
visibleList: ['floating'],
},
{
label: 'device.control.home',
svgIcon: 'home',
command: 'input keyevent 3',
visibleList: ['floating'],
},
{
label: 'device.control.return',
elIcon: 'Back',
command: 'input keyevent 4',
visibleList: ['floating'],
},
{
label: 'device.control.notification',
elIcon: 'Notification',
command: 'cmd statusbar expand-notifications',
tips: 'device.control.notification.tips',
visibleList: ['floating'],
},
{
label: 'device.control.power',
elIcon: 'SwitchButton',
command: 'input keyevent 26',
tips: 'device.control.power.tips',
visibleList: ['floating'],
},
{
label: 'device.control.rotation.name',
Expand All @@ -139,16 +152,19 @@ export default {
label: 'device.control.capture',
elIcon: 'Crop',
component: 'Screenshot',
visibleList: ['floating'],
},
{
label: 'device.control.reboot',
elIcon: 'RefreshLeft',
command: 'reboot',
visibleList: ['floating'],
},
{
label: 'device.control.install',
svgIcon: 'install',
component: 'Application',
visibleList: ['floating'],
},
{
label: 'device.control.file.name',
Expand Down Expand Up @@ -179,10 +195,14 @@ export default {
component: 'MirrorGroup',
tips: 'device.control.mirror-group.tips',
},
],
}
]
return value.filter(
item =>
!this.floating || (item.visibleList ?? []).includes('floating'),
)
},
},
computed: {},
methods: {
handlePrev() {
this.$refs.scrollableRef.scrollBackward()
Expand Down
16 changes: 10 additions & 6 deletions src/composables/useScreenshotAction/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useDeviceStore, usePreferenceStore } from '$/store'

import { allSettledWrapper } from '$/utils/index.js'
import { adaptiveMessage } from '$/utils/modal/index.js'

import { ElMessage } from 'element-plus'

export function useScreenshotAction() {
export function useScreenshotAction({ floating } = {}) {
const deviceStore = useDeviceStore()
const preferenceStore = usePreferenceStore()

Expand All @@ -23,7 +24,7 @@ export function useScreenshotAction() {
async function singleInvoke(device, { silent = false } = {}) {
let closeLoading

if (!silent) {
if (!silent && !floating) {
closeLoading = ElMessage.loading(
window.t('device.control.capture.progress', {
deviceName: deviceStore.getLabel(device),
Expand Down Expand Up @@ -53,12 +54,15 @@ export function useScreenshotAction() {
return false
}

closeLoading()
closeLoading?.()

ElMessage.success(
`${window.t('device.control.capture.success.message.title')}: ${savePath}`,
)
const successMessage = `${window.t(
'device.control.capture.success.message.title',
)}: ${savePath}`

adaptiveMessage(successMessage, { type: 'success', system: floating })
}

async function multipleInvoke(devices) {
loading.value = true

Expand Down
3 changes: 3 additions & 0 deletions src/locales/languages/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"common.delete": "Delete",
"common.name": "Name",
"common.size": "Size",
"common.warning": "Warning",
"common.info": "Message",
"common.danger": "Error",

"common.language.name": "Language",
"common.language.placeholder": "Select language",
Expand Down
3 changes: 3 additions & 0 deletions src/locales/languages/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"common.delete": "删除",
"common.name": "名称",
"common.size": "大小",
"common.warning": "警告",
"common.info": "消息",
"common.danger": "错误",

"common.language.name": "语言",
"common.language.placeholder": "选择你需要的语言",
Expand Down
3 changes: 3 additions & 0 deletions src/locales/languages/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"common.delete": "刪除",
"common.name": "名稱",
"common.size": "大小",
"common.warning": "警告",
"common.info": "消息",
"common.danger": "錯誤",

"common.language.name": "語言",
"common.language.placeholder": "選擇你要的語言",
Expand Down
17 changes: 17 additions & 0 deletions src/utils/modal/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ElMessage } from 'element-plus'
import logoPath from '$electron/resources/build/logo.png'

export function adaptiveMessage(content, { type, system } = {}) {
if (system) {
new Notification(window.t(`common.${type}`), {
icon: logoPath,
body: content,
})

return {
close: () => false,
}
}

return ElMessage[type](content)
}

0 comments on commit 50440f5

Please sign in to comment.