Skip to content

Commit e857f66

Browse files
authored
[analytics] instrument device selector actions (flutter#8606)
Instruments: * `DeviceSelectorAction` * `DeviceSelectorRefresherAction` See: flutter#8598 --- <details> <summary>Contribution guidelines:</summary><br> - See our [contributor guide]([https://github.com/dart-lang/sdk/blob/main/CONTRIBUTING.md](https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview) for general expectations for PRs. - Larger or significant changes should be discussed in an issue before creating a PR. - Dart contributions to our repos should follow the [Dart style guide](https://dart.dev/guides/language/effective-dart) and use `dart format`. - Java and Kotlin contributions should strive to follow Java and Kotlin best practices ([discussion](flutter#8098)). </details>
1 parent 6348906 commit e857f66

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

src/io/flutter/actions/DeviceSelectorAction.java

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@
88
import com.intellij.icons.AllIcons;
99
import com.intellij.ide.ActivityTracker;
1010
import com.intellij.ide.DataManager;
11-
import com.intellij.openapi.actionSystem.*;
11+
import com.intellij.openapi.actionSystem.ActionUpdateThread;
12+
import com.intellij.openapi.actionSystem.AnAction;
13+
import com.intellij.openapi.actionSystem.AnActionEvent;
14+
import com.intellij.openapi.actionSystem.CommonDataKeys;
15+
import com.intellij.openapi.actionSystem.DataContext;
16+
import com.intellij.openapi.actionSystem.DataKey;
17+
import com.intellij.openapi.actionSystem.DefaultActionGroup;
18+
import com.intellij.openapi.actionSystem.PlatformCoreDataKeys;
19+
import com.intellij.openapi.actionSystem.Presentation;
20+
import com.intellij.openapi.actionSystem.Separator;
1221
import com.intellij.openapi.actionSystem.ex.CustomComponentAction;
1322
import com.intellij.openapi.application.Application;
1423
import com.intellij.openapi.application.ApplicationManager;
@@ -31,6 +40,8 @@
3140
import com.intellij.util.ui.UIUtil;
3241
import icons.FlutterIcons;
3342
import io.flutter.FlutterBundle;
43+
import io.flutter.analytics.Analytics;
44+
import io.flutter.analytics.AnalyticsData;
3445
import io.flutter.logging.PluginLogger;
3546
import io.flutter.run.FlutterDevice;
3647
import io.flutter.run.daemon.DeviceService;
@@ -39,12 +50,28 @@
3950
import org.jetbrains.annotations.NotNull;
4051
import org.jetbrains.annotations.Nullable;
4152

42-
import javax.swing.*;
43-
import java.awt.*;
53+
import javax.swing.ButtonModel;
54+
import javax.swing.Icon;
55+
import javax.swing.JButton;
56+
import javax.swing.JComponent;
57+
import javax.swing.JPanel;
58+
import javax.swing.SwingUtilities;
59+
import java.awt.BorderLayout;
60+
import java.awt.Color;
61+
import java.awt.Component;
62+
import java.awt.Container;
63+
import java.awt.Dimension;
64+
import java.awt.FontMetrics;
65+
import java.awt.Graphics;
66+
import java.awt.Graphics2D;
67+
import java.awt.RenderingHints;
4468
import java.awt.event.MouseAdapter;
4569
import java.awt.event.MouseEvent;
46-
import java.util.*;
70+
import java.util.ArrayList;
71+
import java.util.Collection;
72+
import java.util.Collections;
4773
import java.util.List;
74+
import java.util.Objects;
4875

4976
public class DeviceSelectorAction extends AnAction implements CustomComponentAction, DumbAware {
5077
private static final @NotNull Logger LOG = PluginLogger.createLogger(DeviceSelectorAction.class);
@@ -89,7 +116,7 @@ public class DeviceSelectorAction extends AnAction implements CustomComponentAct
89116
* </p>
90117
*
91118
* @return A {@link Color} suitable for toolbar text that adapts to the current theme,
92-
* including configurations like light themes with dark headers.
119+
* including configurations like light themes with dark headers.
93120
*/
94121
@NotNull Color getToolbarForegroundColor() {
95122
return JBColor.namedColor(TOOLBAR_FOREGROUND_KEY, UIUtil.getLabelForeground());
@@ -105,7 +132,7 @@ public class DeviceSelectorAction extends AnAction implements CustomComponentAct
105132
* </p>
106133
*
107134
* @return A {@link Color} suitable for toolbar icon button hover states that adapts to the
108-
* current theme, ensuring consistency with other toolbar actions.
135+
* current theme, ensuring consistency with other toolbar actions.
109136
*/
110137
@NotNull Color getToolbarHoverBackgroundColor() {
111138
return JBColor.namedColor(TOOLBAR_ICON_HOVER_BACKGROUND_KEY, JBUI.CurrentTheme.ActionButton.hoverBackground());
@@ -122,6 +149,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
122149
return;
123150
}
124151

152+
Analytics.report(AnalyticsData.forAction(this, e));
153+
125154
final DefaultActionGroup group = new DefaultActionGroup();
126155
group.addAll(actions);
127156

src/io/flutter/actions/DeviceSelectorRefresherAction.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import com.intellij.openapi.actionSystem.AnAction;
1010
import com.intellij.openapi.actionSystem.AnActionEvent;
1111
import com.intellij.openapi.project.Project;
12+
import io.flutter.analytics.Analytics;
13+
import io.flutter.analytics.AnalyticsData;
1214
import io.flutter.run.daemon.DeviceService;
1315
import io.flutter.utils.FlutterModuleUtils;
1416
import org.jetbrains.annotations.NotNull;
@@ -17,9 +19,10 @@ public class DeviceSelectorRefresherAction extends AnAction {
1719
@Override
1820
public void actionPerformed(@NotNull AnActionEvent e) {
1921
final Project project = e.getProject();
20-
if (project != null) {
21-
DeviceService.getInstance(project).restart();
22-
}
22+
if (project == null) return;
23+
24+
Analytics.report(AnalyticsData.forAction(this, e));
25+
DeviceService.getInstance(project).restart();
2326
}
2427

2528
public @NotNull ActionUpdateThread getActionUpdateThread() {

0 commit comments

Comments
 (0)