You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide a command to get the ID of the selected device for use in tasks #4677
I'm trying to pass the mobile deviceId to a flutter preLaunchTask. Minimal sample below, but ultimately it's a simctl script that uses booted as the device id. However, this breaks down when I have multiple simulator devices booted, so I'm trying to explicitly run the preLaunch script with the target device.
Does someone know how to do this? I've tried almost everything I could think of with variable substitution and environment variables (printenv shows nothing useful), but I can't find any hook into deviceId. It should be the same parameter passed to the -d argument. Caveat: I can't use an explicit deviceId in the launch config because the config is checked in and shared with others, and we all use various versions of devices and Xcode.
There's the possibility this command would return null if there's no selected device though (such as during startup before they have been discovered).
We could also set an environment variable (DART_CODE_DEVICE_ID) for debugger launches, but I don't think we can do it for shell command tasks, because the Dart extension is not involved at all in launching those.
Something that I think could be fairly easily supported though is a command that returns you the select devices ID, so you could do something like:
I love it. null is perfectly usable for my use case as well (I can fall back to booted). Can I do any heavy lifting or is this a officially a feature request? I'd love to help push this along or meet in the middle, but don't want to burden others with a contribution learning curve either.
changed the title [-]Dynamic deviceId available in preLaunchTask?[/-][+]Provide a command to get the ID of the selected device for use in tasks[/+]on Aug 7, 2023
You'd also need to add the command to package.json (it'd need to go into contributes/commands and also in contributes/menus/commandPalette with "when": false to prevent it showing up in the command palette).
To make the change and test it:
fork and clone this repo
run npm install
open the folder in VS Code
make a changes similar to the suggestion above
press F5 to build the extension and launch the Extension Development Host (another instance of VS Code running the extension from source)
open your project and test with something like "command": "echo ${command:flutter.getSelectedDeviceId}",
I don't have a good way to write an automated test for this right now (because the mock device manager isn't available in that code), but I think the code is simple enough to merge without. We should include a comment that the command may be used by users tasks and that it should not be removed even if it appears unused.
This was included in the pre-release version pushed just now if you want to try it out ahead of the release (it's v3.71.20230829 which might take 20 min or so to show up):
Activity
DanTup commentedon Aug 7, 2023
I can't think of a way to do this currently.
Something that I think could be fairly easily supported though is a command that returns you the select devices ID, so you could do something like:
There's the possibility this command would return
nullif there's no selected device though (such as during startup before they have been discovered).We could also set an environment variable (
DART_CODE_DEVICE_ID) for debugger launches, but I don't think we can do it for shell command tasks, because the Dart extension is not involved at all in launching those.ajamespro commentedon Aug 7, 2023
I love it.
nullis perfectly usable for my use case as well (I can fall back tobooted). Can I do any heavy lifting or is this a officially a feature request? I'd love to help push this along or meet in the middle, but don't want to burden others with a contribution learning curve either.[-]Dynamic deviceId available in preLaunchTask?[/-][+]Provide a command to get the ID of the selected device for use in tasks[/+]DanTup commentedon Aug 7, 2023
Contributions are always welcome!
I think you could probably do this with a new line below here:
Dart-Code/src/extension/extension.ts
Lines 322 to 323 in 8582fdc
With something like:
You'd also need to add the command to
package.json(it'd need to go intocontributes/commandsand also incontributes/menus/commandPalettewith"when": falseto prevent it showing up in the command palette).To make the change and test it:
npm installF5to build the extension and launch the Extension Development Host (another instance of VS Code running the extension from source)"command": "echo ${command:flutter.getSelectedDeviceId}",I don't have a good way to write an automated test for this right now (because the mock device manager isn't available in that code), but I think the code is simple enough to merge without. We should include a comment that the command may be used by users tasks and that it should not be removed even if it appears unused.
ajamespro commentedon Aug 7, 2023
Ok, I'll give it shot. And thanks for the spoon feeding. This makes it a lot easier and seems doable.
DanTup commentedon Aug 29, 2023
I'm just working through some smaller fixes for the upcoming release so I made this change.
DanTup commentedon Aug 29, 2023
This was included in the pre-release version pushed just now if you want to try it out ahead of the release (it's v3.71.20230829 which might take 20 min or so to show up):
Add a command to get the ID of the selected device