()
| 538 | |
| 539 | /// Starts the devtools server and returns the URL of the running app. |
| 540 | private startServer(): Promise<string> { |
| 541 | return new Promise<string>(async (resolve, reject) => { |
| 542 | if (this.service) { |
| 543 | try { |
| 544 | await this.service.dispose(); |
| 545 | this.service = undefined; |
| 546 | this.devtoolsUrl = undefined; |
| 547 | } catch (e) { |
| 548 | this.logger.error(e); |
| 549 | } |
| 550 | } |
| 551 | const service = this.service = new DevToolsService(this.logger, this.context.workspaceContext, this.toolingDaemon, this.dartCapabilities); |
| 552 | this.disposables.push(service); |
| 553 | await service.connect(); |
| 554 | |
| 555 | service.registerForServerStarted((n) => { |
| 556 | // When a new debug session starts, we need to wait for its VM |
| 557 | // Service, then register it with this server. |
| 558 | if (this.debugCommands) { |
| 559 | this.disposables.push(this.debugCommands.onDebugSessionVmServiceAvailable(async (session) => { |
| 560 | if (session.vmServiceUri) { |
| 561 | void service.vmRegister({ uri: session.vmServiceUri }); |
| 562 | // Also reconnect any orphaned DevTools views. |
| 563 | await this.reconnectDisconnectedEmbeddedViews(session as DartDebugSessionInformation & { vmServiceUri: string }); |
| 564 | } |
| 565 | })); |
| 566 | } |
| 567 | |
| 568 | // And send any existing sessions we have. |
| 569 | for (const session of debugSessions) { |
| 570 | if (session.vmServiceUri) |
| 571 | void service.vmRegister({ uri: session.vmServiceUri }); |
| 572 | } |
| 573 | |
| 574 | // Finally, trigger a check of extensions |
| 575 | // For initial testing, extension recommendations are allow-list. This comes from config so it can be overridden |
| 576 | // by the user to allow testing the whole flow before being shipped in the list. |
| 577 | // |
| 578 | // Adding "*" to the list allows all extension identifiers, useful for testing. |
| 579 | setTimeout(async () => { |
| 580 | try { |
| 581 | await this.promptForExtensionRecommendations(); |
| 582 | } catch (e) { |
| 583 | // This can fail if we're restarting/shutting down before it fires. |
| 584 | const message = `Failed to check for extension recommendations: ${e}`; |
| 585 | console.error(message); |
| 586 | this.logger.error(message); |
| 587 | } |
| 588 | }, twentySecondsInMs).unref(); |
| 589 | |
| 590 | portToBind = n.port; |
| 591 | resolve(`http://${n.host}:${n.port}/`); |
| 592 | }); |
| 593 | |
| 594 | service.process?.on("close", async (code) => { |
| 595 | this.devtoolsUrl = undefined; |
| 596 | this.setNotStartedStatusBar(); |
| 597 | if (code && code !== 0 && !this.isShuttingDown) { |
no test coverage detected