Skip to content

Commit a6abe92

Browse files
authored
♻️ Add back the device name with the running tab (#7948)
Recovers the ability of #6774. Fixes #7605 Fixes #7539 `myDisplayName` no longer exists in the `com.intellij.execution.ui.RunContentDescriptor`, it has been replaced by a `MutableReactiveProperty` `myDisplayNameView` since 2024 builds. [2024+ `myDisplayNameView`](https://github.com/JetBrains/intellij-community/blob/idea/231.8109.175/platform/execution/src/com/intellij/execution/ui/RunContentDescriptor.java#L30) [2023 `myDisplayName`](https://github.com/JetBrains/intellij-community/blob/idea/241.14494.240/platform/execution/src/com/intellij/execution/ui/RunContentDescriptor.java#L33)
1 parent c3076b4 commit a6abe92

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

flutter-idea/src/io/flutter/run/LaunchState.java

+31-3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
import org.jetbrains.annotations.Nullable;
5151

5252
import java.lang.reflect.Field;
53+
import java.lang.reflect.InvocationTargetException;
54+
import java.lang.reflect.Method;
5355
import java.util.ArrayList;
5456
import java.util.Arrays;
5557
import java.util.List;
@@ -156,14 +158,40 @@ protected RunContentDescriptor launch(@NotNull ExecutionEnvironment env) throws
156158
else {
157159
descriptor = new RunContentBuilder(result, env).showRunContent(env.getContentToReuse());
158160
}
161+
162+
// Add the device name for the run descriptor.
163+
// The descriptor shows the run configuration name (e.g., `main.dart`) by default;
164+
// adding the device name will help users identify the instance when trying to operate a specific one.
165+
final String nameWithDeviceName = descriptor.getDisplayName() + " (" + device.deviceName() + ")";
166+
boolean displayNameUpdated = false;
159167
try {
160-
final Field f = descriptor.getClass().getDeclaredField("myDisplayName");
168+
// Find "myDisplayNameView" for 2024+ builds.
169+
// https://github.com/JetBrains/intellij-community/blob/idea/241.14494.240/platform/execution/src/com/intellij/execution/ui/RunContentDescriptor.java#L33
170+
final Field f = descriptor.getClass().getDeclaredField("myDisplayNameView");
161171
f.setAccessible(true);
162-
f.set(descriptor, descriptor.getDisplayName() + " (" + device.deviceName() + ")");
172+
Object viewInstance = f.get(descriptor);
173+
if (viewInstance != null) {
174+
final Method setValueMethod = viewInstance.getClass().getMethod("setValue", Object.class);
175+
setValueMethod.invoke(viewInstance, nameWithDeviceName);
176+
displayNameUpdated = true;
177+
}
163178
}
164-
catch (IllegalAccessException | NoSuchFieldException e) {
179+
catch (IllegalAccessException | InvocationTargetException | NoSuchFieldException | NoSuchMethodException e) {
165180
LOG.info(e);
166181
}
182+
if (!displayNameUpdated) {
183+
try {
184+
// Find "myDisplayName" for 2023 builds.
185+
// https://github.com/JetBrains/intellij-community/blob/idea/231.8109.175/platform/execution/src/com/intellij/execution/ui/RunContentDescriptor.java#L30
186+
final Field f = descriptor.getClass().getDeclaredField("myDisplayName");
187+
f.setAccessible(true);
188+
f.set(descriptor, nameWithDeviceName);
189+
}
190+
catch (IllegalAccessException | NoSuchFieldException e) {
191+
LOG.info(e);
192+
}
193+
}
194+
167195
return descriptor;
168196
}
169197

0 commit comments

Comments
 (0)