Skip to content

Commit 40f974b

Browse files
authored
feat(devices): add cold boot option for android emulators (#412)
1 parent 1787090 commit 40f974b

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

lua/flutter-tools/devices.lua

+12-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local commands = lazy.require("flutter-tools.commands") ---@module "flutter-tool
66
local executable = lazy.require("flutter-tools.executable") ---@module "flutter-tools.executable"
77
local fmt = string.format
88

9-
---@alias Device {name: string, id: string, platform: string, system: string, type: integer}
9+
---@alias Device {name: string, id: string, platform: string, system: string, type: integer, cold_boot: boolean}
1010

1111
local M = {
1212
---@type Job
@@ -22,7 +22,14 @@ local function get_devices(result, type)
2222
local devices = {}
2323
for _, line in pairs(result) do
2424
local device = M.parse(line, type)
25-
if device then table.insert(devices, device) end
25+
if device then
26+
table.insert(devices, device)
27+
if type == EMULATOR and device.system and device.system == "android" then
28+
local cold_boot_device = vim.tbl_extend("force", {}, device, { cold_boot = true })
29+
cold_boot_device.name = fmt("%s (cold boot)", device.name)
30+
table.insert(devices, cold_boot_device)
31+
end
32+
end
2633
end
2734
return devices
2835
end
@@ -97,7 +104,9 @@ end
97104
function M.launch_emulator(emulator)
98105
if not emulator then return end
99106
executable.flutter(function(cmd)
100-
M.emulator_job = Job:new({ command = cmd, args = { "emulators", "--launch", emulator.id } })
107+
args = { "emulator", "--launch", emulator.id }
108+
if emulator.cold_boot then table.insert(args, "--cold") end
109+
M.emulator_job = Job:new({ command = cmd, args = args })
101110
M.emulator_job:after_success(vim.schedule_wrap(handle_launch))
102111
M.emulator_job:start()
103112
end)

tests/devices_spec.lua

+10
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,15 @@ describe("Devices - ", function()
1717
assert.equal(output.platform, "")
1818
assert.equal(output.system, "android")
1919
end)
20+
21+
it("should skip `crashdata` lines", function()
22+
local output = parse(
23+
[[INFO | Storing crashdata in: /tmp/android-ts/emu-crash-34.2.14.db, detection is enabled for process: 46675 •
24+
INFO | Storing crashdata in: /tmp/android-ts/emu-crash-34.2.14.db, detection is enabled for process: 46675 •
25+
• android]],
26+
1
27+
)
28+
assert.is_nil(output)
29+
end)
2030
end)
2131
end)

0 commit comments

Comments
 (0)