()
| 90 | } |
| 91 | |
| 92 | private async flutterScreenshot() { |
| 93 | let shouldNotify = false; |
| 94 | |
| 95 | // If there is no path for this session, or it differs from config, use the one from config. |
| 96 | if (!this.flutterScreenshotPath || |
| 97 | (config.flutterScreenshotPath && this.flutterScreenshotPath !== config.flutterScreenshotPath)) { |
| 98 | this.flutterScreenshotPath = config.flutterScreenshotPath; |
| 99 | shouldNotify = true; |
| 100 | } |
| 101 | |
| 102 | // If path is still empty, bring up the folder selector. |
| 103 | if (!this.flutterScreenshotPath) { |
| 104 | const selectedFolder = |
| 105 | await vs.window.showOpenDialog({ canSelectFolders: true, openLabel: "Set screenshots folder" }); |
| 106 | if (selectedFolder && selectedFolder.length > 0) { |
| 107 | // Set variable to selected path. This allows prompting the user only once. |
| 108 | this.flutterScreenshotPath = selectedFolder[0].path; |
| 109 | shouldNotify = true; |
| 110 | } else { |
| 111 | // Do nothing if the user cancelled the folder selection. |
| 112 | return; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // Ensure folder exists. |
| 117 | mkDirRecursive(this.flutterScreenshotPath); |
| 118 | |
| 119 | const debugSession = vs.debug.activeDebugSession; |
| 120 | if (!debugSession) { |
| 121 | void vs.window.showErrorMessage("You must have an active Flutter debug session to take screenshots"); |
| 122 | return; |
| 123 | } |
| 124 | if (debugSession.type !== "dart") { |
| 125 | void vs.window.showErrorMessage("The active debug session is not a Flutter app"); |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | const projectFolder = debugSession.configuration.cwd as string; |
| 130 | const deviceId = (debugSession.configuration.deviceId ?? this.deviceManager?.currentDevice?.id) as string | undefined; |
| 131 | const outputFilename = nextAvailableFilename(this.flutterScreenshotPath, "flutter_", ".png"); |
| 132 | const args = ["screenshot"]; |
| 133 | if (deviceId) { |
| 134 | args.push("-d"); |
| 135 | args.push(deviceId); |
| 136 | } |
| 137 | args.push("-o"); |
| 138 | args.push(path.join(this.flutterScreenshotPath, outputFilename)); |
| 139 | await this.runFlutterInFolder(projectFolder, args, "screenshot"); |
| 140 | |
| 141 | if (shouldNotify) { |
| 142 | const res = await vs.window.showInformationMessage(`Screenshots will be saved to ${this.flutterScreenshotPath}`, "Show Folder"); |
| 143 | if (res) |
| 144 | await vs.commands.executeCommand("revealFileInOS", vs.Uri.file(this.flutterScreenshotPath)); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | public flutterDoctor(options?: { commandSource?: string }) { |
| 149 | if (!this.workspace.sdks.flutter) { |
nothing calls this directly
no test coverage detected