|
@@ -55,81 +55,43 @@ class DeviceClass {
|
|
|
async handleAdd() {
|
|
async handleAdd() {
|
|
|
|
|
|
|
|
const ip = document.querySelector('.ip-input input').value
|
|
const ip = document.querySelector('.ip-input input').value
|
|
|
- hintView.setContent(ip)
|
|
|
|
|
- hintView.show()
|
|
|
|
|
const result = await window.electronAPI.runNodejsScript('adb-connect', ip, '5555')
|
|
const result = await window.electronAPI.runNodejsScript('adb-connect', ip, '5555')
|
|
|
|
|
|
|
|
if(result.stdout == 'success') {
|
|
if(result.stdout == 'success') {
|
|
|
- const newDevice = await this.addDevice(ip)
|
|
|
|
|
- if (newDevice && this.setDeviceList) {
|
|
|
|
|
- this.setDeviceList(prev => [...prev, newDevice])
|
|
|
|
|
|
|
+ hintView.setContent('设备添加成功')
|
|
|
|
|
+ hintView.show()
|
|
|
|
|
|
|
|
- hintView.setContent('设备添加成功')
|
|
|
|
|
- hintView.show()
|
|
|
|
|
- }
|
|
|
|
|
- return
|
|
|
|
|
|
|
+ await this.addDevice(ip);
|
|
|
|
|
+
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
alertView.show()
|
|
alertView.show()
|
|
|
alertView.setContent('无法检测到连接设备')
|
|
alertView.setContent('无法检测到连接设备')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async addDevice(ip) {
|
|
|
|
|
- const readResult = await window.electronAPI.runNodejsScript('json-parser', 'read', 'device_list.json')
|
|
|
|
|
-
|
|
|
|
|
- let jsonData
|
|
|
|
|
- if (readResult.stdout === '') {
|
|
|
|
|
- await window.electronAPI.runNodejsScript('json-parser', 'create', 'device_list.json', JSON.stringify({devices: []}))
|
|
|
|
|
- jsonData = {devices: []}
|
|
|
|
|
- } else {
|
|
|
|
|
- const parsed = JSON.parse(readResult.stdout)
|
|
|
|
|
- jsonData = parsed.data || {devices: []}
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ async addDevice(ip) {
|
|
|
// 数组中是字符串,直接 push IP 字符串
|
|
// 数组中是字符串,直接 push IP 字符串
|
|
|
- jsonData.devices.push(ip)
|
|
|
|
|
- await window.electronAPI.runNodejsScript('json-parser', 'update', 'device_list.json', JSON.stringify({devices: jsonData.devices}))
|
|
|
|
|
|
|
+ this.deviceArr.push(ip)
|
|
|
|
|
+ await window.electronAPI.runNodejsScript('json-parser', 'update', 'device_list.json', JSON.stringify({devices: this.deviceArr}))
|
|
|
|
|
|
|
|
- // 更新 this.deviceArr
|
|
|
|
|
- this.deviceArr = jsonData.devices
|
|
|
|
|
- this.setDeviceList(jsonData.devices);
|
|
|
|
|
- return ip
|
|
|
|
|
|
|
+ this.setDeviceList(this.deviceArr);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async removeDevice(ip) {
|
|
async removeDevice(ip) {
|
|
|
|
|
|
|
|
comfirmView.show()
|
|
comfirmView.show()
|
|
|
comfirmView.setContent('确定要删除设备吗?')
|
|
comfirmView.setContent('确定要删除设备吗?')
|
|
|
|
|
+
|
|
|
comfirmView.onConfirm = async () => {
|
|
comfirmView.onConfirm = async () => {
|
|
|
comfirmView.hide()
|
|
comfirmView.hide()
|
|
|
-
|
|
|
|
|
- const readResult = await window.electronAPI.runNodejsScript('json-parser', 'read', 'device_list.json')
|
|
|
|
|
-
|
|
|
|
|
- if (readResult.stdout === '') {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const parsed = JSON.parse(readResult.stdout)
|
|
|
|
|
- const jsonData = parsed.data || {devices: []}
|
|
|
|
|
-
|
|
|
|
|
- // 过滤掉要删除的设备(数组中是字符串,直接比较)
|
|
|
|
|
- const filteredDevices = jsonData.devices.filter(deviceIp => deviceIp !== ip)
|
|
|
|
|
|
|
|
|
|
|
|
+ // 从数组中移除指定 IP(deviceIp 是数组中的每个字符串元素)
|
|
|
|
|
+ this.deviceArr = this.deviceArr.filter(deviceIp => deviceIp !== ip)
|
|
|
|
|
+
|
|
|
// 更新 JSON 文件
|
|
// 更新 JSON 文件
|
|
|
- await window.electronAPI.runNodejsScript('json-parser', 'update', 'device_list.json', JSON.stringify({devices: filteredDevices}))
|
|
|
|
|
-
|
|
|
|
|
- // 更新 this.deviceArr
|
|
|
|
|
- this.deviceArr = filteredDevices
|
|
|
|
|
-
|
|
|
|
|
- // 更新 deviceArrRef
|
|
|
|
|
- if (this.deviceArrRef) {
|
|
|
|
|
- this.deviceArrRef.current = filteredDevices
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 更新 React state
|
|
|
|
|
- if (this.setDeviceList) {
|
|
|
|
|
- this.setDeviceList(filteredDevices)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await window.electronAPI.runNodejsScript('json-parser', 'update', 'device_list.json', JSON.stringify({devices: this.deviceArr}))
|
|
|
|
|
+
|
|
|
|
|
+ this.setDeviceList(this.deviceArr)
|
|
|
}
|
|
}
|
|
|
comfirmView.onCancel = () => {
|
|
comfirmView.onCancel = () => {
|
|
|
comfirmView.hide()
|
|
comfirmView.hide()
|