MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / deviceAdded

Method deviceAdded

src/shared/vscode/device_manager.ts:86–129  ·  view source on GitHub ↗
(device: f.Device)

Source from the content-addressed store, hash-verified

84 }
85
86 public async deviceAdded(device: f.Device): Promise<void> {
87 device = { ...device, type: "device" };
88 this.devices.push(device);
89
90 // undefined is treated as true for backwards compatibility.
91 let canAutoSelectDevice = device.ephemeral !== false || this.isDevicePreferred(device);
92 const currentDeviceIsPreferred = this.isDevicePreferred(this.currentDevice);
93
94 if (canAutoSelectDevice && this.rememberNextAddedDevice)
95 this.rememberDevice(device);
96 else if (canAutoSelectDevice && currentDeviceIsPreferred) {
97 this.logger.info(`Will not auto-select ${device.name} because current device is preferred`);
98 // Don't allow auto-selection if we have the remembered device selected.
99 canAutoSelectDevice = false;
100 }
101
102 // In a remote workspace, allow selecting web-server over a non-ephemeral device so
103 // that we don't seem to default to Linux on a remote we probably can't see.
104 if (!isRunningLocally && this.currentDevice?.ephemeral === false && device.id === "web-server")
105 canAutoSelectDevice = true;
106
107 const maySelectThisDevice = () => !this.currentDevice
108 || (this.config.flutterSelectDeviceWhenConnected && canAutoSelectDevice)
109 // HACK: If the Chrome device becomes available and the selected device is
110 // web-server, allow switching because most users would prefer the Chrome device.
111 // We can revert this in future if Flutter changes the order these devices show up
112 // or has some other way of deciding priority.
113 || (this.currentDevice?.id === "web-server" && device.id === "chrome" && !currentDeviceIsPreferred);
114 if (maySelectThisDevice()) {
115 // Finally, check if it's valid for the workspace. We don't want to
116 // auto-select to a mobile if you have a web-only project open.
117 const supportedPlatforms = await this.getSupportedPlatformsForWorkspace();
118 // We need to re-check maySelectThisDevice() as the answer may have changed if
119 // another device was selected while we were awaiting (which would prevent us
120 // selecting a non-ephemeral device here).
121 if (maySelectThisDevice() && this.isSupported(supportedPlatforms, device)) {
122 this.setCurrentDevice(device);
123 }
124 }
125
126 void this.updateStatusBar();
127 this.onDeviceAddedEmitter.fire(device);
128 this.onDevicesChangedEmitter.fire();
129 }
130
131 private setCurrentDevice(device: f.Device | undefined) {
132 this.currentDevice = device;

Callers

nothing calls this directly

Calls 8

isDevicePreferredMethod · 0.95
rememberDeviceMethod · 0.95
isSupportedMethod · 0.95
setCurrentDeviceMethod · 0.95
updateStatusBarMethod · 0.95
infoMethod · 0.65
fireMethod · 0.45

Tested by

no test coverage detected