Skip to content

♻️ Add back the device name with the running tab #7948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 11, 2025
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