@@ -3,20 +3,21 @@ import * as os from "os";
33import * as path from "path" ;
44import * as vs from "vscode" ;
55import { window , workspace } from "vscode" ;
6- import { CHROME_OS_DEVTOOLS_PORT , isChromeOS , pleaseReportBug , pubPath } from "../../shared/constants" ;
6+ import { CHROME_OS_DEVTOOLS_PORT , isChromeOS , pubPath } from "../../shared/constants" ;
77import { FlutterService , LogCategory } from "../../shared/enums" ;
88import { Logger , Sdks } from "../../shared/interfaces" ;
99import { CategoryLogger } from "../../shared/logging" ;
1010import { UnknownNotification } from "../../shared/services/interfaces" ;
1111import { getRandomInt } from "../../shared/utils/fs" ;
1212import { waitFor } from "../../shared/utils/promises" ;
13- import { envUtils , isRunningLocally } from "../../shared/vscode/utils" ;
13+ import { isRunningLocally } from "../../shared/vscode/utils" ;
1414import { Analytics } from "../analytics" ;
1515import { DebugCommands , debugSessions } from "../commands/debug" ;
1616import { config } from "../config" ;
1717import { PubGlobal } from "../pub/global" ;
1818import { StdIOService } from "../services/stdio_service" ;
1919import { DartDebugSessionInformation } from "../utils/vscode/debug" ;
20+ import { envUtils } from "../utils/vscode/editor" ;
2021
2122const devtools = "devtools" ;
2223const devtoolsPackageName = "Dart DevTools" ;
@@ -58,7 +59,7 @@ export class DevToolsManager implements vs.Disposable {
5859 }
5960 try {
6061 const url = await this . devtoolsUrl ;
61- const didLaunch = await vs . window . withProgress ( {
62+ await vs . window . withProgress ( {
6263 location : vs . ProgressLocation . Notification ,
6364 title : "Opening Dart DevTools..." ,
6465 } , async ( _ ) => {
@@ -67,48 +68,42 @@ export class DevToolsManager implements vs.Disposable {
6768 ide : "VSCode" ,
6869 theme : config . useDevToolsDarkTheme ? "dark" : null ,
6970 } ;
70- if ( ! isRunningLocally ) {
71- const paramsString = Object . keys ( queryParams )
72- . map ( ( key ) => `${ encodeURIComponent ( key ) } =${ encodeURIComponent ( queryParams [ key ] ) } ` )
73- . join ( "&" ) ;
74- const fullUrl = `${ url } ?${ paramsString } &uri=${ encodeURIComponent ( session . vmServiceUri ) } ` ;
75- await envUtils . openInBrowser ( fullUrl ) ;
76- } else {
77- const canLaunchDevToolsThroughService = await waitFor ( ( ) => this . debugCommands . flutterExtensions . serviceIsRegistered ( FlutterService . LaunchDevTools ) , 500 ) ;
78- if ( canLaunchDevToolsThroughService ) {
79- try {
80- await session . session . customRequest (
81- "service" ,
82- {
83- params : { queryParams } ,
84- type : this . debugCommands . flutterExtensions . getServiceMethodName ( FlutterService . LaunchDevTools ) ,
85- } ,
86- ) ;
87-
88- return true ;
89- } catch ( e ) {
90- this . logger . error ( `DevTools failed to launch browser ${ e . message } ` ) ;
91- vs . window . showErrorMessage ( `Dart DevTools was unable to launch Chrome.` , "Show Full Error" ) . then ( ( res ) => {
92- if ( res ) {
93- const fileName = `bug-${ getRandomInt ( 0x1000 , 0x10000 ) . toString ( 16 ) } .txt` ;
94- const tempPath = path . join ( os . tmpdir ( ) , fileName ) ;
95- fs . writeFileSync ( tempPath , e . message ) ;
96- workspace . openTextDocument ( tempPath ) . then ( ( document ) => {
97- window . showTextDocument ( document ) ;
98- } ) ;
99- }
100- } ) ;
101- return false ;
102- }
103- } else {
104- this . logger . error ( `DevTools failed to register launchDevTools service` ) ;
105- vs . window . showErrorMessage ( `The DevTools service failed to register. ${ pleaseReportBug } ` ) ;
106- return false ;
71+ const canLaunchDevToolsThroughService = isRunningLocally
72+ && ! process . env . DART_CODE_IS_TEST_RUN
73+ && await waitFor ( ( ) => this . debugCommands . flutterExtensions . serviceIsRegistered ( FlutterService . LaunchDevTools ) , 500 ) ;
74+ if ( canLaunchDevToolsThroughService ) {
75+ try {
76+ await session . session . customRequest (
77+ "service" ,
78+ {
79+ params : { queryParams } ,
80+ type : this . debugCommands . flutterExtensions . getServiceMethodName ( FlutterService . LaunchDevTools ) ,
81+ } ,
82+ ) ;
83+
84+ return true ;
85+ } catch ( e ) {
86+ this . logger . error ( `DevTools failed to launch Chrome, will launch default browser locally instead: ${ e . message } ` ) ;
87+ vs . window . showWarningMessage ( `Dart DevTools was unable to launch Chrome so your default browser was launched instead.` , "Show Full Error" ) . then ( ( res ) => {
88+ if ( res ) {
89+ const fileName = `bug-${ getRandomInt ( 0x1000 , 0x10000 ) . toString ( 16 ) } .txt` ;
90+ const tempPath = path . join ( os . tmpdir ( ) , fileName ) ;
91+ fs . writeFileSync ( tempPath , e . message || e ) ;
92+ workspace . openTextDocument ( tempPath ) . then ( ( document ) => {
93+ window . showTextDocument ( document ) ;
94+ } ) ;
95+ }
96+ } ) ;
10797 }
10898 }
99+
100+ const paramsString = Object . keys ( queryParams )
101+ . map ( ( key ) => `${ encodeURIComponent ( key ) } =${ encodeURIComponent ( queryParams [ key ] ) } ` )
102+ . join ( "&" ) ;
103+ const fullUrl = `${ url } ?${ paramsString } &uri=${ encodeURIComponent ( session . vmServiceUri ) } ` ;
104+ await envUtils . openInBrowser ( fullUrl ) ;
109105 } ) ;
110- if ( ! didLaunch )
111- return ;
106+
112107 this . devToolsStatusBarItem . text = "Dart DevTools" ;
113108 this . devToolsStatusBarItem . tooltip = `Dart DevTools is running at ${ url } ` ;
114109 this . devToolsStatusBarItem . command = "dart.openDevTools" ;
0 commit comments