mirror of
https://github.com/viarotel-org/escrcpy.git
synced 2024-11-14 10:47:55 +01:00
fix: 🔧 修复 ADB 环境变量配置错误导致无法连接的问题
This commit is contained in:
parent
6dd2db9da9
commit
9ef720383e
@ -8,8 +8,8 @@ import './ipc/index.js'
|
||||
function createWindow() {
|
||||
// Create the browser window.
|
||||
const mainWindow = new BrowserWindow({
|
||||
width: 900,
|
||||
height: 670,
|
||||
minWidth: 900,
|
||||
minHeight: 700,
|
||||
show: false,
|
||||
autoHideMenuBar: true,
|
||||
...(process.platform === 'linux' ? { icon } : {}),
|
||||
|
@ -2,6 +2,7 @@ import { electronAPI } from '@electron-toolkit/preload'
|
||||
import { Adb } from '@devicefarmer/adbkit'
|
||||
|
||||
import scrcpyPath from '../../resources/core/scrcpy.exe?asset&asarUnpack'
|
||||
import adbPath from '../../resources/core/adb.exe?asset&asarUnpack'
|
||||
import { addContext } from './helpers/index.js'
|
||||
|
||||
const util = require('node:util')
|
||||
@ -17,7 +18,7 @@ addContext('electron', electronAPI)
|
||||
addContext('api', api)
|
||||
|
||||
addContext('adbkit', () => {
|
||||
const client = Adb.createClient()
|
||||
const client = Adb.createClient({ bin: adbPath })
|
||||
console.log('client', client)
|
||||
|
||||
const getDevices = async () => await client.listDevicesWithPaths()
|
||||
@ -49,9 +50,9 @@ addContext('adbkit', () => {
|
||||
return close
|
||||
}
|
||||
|
||||
// window.addEventListener('beforeunload', () => {
|
||||
// kill()
|
||||
// })
|
||||
window.addEventListener('beforeunload', () => {
|
||||
kill()
|
||||
})
|
||||
|
||||
return {
|
||||
getDevices,
|
||||
@ -64,7 +65,8 @@ addContext('adbkit', () => {
|
||||
})
|
||||
|
||||
addContext('scrcpy', () => {
|
||||
const shell = command => exec(`${scrcpyPath} ${command}`)
|
||||
const shell = command =>
|
||||
exec(`${scrcpyPath} ${command}`, { env: { ...process.env, ADB: adbPath } })
|
||||
|
||||
return {
|
||||
shell,
|
||||
|
@ -1,5 +1,7 @@
|
||||
<template>
|
||||
<div class=""></div>
|
||||
<div class="">
|
||||
[WIP]
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
@ -9,7 +9,14 @@
|
||||
</el-button>
|
||||
</div>
|
||||
<div class="pt-4 flex-1 h-0 overflow-hidden">
|
||||
<el-table v-loading="loading" :data="deviceList" style="width: 100%" border height="100%">
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:element-loading-text="loadingText"
|
||||
:data="deviceList"
|
||||
style="width: 100%"
|
||||
border
|
||||
height="100%"
|
||||
>
|
||||
<template #empty>
|
||||
<el-empty description="设备列表为空" />
|
||||
</template>
|
||||
@ -30,7 +37,14 @@
|
||||
<el-table-column label="操作" width="300" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" :loading="row.$loading" @click="handleStart(row)">
|
||||
{{ row.$loading ? '运行中' : '连接设备' }}
|
||||
{{ row.$loading ? '镜像中' : '开始镜像' }}
|
||||
</el-button>
|
||||
<el-button
|
||||
:disabled="!row.$loading"
|
||||
type="default"
|
||||
@click="handleScreenUp(row)"
|
||||
>
|
||||
点亮屏幕
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@ -46,6 +60,7 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
loadingText: '初始化中...',
|
||||
deviceList: [],
|
||||
}
|
||||
},
|
||||
@ -57,6 +72,9 @@ export default {
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
handleScreenUp(row) {
|
||||
this.$adb.shell(row.id, 'input keyevent KEYCODE_POWER')
|
||||
},
|
||||
handleReset() {
|
||||
this.$electron.ipcRenderer.send('restart-app')
|
||||
},
|
||||
@ -92,6 +110,7 @@ export default {
|
||||
this.deviceList = []
|
||||
}
|
||||
this.loading = false
|
||||
this.loadingText = '正在获取设备列表...'
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -23,7 +23,14 @@
|
||||
</el-button>
|
||||
</div>
|
||||
<div class="pt-4 flex-1 h-0 overflow-hidden">
|
||||
<el-table v-loading="loading" :data="deviceList" style="width: 100%" border height="100%">
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:element-loading-text="loadingText"
|
||||
:data="deviceList"
|
||||
style="width: 100%"
|
||||
border
|
||||
height="100%"
|
||||
>
|
||||
<template #empty>
|
||||
<el-empty description="设备列表为空" />
|
||||
</template>
|
||||
@ -44,9 +51,17 @@
|
||||
<el-table-column label="操作" width="300" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" :loading="row.$loading" @click="handleStart(row)">
|
||||
{{ row.$loading ? '运行中' : '连接设备' }}
|
||||
{{ row.$loading ? '镜像中' : '开始镜像' }}
|
||||
</el-button>
|
||||
<el-button type="danger" :loading="row.$stopLoading" @click="handleStop(row)">
|
||||
<el-button :disabled="!row.$loading" type="default" @click="handleScreenUp(row)">
|
||||
点亮屏幕
|
||||
</el-button>
|
||||
<el-button
|
||||
:disabled="!row.$loading"
|
||||
type="danger"
|
||||
:loading="row.$stopLoading"
|
||||
@click="handleStop(row)"
|
||||
>
|
||||
{{ row.$stopLoading ? '断开中' : '断开连接' }}
|
||||
</el-button>
|
||||
</template>
|
||||
@ -58,16 +73,19 @@
|
||||
|
||||
<script>
|
||||
import { isIPWithPort, sleep } from '@renderer/utils/index.js'
|
||||
import storage from '@renderer/utils/storages'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
const adbCache = storage.get('adbCache') || {}
|
||||
return {
|
||||
loading: false,
|
||||
loadingText: '初始化中...',
|
||||
connectLoading: false,
|
||||
deviceList: [],
|
||||
formData: {
|
||||
host: '',
|
||||
port: null,
|
||||
host: adbCache.host,
|
||||
port: adbCache.port,
|
||||
},
|
||||
}
|
||||
},
|
||||
@ -79,6 +97,9 @@ export default {
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
handleScreenUp(row) {
|
||||
this.$adb.shell(row.id, 'input keyevent KEYCODE_POWER')
|
||||
},
|
||||
handleReset() {
|
||||
this.$electron.ipcRenderer.send('restart-app')
|
||||
},
|
||||
@ -91,6 +112,7 @@ export default {
|
||||
try {
|
||||
await this.$adb.connect(this.formData.host, this.formData.port || 5555)
|
||||
this.$message.success('连接设备成功')
|
||||
storage.set('adbCache', this.formData)
|
||||
}
|
||||
catch (error) {
|
||||
if (error.message)
|
||||
@ -144,6 +166,7 @@ export default {
|
||||
this.deviceList = []
|
||||
}
|
||||
this.loading = false
|
||||
this.loadingText = '正在获取设备列表...'
|
||||
},
|
||||
},
|
||||
}
|
||||
|
29
src/renderer/src/utils/storages/cookieStorage.js
Normal file
29
src/renderer/src/utils/storages/cookieStorage.js
Normal file
@ -0,0 +1,29 @@
|
||||
import jsCookie from 'js-cookie'
|
||||
|
||||
/**
|
||||
* 操作 Cookie
|
||||
* @method set 设置
|
||||
* @method get 获取
|
||||
* @method remove 移除
|
||||
* @method clear 移除全部
|
||||
*/
|
||||
export default {
|
||||
// 设置
|
||||
set(key, val) {
|
||||
jsCookie.set(key, JSON.stringify(val))
|
||||
},
|
||||
// 获取
|
||||
get(key) {
|
||||
const json = jsCookie.get(key)
|
||||
try {
|
||||
return JSON.parse(json)
|
||||
}
|
||||
catch (error) {
|
||||
return json
|
||||
}
|
||||
},
|
||||
// 移除
|
||||
remove(key) {
|
||||
jsCookie.remove(key)
|
||||
},
|
||||
}
|
7
src/renderer/src/utils/storages/index.js
Normal file
7
src/renderer/src/utils/storages/index.js
Normal file
@ -0,0 +1,7 @@
|
||||
import defaultStorage from './localStorage'
|
||||
|
||||
// export { default as localStorage } from './localStorage'
|
||||
// export { default as sessionStorage } from './sessionStorage'
|
||||
// export { default as cookieStorage } from './cookieStorage'
|
||||
|
||||
export default defaultStorage
|
31
src/renderer/src/utils/storages/localStorage.js
Normal file
31
src/renderer/src/utils/storages/localStorage.js
Normal file
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* window.localStorage
|
||||
* @method set 设置
|
||||
* @method get 获取
|
||||
* @method remove 移除
|
||||
* @method clear 移除全部
|
||||
*/
|
||||
export default {
|
||||
// 设置
|
||||
set(key, val) {
|
||||
window.localStorage.setItem(key, JSON.stringify(val))
|
||||
},
|
||||
// 获取
|
||||
get(key) {
|
||||
const json = window.localStorage.getItem(key)
|
||||
try {
|
||||
return JSON.parse(json)
|
||||
}
|
||||
catch (error) {
|
||||
return json
|
||||
}
|
||||
},
|
||||
// 移除
|
||||
remove(key) {
|
||||
window.localStorage.removeItem(key)
|
||||
},
|
||||
// 移除全部
|
||||
clear() {
|
||||
window.localStorage.clear()
|
||||
},
|
||||
}
|
31
src/renderer/src/utils/storages/sessionStorage.js
Normal file
31
src/renderer/src/utils/storages/sessionStorage.js
Normal file
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* window.sessionStorage
|
||||
* @method set 设置
|
||||
* @method get 获取
|
||||
* @method remove 移除
|
||||
* @method clear 移除全部
|
||||
*/
|
||||
export default {
|
||||
// 设置
|
||||
set(key, val) {
|
||||
window.sessionStorage.setItem(key, JSON.stringify(val))
|
||||
},
|
||||
// 获取
|
||||
get(key) {
|
||||
const json = window.sessionStorage.getItem(key)
|
||||
try {
|
||||
return JSON.parse(json)
|
||||
}
|
||||
catch (error) {
|
||||
return json
|
||||
}
|
||||
},
|
||||
// 移除
|
||||
remove(key) {
|
||||
window.sessionStorage.removeItem(key)
|
||||
},
|
||||
// 移除全部
|
||||
clear() {
|
||||
window.sessionStorage.clear()
|
||||
},
|
||||
}
|
Loading…
Reference in New Issue
Block a user