Skip to content

Commit 98c374b

Browse files
authored
quick updates to get apptype (#2969)
1 parent c411df4 commit 98c374b

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

cmd/server/main-server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ func startupActivityUpdate(firstLaunch bool) {
343343
ClientArch: wavebase.ClientArch(),
344344
ClientOSRelease: wavebase.UnameKernelRelease(),
345345
ClientIsDev: wavebase.IsDevMode(),
346+
ClientPackageType: wavebase.ClientPackageType(),
347+
ClientMacOSVersion: wavebase.ClientMacOSVersion(),
346348
AutoUpdateChannel: autoUpdateChannel,
347349
AutoUpdateEnabled: autoUpdateEnabled,
348350
LocalShellType: shellType,

frontend/types/gotypes.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,8 @@ declare global {
14421442
"client:buildtime"?: string;
14431443
"client:osrelease"?: string;
14441444
"client:isdev"?: boolean;
1445+
"client:packagetype"?: string;
1446+
"client:macos"?: string;
14451447
"cohort:month"?: string;
14461448
"cohort:isoweek"?: string;
14471449
"autoupdate:channel"?: string;
@@ -1540,6 +1542,8 @@ declare global {
15401542
"client:buildtime"?: string;
15411543
"client:osrelease"?: string;
15421544
"client:isdev"?: boolean;
1545+
"client:packagetype"?: string;
1546+
"client:macos"?: string;
15431547
"cohort:month"?: string;
15441548
"cohort:isoweek"?: string;
15451549
"autoupdate:channel"?: string;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/telemetry/telemetrydata/telemetrydata.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ type TEventUserProps struct {
7676
ClientBuildTime string `json:"client:buildtime,omitempty"`
7777
ClientOSRelease string `json:"client:osrelease,omitempty"`
7878
ClientIsDev bool `json:"client:isdev,omitempty"`
79+
ClientPackageType string `json:"client:packagetype,omitempty"`
80+
ClientMacOSVersion string `json:"client:macos,omitempty"`
7981

8082
CohortMonth string `json:"cohort:month,omitempty"`
8183
CohortISOWeek string `json:"cohort:isoweek,omitempty"`

pkg/wavebase/wavebase.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,46 @@ func ClientArch() string {
346346
return fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
347347
}
348348

349+
func ClientPackageType() string {
350+
if os.Getenv("SNAP") != "" {
351+
return "snap"
352+
}
353+
if os.Getenv("APPIMAGE") != "" {
354+
return "appimage"
355+
}
356+
return ""
357+
}
358+
359+
var macOSVersionOnce = &sync.Once{}
360+
var cachedMacOSVersion string
361+
362+
var macOSVersionRegex = regexp.MustCompile(`^(\d+\.\d+(?:\.\d+)?)`)
363+
364+
func internalMacOSVersion() string {
365+
ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second)
366+
defer cancelFn()
367+
out, err := exec.CommandContext(ctx, "sw_vers", "-productVersion").Output()
368+
if err != nil {
369+
return ""
370+
}
371+
versionStr := strings.TrimSpace(string(out))
372+
m := macOSVersionRegex.FindStringSubmatch(versionStr)
373+
if len(m) < 2 {
374+
return ""
375+
}
376+
return m[1]
377+
}
378+
379+
func ClientMacOSVersion() string {
380+
if runtime.GOOS != "darwin" {
381+
return ""
382+
}
383+
macOSVersionOnce.Do(func() {
384+
cachedMacOSVersion = internalMacOSVersion()
385+
})
386+
return cachedMacOSVersion
387+
}
388+
349389
var releaseRegex = regexp.MustCompile(`^(\d+\.\d+\.\d+)`)
350390
var osReleaseOnce = &sync.Once{}
351391
var osRelease string

0 commit comments

Comments
 (0)