@@ -41,18 +41,26 @@ local function try_get_profiler_url_chrome(data)
41
41
return data :match (" (ws%:%/%/127%.0%.0%.1%:%d+/.+/ws)$" )
42
42
end
43
43
44
- local function start_browser ()
44
+ function M . start_browser ()
45
45
local auto_open_browser = config .dev_tools .auto_open_browser
46
46
if not auto_open_browser then return end
47
+
47
48
local url = M .get_profiler_url ()
49
+ if not url then return end
50
+
48
51
local open_command = utils .open_command ()
49
52
if not open_command then
50
53
return ui .notify (
51
54
" Sorry your Operating System is not supported, please raise an issue" ,
52
55
ui .ERROR
53
56
)
54
57
end
55
- if url and open_command then vim .fn .jobstart ({ open_command , url }, { detach = true }) end
58
+
59
+ Job :new ({
60
+ command = open_command ,
61
+ args = { url },
62
+ detached = true
63
+ }):start ()
56
64
end
57
65
58
66
function M .handle_log (data )
@@ -84,7 +92,7 @@ function M.register_profiler_url(url)
84
92
end
85
93
86
94
function M .handle_devtools_available ()
87
- start_browser ()
95
+ M . start_browser ()
88
96
ui .notify (" Detected devtools url, execute FlutterCopyProfilerUrl to copy it" )
89
97
end
90
98
@@ -103,16 +111,21 @@ end
103
111
--- @param data string
104
112
--- @param _ Job
105
113
local function handle_start (_ , data , _ )
106
- if # data > 0 then
107
- local json = fn .json_decode (data )
108
- if json and json .params then
109
- devtools_pid = json .params .pid
110
- devtools_url = string.format (" http://%s:%s" , json .params .host , json .params .port )
111
- start_browser ()
112
- local msg = string.format (" Serving DevTools at %s" , devtools_url )
113
- ui .notify (msg , ui .INFO , { timeout = 20000 })
114
- end
115
- end
114
+ if # data <= 0 then return end
115
+
116
+ local json = fn .json_decode (data )
117
+ if not json or not json .params then return end
118
+
119
+ devtools_pid = json .params .pid
120
+ if not json .params .host or not json .params .port then return end
121
+
122
+ devtools_url = string.format (" http://%s:%s" , json .params .host , json .params .port )
123
+ M .start_browser ()
124
+ ui .notify (
125
+ string.format (" Serving DevTools at %s" , devtools_url ),
126
+ ui .INFO ,
127
+ { timeout = 10000 }
128
+ )
116
129
end
117
130
118
131
--- Handler errors whilst opening dev tools
0 commit comments