Skip to content

Commit 0c94262

Browse files
authored
1 parent 69d1b88 commit 0c94262

2 files changed

Lines changed: 74 additions & 1 deletion

File tree

src/io/flutter/devtools/DevToolsUrl.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
*/
66
package io.flutter.devtools;
77

8+
import com.intellij.openapi.application.ApplicationManager;
89
import io.flutter.bazel.WorkspaceCache;
910
import io.flutter.sdk.FlutterSdkUtil;
1011
import io.flutter.sdk.FlutterSdkVersion;
1112
import com.intellij.openapi.util.text.StringUtil;
13+
import com.intellij.openapi.application.ApplicationInfo;
1214
import org.jetbrains.annotations.NotNull;
1315
import org.jetbrains.annotations.Nullable;
1416

@@ -19,6 +21,7 @@
1921
import java.util.Objects;
2022

2123
public class DevToolsUrl {
24+
public static final String UNKNOWN_INTELLIJ_NAME = "IntelliJ - Unknown";
2225
private String devToolsHost;
2326
private int devToolsPort;
2427
public String vmServiceUri;
@@ -34,6 +37,7 @@ public class DevToolsUrl {
3437
private final boolean canUseMultiEmbed;
3538

3639
public final DevToolsIdeFeature ideFeature;
40+
private final String ideName;
3741

3842
@NotNull private final DevToolsUtils devToolsUtils;
3943

@@ -50,6 +54,7 @@ public static class Builder {
5054
private @Nullable FlutterSdkVersion flutterSdkVersion;
5155
private WorkspaceCache workspaceCache;
5256
private DevToolsIdeFeature ideFeature;
57+
private String ideName;
5358

5459
private DevToolsUtils devToolsUtils;
5560

@@ -130,6 +135,12 @@ public Builder setFlutterSdkUtil(FlutterSdkUtil flutterSdkUtil) {
130135
return this;
131136
}
132137

138+
@NotNull
139+
public Builder setIdeName(String ideName) {
140+
this.ideName = ideName;
141+
return this;
142+
}
143+
133144
@NotNull
134145
public DevToolsUrl build() {
135146
if (devToolsUtils == null) {
@@ -161,6 +172,7 @@ private DevToolsUrl(Builder builder) {
161172
this.flutterSdkVersion = builder.flutterSdkVersion;
162173
this.ideFeature = builder.ideFeature;
163174
this.sdkUtil = builder.flutterSdkUtil;
175+
this.ideName = builder.ideName != null ? builder.ideName : getIdeName();
164176

165177
if (builder.workspaceCache != null && builder.workspaceCache.isBazel()) {
166178
this.canUseMultiEmbed = true;
@@ -179,7 +191,10 @@ public String getUrlString() {
179191
final List<String> params = new ArrayList<>();
180192

181193
String ideValue = sdkUtil.getFlutterHostEnvValue();
182-
params.add("ide=" + (ideValue == null ? "IntelliJPluginUnknown" : ideValue));
194+
String ideParamValue = ideValue == null ? UNKNOWN_INTELLIJ_NAME : ideValue;
195+
params.add("ide=" + URLEncoder.encode(ideParamValue, StandardCharsets.UTF_8));
196+
params.add("dashTool=intellij-plugins");
197+
params.add("dashIdeName=" + URLEncoder.encode(this.ideName, StandardCharsets.UTF_8));
183198
if (colorHexCode != null) {
184199
params.add("backgroundColor=" + colorHexCode);
185200
}
@@ -216,6 +231,20 @@ public String getUrlString() {
216231
+ StringUtil.join(params, "&");
217232
}
218233

234+
private @NotNull String getIdeName() {
235+
if (ApplicationManager.getApplication() == null) {
236+
return UNKNOWN_INTELLIJ_NAME;
237+
}
238+
ApplicationInfo appInfo = ApplicationInfo.getInstance();
239+
if (appInfo != null) {
240+
String versionName = appInfo.getVersionName();
241+
if (versionName != null) {
242+
return versionName;
243+
}
244+
}
245+
return UNKNOWN_INTELLIJ_NAME;
246+
}
247+
219248
public boolean maybeUpdateColor() {
220249
final String newColor = devToolsUtils.getColorHexCode();
221250
if (Objects.equals(colorHexCode, newColor)) {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2026 The Chromium Authors. All rights reserved.
3+
* Use of this source code is governed by a BSD-style license that can be
4+
* found in the LICENSE file.
5+
*/
6+
package io.flutter.devtools;
7+
8+
import io.flutter.sdk.FlutterSdkUtil;
9+
import org.junit.Test;
10+
11+
import java.net.URLEncoder;
12+
import java.nio.charset.StandardCharsets;
13+
14+
import static org.junit.Assert.assertTrue;
15+
16+
public class DevToolsUrlTest {
17+
18+
@Test
19+
public void testGetUrlString() {
20+
DevToolsUrl.Builder builder = new DevToolsUrl.Builder()
21+
.setDevToolsHost("127.0.0.1")
22+
.setDevToolsPort(9100)
23+
.setVmServiceUri("http://127.0.0.1:12345/abc=")
24+
.setIdeName("Test IDE Name");
25+
26+
// Mock FlutterSdkUtil to avoid calling real IntelliJ APIs which might fail in unit tests.
27+
builder.setFlutterSdkUtil(new FlutterSdkUtil() {
28+
@Override
29+
public String getFlutterHostEnvValue() {
30+
return "Test:IDE";
31+
}
32+
});
33+
34+
DevToolsUrl devToolsUrl = builder.build();
35+
String url = devToolsUrl.getUrlString();
36+
37+
// Test:IDE encoded becomes Test%3AIDE
38+
assertTrue(url.contains("ide=Test%3AIDE"));
39+
assertTrue(url.contains("dashTool=intellij-plugins"));
40+
41+
// Test IDE Name encoded becomes Test+IDE+Name
42+
assertTrue(url.contains("dashIdeName=Test+IDE+Name"));
43+
}
44+
}

0 commit comments

Comments
 (0)