@@ -41,13 +41,8 @@ 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
- function M .start_browser ()
45
- local auto_open_browser = config .dev_tools .auto_open_browser
46
- if not auto_open_browser then return end
47
-
48
- local url = M .get_profiler_url ()
49
- if not url then return end
50
-
44
+ --- @param url string
45
+ local function open_dev_tools (url )
51
46
local open_command = utils .open_command ()
52
47
if not open_command then
53
48
return ui .notify (
@@ -59,10 +54,27 @@ function M.start_browser()
59
54
Job :new ({
60
55
command = open_command ,
61
56
args = { url },
62
- detached = true
57
+ detached = true ,
63
58
}):start ()
64
59
end
65
60
61
+ local function start_browser ()
62
+ local auto_open_browser = config .dev_tools .auto_open_browser
63
+ if not auto_open_browser then return end
64
+ local url = M .get_profiler_url ()
65
+ if not url then return end
66
+ open_dev_tools (url )
67
+ end
68
+
69
+ function M .open_dev_tools ()
70
+ local url = M .get_profiler_url ()
71
+ if url then
72
+ open_dev_tools (url )
73
+ else
74
+ ui .notify (" No active devtools server found" )
75
+ end
76
+ end
77
+
66
78
function M .handle_log (data )
67
79
if devtools_profiler_url or (profiler_url and devtools_url ) then return end
68
80
@@ -92,7 +104,7 @@ function M.register_profiler_url(url)
92
104
end
93
105
94
106
function M .handle_devtools_available ()
95
- M . start_browser ()
107
+ start_browser ()
96
108
ui .notify (" Detected devtools url, execute FlutterCopyProfilerUrl to copy it" )
97
109
end
98
110
@@ -120,12 +132,8 @@ local function handle_start(_, data, _)
120
132
if not json .params .host or not json .params .port then return end
121
133
122
134
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
- )
135
+ start_browser ()
136
+ ui .notify (string.format (" Serving DevTools at %s" , devtools_url ), ui .INFO , { timeout = 10000 })
129
137
end
130
138
131
139
--- Handler errors whilst opening dev tools
@@ -224,4 +232,7 @@ function M.on_flutter_shutdown()
224
232
devtools_profiler_url = nil
225
233
end
226
234
235
+ function M .set_devtools_url (url ) devtools_url = url end
236
+ function M .set_profiler_url (url ) profiler_url = url end
237
+
227
238
return M
0 commit comments