Skip to content

Commit 1abe15a

Browse files
committed
feat: support ANDROID_AVD_HOME env variable
1 parent 20b3cb2 commit 1abe15a

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/main/window/avd.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import isWindows from 'licia/isWindows'
2020
import isMac from 'licia/isMac'
2121
import keys from 'licia/keys'
2222
import sleep from 'licia/sleep'
23+
import log from 'share/common/log'
24+
25+
const logger = log('avd')
2326

2427
const store = getAvdStore()
2528
const settingsStore = getSettingsStore()
@@ -53,7 +56,7 @@ export function showWin() {
5356
}
5457

5558
let avds: types.PlainObj<IAvd> = {}
56-
const avdFolder = path.resolve(os.homedir(), '.android', 'avd')
59+
let avdFolder = process.env.ANDROID_AVD_HOME || ''
5760

5861
async function reloadAvds() {
5962
avds = {}
@@ -68,8 +71,8 @@ async function reloadAvds() {
6871
try {
6972
const avdInfo = await parseAvdInfo(iniFiles[i])
7073
avds[avdInfo.id] = avdInfo
71-
} catch {
72-
// ignore
74+
} catch (e) {
75+
logger.error(e)
7376
}
7477
}
7578
}
@@ -100,11 +103,15 @@ async function parseAvdInfo(file: string): Promise<IAvd> {
100103
}
101104

102105
async function getAvdPid(folder: string) {
103-
const file = path.resolve(folder, 'hardware-qemu.ini.lock')
106+
let file = path.resolve(folder, 'hardware-qemu.ini.lock')
104107
if (!(await fs.pathExists(file))) {
105108
return 0
106109
}
107110

111+
const stat = await fs.stat(file)
112+
if (!stat.isFile()) {
113+
file = path.resolve(file, 'pid')
114+
}
108115
const content = await fs.readFile(file, 'utf-8')
109116
return parseInt(content, 10)
110117
}
@@ -164,6 +171,12 @@ const stopAvd: IpcStopAvd = async (avdId) => {
164171
return
165172
}
166173
process.kill(avd.pid)
174+
setTimeout(async () => {
175+
const pidPath = path.resolve(avd.folder, 'hardware-qemu.ini.lock')
176+
if (await fs.pathExists(pidPath)) {
177+
await fs.remove(pidPath)
178+
}
179+
}, 500)
167180
}
168181

169182
const wipeAvdData = async (avdId: string) => {
@@ -185,6 +198,12 @@ const wipeAvdData = async (avdId: string) => {
185198
}
186199

187200
const initIpc = once(() => {
201+
if (!fs.existsSync(avdFolder)) {
202+
avdFolder = path.resolve(os.homedir(), '.android', 'avd')
203+
}
204+
205+
logger.info('AVD folder', avdFolder)
206+
188207
reloadAvds()
189208

190209
handleEvent('getAvds', getAvds)

0 commit comments

Comments
 (0)