refactoring
This commit is contained in:
parent
01622c75b8
commit
4c71b931be
@ -180,6 +180,22 @@ local stop_spinner = function(set_inactive)
|
|||||||
vim.notify.dismiss()
|
vim.notify.dismiss()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.flutter_clear(is_emulator)
|
||||||
|
local config_path = get_config_path()
|
||||||
|
local config_data = load_table(config_path)
|
||||||
|
if is_emulator then
|
||||||
|
if config_data.emulator ~= nil then
|
||||||
|
config_data.emulator = nil
|
||||||
|
save_table(config_data, config_path)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if config_data.device ~= nil then
|
||||||
|
config_data.device = nil
|
||||||
|
save_table(config_data, config_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function M.flutter_list(is_emulators)
|
function M.flutter_list(is_emulators)
|
||||||
if flutter_busy == true then
|
if flutter_busy == true then
|
||||||
return
|
return
|
||||||
@ -264,31 +280,49 @@ function M.flutter_list(is_emulators)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
M.flutter_run = function(is_emulator)
|
||||||
|
local config_path = get_config_path()
|
||||||
|
local config_data = load_table(config_path)
|
||||||
|
if is_emulator then
|
||||||
|
if config_data.emulator == nil then
|
||||||
|
if callbacks[2] == nil then
|
||||||
|
callbacks[2] = function()
|
||||||
|
M.flutter_run(is_emulator)
|
||||||
|
end
|
||||||
|
M.flutter_list(true)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local job =
|
||||||
|
Job:new(
|
||||||
|
{command = get_flutter_command(), args = {"emulators", "--launch", config_data.emulator.id}}
|
||||||
|
)
|
||||||
|
job:start()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if config_data.device == nil then
|
||||||
|
if callbacks[1] == nil then
|
||||||
|
callbacks[1] = function()
|
||||||
|
M.flutter_run(is_emulator)
|
||||||
|
end
|
||||||
|
M.flutter_list(false)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
flutter_run_device(config_data.device.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
M.setup = function(opts)
|
M.setup = function(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
config.use_coc = vim.F.if_nil(opts.use_coc, config.use_coc)
|
config.use_coc = vim.F.if_nil(opts.use_coc, config.use_coc)
|
||||||
end
|
end
|
||||||
|
|
||||||
_G.Flutter_Companion_Clear_Selected_Device = function()
|
_G.Flutter_Companion_Clear_Selected_Device = function()
|
||||||
local config_path = get_config_path()
|
M.flutter_clear(false)
|
||||||
local config_data = load_table(config_path)
|
|
||||||
if config_data.device ~= nil then
|
|
||||||
config_data.device = nil
|
|
||||||
save_table(config_data, config_path)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
_G.Flutter_Companion_Run_Selected_Device = function()
|
_G.Flutter_Companion_Run_Selected_Device = function()
|
||||||
local config_path = get_config_path()
|
M.flutter_run(false)
|
||||||
local config_data = load_table(config_path)
|
|
||||||
if config_data.device == nil then
|
|
||||||
if callbacks[1] == nil then
|
|
||||||
callbacks[1] = _G.Flutter_Companion_Run_Selected_Device
|
|
||||||
M.flutter_list(false)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
flutter_run_device(config_data.device.id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
_G.Flutter_Companion_Select_Device = function()
|
_G.Flutter_Companion_Select_Device = function()
|
||||||
@ -296,29 +330,11 @@ _G.Flutter_Companion_Select_Device = function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
_G.Flutter_Companion_Clear_Selected_Emulator = function()
|
_G.Flutter_Companion_Clear_Selected_Emulator = function()
|
||||||
local config_path = get_config_path()
|
M.flutter_clear(true)
|
||||||
local config_data = load_table(config_path)
|
|
||||||
if config_data.emulator ~= nil then
|
|
||||||
config_data.emulator = nil
|
|
||||||
save_table(config_data, config_path)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
_G.Flutter_Companion_Run_Selected_Emulator = function()
|
_G.Flutter_Companion_Run_Selected_Emulator = function()
|
||||||
local config_path = get_config_path()
|
M.flutter_run(true)
|
||||||
local config_data = load_table(config_path)
|
|
||||||
if config_data.emulator == nil then
|
|
||||||
if callbacks[2] == nil then
|
|
||||||
callbacks[2] = _G.Flutter_Companion_Run_Selected_Emulator
|
|
||||||
M.flutter_list(true)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
local job =
|
|
||||||
Job:new(
|
|
||||||
{command = get_flutter_command(), args = {"emulators", "--launch", config_data.emulator.id}}
|
|
||||||
)
|
|
||||||
job:start()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
_G.Flutter_Companion_Select_Emulator = function()
|
_G.Flutter_Companion_Select_Emulator = function()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user