Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions flutter-idea/src/io/flutter/run/LaunchState.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -156,14 +158,40 @@ protected RunContentDescriptor launch(@NotNull ExecutionEnvironment env) throws
else {
descriptor = new RunContentBuilder(result, env).showRunContent(env.getContentToReuse());
}

// Add the device name for the run descriptor.
// The descriptor shows the run configuration name (e.g., `main.dart`) by default;
// adding the device name will help users identify the instance when trying to operate a specific one.
final String nameWithDeviceName = descriptor.getDisplayName() + " (" + device.deviceName() + ")";
boolean displayNameUpdated = false;
try {
final Field f = descriptor.getClass().getDeclaredField("myDisplayName");
// Find "myDisplayNameView" for 2024+ builds.
// https://github.com/JetBrains/intellij-community/blob/idea/241.14494.240/platform/execution/src/com/intellij/execution/ui/RunContentDescriptor.java#L33
final Field f = descriptor.getClass().getDeclaredField("myDisplayNameView");
f.setAccessible(true);
f.set(descriptor, descriptor.getDisplayName() + " (" + device.deviceName() + ")");
Object viewInstance = f.get(descriptor);
if (viewInstance != null) {
final Method setValueMethod = viewInstance.getClass().getMethod("setValue", Object.class);
setValueMethod.invoke(viewInstance, nameWithDeviceName);
displayNameUpdated = true;
}
}
catch (IllegalAccessException | NoSuchFieldException e) {
catch (IllegalAccessException | InvocationTargetException | NoSuchFieldException | NoSuchMethodException e) {
LOG.info(e);
}
if (!displayNameUpdated) {
try {
// Find "myDisplayName" for 2023 builds.
// https://github.com/JetBrains/intellij-community/blob/idea/231.8109.175/platform/execution/src/com/intellij/execution/ui/RunContentDescriptor.java#L30
final Field f = descriptor.getClass().getDeclaredField("myDisplayName");
f.setAccessible(true);
f.set(descriptor, nameWithDeviceName);
}
catch (IllegalAccessException | NoSuchFieldException e) {
LOG.info(e);
}
}

return descriptor;
}

Expand Down