diff --git a/electron/main.js b/electron/main.js
index f48beca8..bbffed26 100644
--- a/electron/main.js
+++ b/electron/main.js
@@ -61,7 +61,7 @@ let mainWindow
function createWindow() {
const bounds = appStore.get('common.bounds') || {}
- const baseWidth = 640
+ const baseWidth = 768
const baseHeight = Number((baseWidth / 1.57).toFixed())
mainWindow = new BrowserWindow({
diff --git a/src/components/ControlBar/index.vue b/src/components/ControlBar/index.vue
index 28d9a51e..0c817e6d 100644
--- a/src/components/ControlBar/index.vue
+++ b/src/components/ControlBar/index.vue
@@ -29,7 +29,7 @@
type="primary"
plain
class="!border-none !mx-0 bg-transparent !rounded-0"
- :disabled="device.$unauthorized"
+ :disabled="device.unauthorized"
:title="$t(item.tips || item.label)"
:loading="loading"
@click="handleClick(item, trigger || item.trigger)"
diff --git a/src/components/TaskListDialog/index.vue b/src/components/TaskListDialog/index.vue
index b7acbb2d..3d7f3cbf 100644
--- a/src/components/TaskListDialog/index.vue
+++ b/src/components/TaskListDialog/index.vue
@@ -96,7 +96,7 @@
diff --git a/src/dicts/device/index.js b/src/dicts/device/index.js
index ea5010db..ad31af2a 100644
--- a/src/dicts/device/index.js
+++ b/src/dicts/device/index.js
@@ -1,4 +1,9 @@
export const deviceStatus = [
+ {
+ label: 'device.status.offline',
+ value: 'offline',
+ tagType: 'info',
+ },
{
label: 'device.status.unauthorized',
value: 'unauthorized',
diff --git a/src/locales/languages/zh-CN.json b/src/locales/languages/zh-CN.json
index f2bae4fb..a2523c81 100644
--- a/src/locales/languages/zh-CN.json
+++ b/src/locales/languages/zh-CN.json
@@ -63,6 +63,7 @@
"device.permission.error": "设备可能未授权成功,请重新插拔设备并点击允许USB调试",
"device.terminal.name": "终端调试",
"device.status": "状态",
+ "device.status.offline": "已离线",
"device.status.unauthorized": "未授权",
"device.status.connected": "已连接",
diff --git a/src/pages/device/components/MirrorAction/index.vue b/src/pages/device/components/MirrorAction/index.vue
index c608464a..272c62b6 100644
--- a/src/pages/device/components/MirrorAction/index.vue
+++ b/src/pages/device/components/MirrorAction/index.vue
@@ -2,7 +2,7 @@
diff --git a/src/pages/device/components/Remark/index.vue b/src/pages/device/components/Remark/index.vue
index 2a6d8678..5a87ca50 100644
--- a/src/pages/device/components/Remark/index.vue
+++ b/src/pages/device/components/Remark/index.vue
@@ -11,14 +11,14 @@
- {{ device.$remark || $t('device.remark') }}
+ {{ device.remark || $t('device.remark') }}
- {{ row.$name }}
+ {{ row.name }}
-
+
WIFI
@@ -242,7 +242,7 @@ export default {
},
toggleRowExpansion(...args) {
- this.$refs.elTable.toggleRowExpansion(...args)
+ this.$refs.tableRef.toggleRowExpansion(...args)
},
handleConnect(...args) {
diff --git a/src/pages/preference/components/ScopeSelect/index.vue b/src/pages/preference/components/ScopeSelect/index.vue
index c96697e3..47fd20e1 100644
--- a/src/pages/preference/components/ScopeSelect/index.vue
+++ b/src/pages/preference/components/ScopeSelect/index.vue
@@ -45,8 +45,8 @@ const deviceStore = useDeviceStore()
const options = computed(() => {
const value = deviceStore.list.map(item => ({
...item,
- label: `${item.id}(${item.$name}${
- item.$remark ? `,${item.$remark}` : ''
+ label: `${item.id}(${item.name}${
+ item.remark ? `,${item.remark}` : ''
})`,
value: item.id,
}))
diff --git a/src/store/device/helpers/index.js b/src/store/device/helpers/index.js
new file mode 100644
index 00000000..30fa00ab
--- /dev/null
+++ b/src/store/device/helpers/index.js
@@ -0,0 +1,65 @@
+import { defaultsDeep, keyBy, omit } from 'lodash-es'
+import { isIPWithPort, replaceIP } from '$/utils/index.js'
+
+/**
+ * 获取设备名称
+ */
+export function getDeviceName(device) {
+ return device.model ? device.model.split(':')[1] : '未授权设备'
+}
+
+/**
+ * 获取备注名称
+ */
+export function getRemark(deviceId) {
+ const value = window.appStore.get(`device.${replaceIP(deviceId)}.remark`)
+ return value
+}
+
+/**
+ * 获取历史设备列表
+ */
+export function getHistoryDevices() {
+ const devices = window.appStore.get('devices') || []
+ return devices.map(device => ({
+ ...device,
+ status: 'offline',
+ }))
+}
+
+/**
+ * 获取当前连接的设备
+ */
+export async function getCurrentDevices() {
+ const rawDevices = await window.adb.getDevices() || []
+
+ return rawDevices.map(device => ({
+ ...device,
+ id: device.id,
+ status: device.type,
+ name: getDeviceName(device),
+ unauthorized: device.type === 'unauthorized',
+ wifi: isIPWithPort(device.id),
+ remark: getRemark(device.id),
+ }))
+}
+
+/**
+ * 合并历史和当前设备列表
+ */
+export function mergeDevices(historyDevices, currentDevices) {
+ const historyMap = keyBy(historyDevices, 'id')
+ const currentMap = keyBy(currentDevices, 'id')
+
+ return Object.values(defaultsDeep(currentMap, historyMap))
+}
+
+/**
+ * 保存设备信息到存储
+ */
+export function saveDevicesToStore(devices) {
+ const cleanedDevices = devices.map(device =>
+ omit(device, ['status', 'unauthorized']),
+ )
+ window.appStore.set('devices', cleanedDevices)
+}
diff --git a/src/store/device/index.js b/src/store/device/index.js
index b32693f9..36bef4de 100644
--- a/src/store/device/index.js
+++ b/src/store/device/index.js
@@ -1,10 +1,19 @@
import { defineStore } from 'pinia'
import dayjs from 'dayjs'
+
import { capitalize } from 'lodash-es'
-import { isIPWithPort, replaceIP } from '$/utils/index.js'
+
+import { replaceIP } from '$/utils/index.js'
import { name as packageName } from '$root/package.json'
+import {
+ getCurrentDevices,
+ getHistoryDevices,
+ mergeDevices,
+ saveDevicesToStore,
+} from './helpers/index.js'
+
const $appStore = window.appStore
export const useDeviceStore = defineStore({
@@ -36,7 +45,7 @@ export const useDeviceStore = defineStore({
const appName = capitalize(packageName)
- const deviceName = `${data?.$remark || data.$name}${data.$wifi ? '(WIFI)' : ''}`
+ const deviceName = `${data?.remark || data.name}${data.wifi ? '(WIFI)' : ''}`
const currentTime = dayjs().format('YYYYMMDDHHmmss')
@@ -75,23 +84,22 @@ export const useDeviceStore = defineStore({
setList(data) {
this.list = data
},
+ /**
+ * 获取设备列表
+ * @returns {Promise} 合并后的设备列表
+ */
async getList() {
- const res = await window.adb.getDevices()
-
- const data
- = res?.map(item => ({
- ...item,
- id: item.id,
- status: item.type,
- $name: item.model ? item.model.split(':')[1] : '未授权设备',
- $unauthorized: item.type === 'unauthorized',
- $wifi: isIPWithPort(item.id),
- $remark: this.getRemark(item.id),
- })) || []
+ const historyDevices = getHistoryDevices()
- this.list = data
+ const currentDevices = await getCurrentDevices()
+
+ const mergedDevices = mergeDevices(historyDevices, currentDevices)
- return data
+ saveDevicesToStore(mergedDevices)
+
+ this.list = mergedDevices
+
+ return mergedDevices
},
setConfig(value, key = 'device') {
$appStore.set(key, value)
@@ -101,9 +109,5 @@ export const useDeviceStore = defineStore({
$appStore.set(`device.${replaceIP(deviceId)}.remark`, value)
this.init()
},
- getRemark(deviceId) {
- const value = $appStore.get(`device.${replaceIP(deviceId)}.remark`)
- return value
- },
},
})