Skip to content

Commit b7b5399

Browse files
Set the extra user agent when a new rpc instance is created
1 parent e9092cc commit b7b5399

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: commands/instances.go

+18
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ func (s *arduinoCoreServerImpl) Create(ctx context.Context, req *rpc.CreateReque
6767
var userAgent string
6868
if md, ok := metadata.FromIncomingContext(ctx); ok {
6969
userAgent = strings.Join(md.Get("user-agent"), " ")
70+
if userAgent != "" {
71+
// s.SettingsGetValue() returns an error if the key does not exist and for this reason we are accessing
72+
// network.user_agent_ext directly from s.settings.ExtraUserAgent() to set it
73+
if s.settings.ExtraUserAgent() == "" {
74+
if strings.Contains(userAgent, "arduino-ide/2") {
75+
// needed for analytics purposes
76+
userAgent = userAgent + " daemon"
77+
}
78+
_, err := s.SettingsSetValue(ctx, &rpc.SettingsSetValueRequest{
79+
Key: "network.user_agent_ext",
80+
ValueFormat: "cli",
81+
EncodedValue: userAgent,
82+
})
83+
if err != nil {
84+
return nil, err
85+
}
86+
}
87+
}
7088
}
7189

7290
// Setup downloads directory

0 commit comments

Comments
 (0)