Skip to content

Commit 0906973

Browse files
committed
feat: avd manager wipe data
1 parent 9f2bb6d commit 0906973

File tree

9 files changed

+50
-5
lines changed

9 files changed

+50
-5
lines changed

src/common/langs/en-US.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,7 @@
206206
"avdManager": "AVD Manager",
207207
"sdkVersion": "SDK Version",
208208
"openDir": "Open Directory",
209-
"qrcodePair": "Pair using QR code"
209+
"qrcodePair": "Pair using QR code",
210+
"wipeDate": "Wipe Data",
211+
"wipeDataConfirm": "Are you sure you want to wipe user files from {{name}}?"
210212
}

src/common/langs/zh-CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,7 @@
206206
"avdManager": "AVD 管理器",
207207
"sdkVersion": "SDK 版本",
208208
"openDir": "打开目录",
209-
"qrcodePair": "扫码配对"
209+
"qrcodePair": "扫码配对",
210+
"wipeData": "清除数据",
211+
"wipeDataConfirm": "确定要清除 {{name}} 的数据吗?"
210212
}

src/common/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ export type IpcGetPackageInfos = (
6363
export type IpcGetAvds = (forceRefresh?: boolean) => Promise<IAvd[]>
6464
export type IpcStartAvd = (avdId: string) => Promise<void>
6565
export type IpcStopAvd = IpcStartAvd
66+
export type IpcWipeAvdData = (avdId: string) => Promise<void>

src/main/window/avd.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import memoize from 'licia/memoize'
1919
import isWindows from 'licia/isWindows'
2020
import isMac from 'licia/isMac'
2121
import keys from 'licia/keys'
22+
import sleep from 'licia/sleep'
2223

2324
const store = getAvdStore()
2425
const settingsStore = getSettingsStore()
@@ -165,10 +166,29 @@ const stopAvd: IpcStopAvd = async (avdId) => {
165166
process.kill(avd.pid)
166167
}
167168

169+
const wipeAvdData = async (avdId: string) => {
170+
const avd = avds[avdId]
171+
if (!avd) {
172+
return
173+
}
174+
if (avd.pid) {
175+
await stopAvd(avdId)
176+
await sleep(1000)
177+
}
178+
const removed = [
179+
path.resolve(avd.folder, 'snapshots'),
180+
path.resolve(avd.folder, 'userdata-qemu.img'),
181+
]
182+
for (const item of removed) {
183+
await fs.remove(item)
184+
}
185+
}
186+
168187
const initIpc = once(() => {
169188
reloadAvds()
170189

171190
handleEvent('getAvds', getAvds)
172191
handleEvent('startAvd', startAvd)
173192
handleEvent('stopAvd', stopAvd)
193+
handleEvent('wipeAvdData', wipeAvdData)
174194
})

src/preload/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
IpcSetScreencastAlwaysOnTop,
1212
IpcStartAvd,
1313
IpcStopAvd,
14+
IpcWipeAvdData,
1415
} from '../common/types'
1516
import { ipcRenderer } from 'electron'
1617
import { IpcGetStore, IpcSetStore } from 'share/common/types'
@@ -141,4 +142,5 @@ export default Object.assign(mainObj, {
141142
getAvds: invoke<IpcGetAvds>('getAvds'),
142143
startAvd: invoke<IpcStartAvd>('startAvd'),
143144
stopAvd: invoke<IpcStopAvd>('stopAvd'),
145+
wipeAvdData: invoke<IpcWipeAvdData>('wipeAvdData'),
144146
})

src/renderer/avd/components/Toolbar.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { t } from '../../../common/util'
99
import store from '../store'
1010
import ToolbarIcon from 'share/renderer/components/ToolbarIcon'
1111
import { notify } from 'share/renderer/lib/util'
12+
import Modal from 'luna-modal'
1213

1314
export default observer(function Toolbar() {
1415
let pid = 0
@@ -38,6 +39,19 @@ export default observer(function Toolbar() {
3839
}}
3940
disabled={!store.avd}
4041
/>
42+
<ToolbarIcon
43+
icon="clear"
44+
title={t('wipeData')}
45+
onClick={async () => {
46+
const result = await Modal.confirm(
47+
t('wipeDataConfirm', { name: store.avd!.name })
48+
)
49+
if (result) {
50+
await main.wipeAvdData(store.avd!.id)
51+
}
52+
}}
53+
disabled={!store.avd}
54+
/>
4155
<ToolbarIcon
4256
icon="open-file"
4357
title={t('openDir')}

src/renderer/icon.css

Lines changed: 4 additions & 1 deletion
Large diffs are not rendered by default.

src/renderer/icon.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@
5757
"../share/renderer/icon/text.svg",
5858
"../share/renderer/icon/video-recorder.svg",
5959
"../share/renderer/icon/open-file.svg",
60-
"../share/renderer/icon/qrcode.svg"
60+
"../share/renderer/icon/qrcode.svg",
61+
"../share/renderer/icon/clear.svg"
6162
]

src/share

0 commit comments

Comments
 (0)