Skip to content
Merged
Show file tree
Hide file tree
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
52 changes: 28 additions & 24 deletions src/io/flutter/actions/DeviceSelectorAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package io.flutter.actions;

import com.intellij.icons.AllIcons;
import com.intellij.ide.ActivityTracker;
import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnAction;
Expand Down Expand Up @@ -46,6 +45,7 @@
import io.flutter.run.FlutterDevice;
import io.flutter.run.daemon.DeviceService;
import io.flutter.sdk.AndroidEmulatorManager;
import io.flutter.utils.AsyncUtils;
import io.flutter.utils.FlutterModuleUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -381,14 +381,19 @@ public void projectClosing(@NotNull Project project) {
update(project, presentation);
}

updateComponent(project, presentation);
Comment thread
pq marked this conversation as resolved.
Comment thread
pq marked this conversation as resolved.
}

private void updateComponent(@NotNull Project project, @NotNull Presentation presentation) {
final DeviceService deviceService = DeviceService.getInstance(project);
final FlutterDevice selectedDevice = deviceService.getSelectedDevice();
final Collection<FlutterDevice> devices = deviceService.getConnectedDevices();

final String text;
Icon icon = DEFAULT_DEVICE_ICON;
Icon icon;

if (devices.isEmpty()) {
icon = DEFAULT_DEVICE_ICON;
final boolean isLoading = deviceService.getStatus() == DeviceService.State.LOADING;
if (isLoading) {
text = FlutterBundle.message("devicelist.loading");
Expand All @@ -398,6 +403,7 @@ public void projectClosing(@NotNull Project project) {
}
}
else if (selectedDevice == null) {
icon = DEFAULT_DEVICE_ICON;
text = FlutterBundle.message("devicelist.noDeviceSelected");
}
else {
Expand All @@ -412,25 +418,27 @@ else if (selectedDevice == null) {
// Update the custom component if it exists
final JButton customComponent = presentation.getClientProperty(CUSTOM_COMPONENT_KEY);
if (customComponent != null) {
final @Nullable JBLabel iconLabel = (JBLabel)customComponent.getClientProperty(ICON_LABEL_KEY);
final @Nullable JBLabel textLabel = (JBLabel)customComponent.getClientProperty(TEXT_LABEL_KEY);
AsyncUtils.invokeLater(() -> {
Comment thread
pq marked this conversation as resolved.
final @Nullable JBLabel iconLabel = (JBLabel)customComponent.getClientProperty(ICON_LABEL_KEY);
final @Nullable JBLabel textLabel = (JBLabel)customComponent.getClientProperty(TEXT_LABEL_KEY);

if (iconLabel != null) {
iconLabel.setIcon(icon);
}
if (textLabel != null) {
textLabel.setText(text);
// Update the foreground color to adapt to theme changes.
textLabel.setForeground(getToolbarForegroundColor());
customComponent.invalidate();
Container parent = customComponent.getParent();
while (parent != null) {
parent.invalidate();
parent = parent.getParent();
if (iconLabel != null) {
iconLabel.setIcon(icon);
}
customComponent.revalidate();
customComponent.repaint();
}
if (textLabel != null) {
textLabel.setText(text);
// Update the foreground color to adapt to theme changes.
textLabel.setForeground(getToolbarForegroundColor());
customComponent.invalidate();
Container parent = customComponent.getParent();
while (parent != null) {
parent.invalidate();
parent = parent.getParent();
}
customComponent.revalidate();
customComponent.repaint();
}
});
}
}

Expand All @@ -447,6 +455,7 @@ private void update(@NotNull Project project, @NotNull Presentation presentation
}
updateActions(project, presentation);
updateVisibility(project, presentation);
updateComponent(project, presentation);
Comment thread
pq marked this conversation as resolved.
}

private static void updateVisibility(final Project project, final @NotNull Presentation presentation) {
Expand Down Expand Up @@ -531,11 +540,6 @@ private void updateActions(@NotNull Project project, @NotNull Presentation prese
// Atomically replace the action list
LOG.debug("[" + projectName + "] Replacing device selector actions");
this.actions = newActions;

var tracker = ActivityTracker.getInstance();
if (tracker != null) {
tracker.inc();
}
}

private static class SelectDeviceAction extends AnAction {
Expand Down
1 change: 0 additions & 1 deletion src/io/flutter/run/daemon/DeviceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ private void refreshDeviceDaemon() {
if (project.isDisposed()) return;
deviceDaemon.refresh(this::chooseNextDaemon);
refreshInProgress = false;
ActivityTracker.getInstance().inc();
});
}

Expand Down
Loading