Skip to content

Commit 6d21c82

Browse files
committed
♻️ Refactored from myDisplayName to myDisplayNameView
1 parent 0e4511e commit 6d21c82

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

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

+22-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,31 @@ protected RunContentDescriptor launch(@NotNull ExecutionEnvironment env) throws
156158
else {
157159
descriptor = new RunContentBuilder(result, env).showRunContent(env.getContentToReuse());
158160
}
161+
final String nameWithDeviceName = descriptor.getDisplayName() + " (" + device.deviceName() + ")";
162+
boolean displayNameUpdated = false;
159163
try {
160-
final Field f = descriptor.getClass().getDeclaredField("myDisplayName");
164+
final Field f = descriptor.getClass().getDeclaredField("myDisplayNameView");
161165
f.setAccessible(true);
162-
f.set(descriptor, descriptor.getDisplayName() + " (" + device.deviceName() + ")");
166+
Object viewInstance = f.get(descriptor);
167+
if (viewInstance != null) {
168+
final Method setValueMethod = viewInstance.getClass().getMethod("setValue", Object.class);
169+
setValueMethod.invoke(viewInstance, nameWithDeviceName);
170+
displayNameUpdated = true;
171+
}
163172
}
164-
catch (IllegalAccessException | NoSuchFieldException e) {
173+
catch (ClassCastException | IllegalAccessException | InvocationTargetException | NoSuchFieldException | NoSuchMethodException e) {
165174
LOG.info(e);
166175
}
176+
if (!displayNameUpdated) {
177+
try {
178+
final Field f = descriptor.getClass().getDeclaredField("myDisplayName");
179+
f.setAccessible(true);
180+
f.set(descriptor, nameWithDeviceName);
181+
}
182+
catch (IllegalAccessException | NoSuchFieldException e) {
183+
LOG.info(e);
184+
}
185+
}
167186
return descriptor;
168187
}
169188

0 commit comments

Comments
 (0)