Skip to content

Commit

Permalink
fix: 🔧 修复 Linux 及 MacOS 获取默认依赖路径异常的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Oct 20, 2023
1 parent 45af64e commit 87b533f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
12 changes: 10 additions & 2 deletions electron/configs/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { resolve } from 'node:path'
import which from 'which'

import { buildResolve, extraResolve } from '@electron/helpers/index.js'

Expand All @@ -11,7 +12,14 @@ export const icoLogoPath = buildResolve('logo.ico')
export const icnsLogoPath = buildResolve('logo.icns')

export const adbPath
= process.platform === 'win32' ? extraResolve('core/adb.exe') : 'adb'
= process.platform === 'win32'
? extraResolve('core/adb.exe')
: which.sync('adb', { nothrow: true })

export const scrcpyPath
= process.platform === 'win32' ? extraResolve('core/scrcpy.exe') : 'scrcpy'
= process.platform === 'win32'
? extraResolve('core/scrcpy.exe')
: which.sync('scrcpy', { nothrow: true })

// console.log('adbPath', adbPath)
// console.log('scrcpyPath', scrcpyPath)
4 changes: 0 additions & 4 deletions electron/exposes/adbkit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import path from 'node:path'
import fs from 'node:fs'
import dayjs from 'dayjs'
import { Adb } from '@devicefarmer/adbkit'
import _which from 'which'
import appStore from '@electron/helpers/store.js'
import { adbPath } from '@electron/configs/index.js'

Expand Down Expand Up @@ -100,8 +99,6 @@ const install = async (id, path) => client.getDevice(id).install(path)

const version = async () => client.version()

const which = async () => _which('adb')

const watch = async (callback) => {
const tracker = await client.trackDevices()
tracker.on('add', async (ret) => {
Expand Down Expand Up @@ -147,7 +144,6 @@ export default () => {
screencap,
install,
version,
which,
watch,
}
}
4 changes: 0 additions & 4 deletions electron/exposes/scrcpy/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { spawn } from 'node:child_process'
import _which from 'which'
import appStore from '@electron/helpers/store.js'
import { adbPath, scrcpyPath } from '@electron/configs/index.js'

Expand Down Expand Up @@ -48,9 +47,6 @@ const shell = async (command, { stdout, stderr } = {}) => {
})
}

const which = async () => _which('scrcpy')

export default () => ({
shell,
which,
})
13 changes: 6 additions & 7 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ export default {
return false
}
try {
const adbWhichPath = await this.$adb.which()
console.log('adbWhichPath', adbWhichPath)
const scrcpyWhichPath = await this.$scrcpy.which()
console.log('scrcpyWhichPath', scrcpyWhichPath)
const { adbPath, scrcpyPath } = this.$electron?.configs || {}
if (adbPath) {
return false
}
catch (error) {
console.warn(error?.message || error?.cause?.message)
if (scrcpyPath) {
return false
}
this.$alert(
Expand Down

0 comments on commit 87b533f

Please sign in to comment.