Skip to content

Commit 8609680

Browse files
committed
Accept arch and os version as init params on Qt
1 parent 70b6ae5 commit 8609680

File tree

5 files changed

+36
-10
lines changed

5 files changed

+36
-10
lines changed

glean/src/core/config.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ export interface ConfigurationInterface {
2929
plugins?: Plugin[],
3030
// The HTTP client implementation to use for uploading pings.
3131
httpClient?: Uploader,
32+
// Qt-only fields
33+
//
34+
// These values are not easily accessible from QML,
35+
// so we expose them as init fields for the caller to fill them out.
36+
//
37+
// The architecture of the device (e.g. "arm", "x86").
38+
readonly architecture?: string,
39+
// The user-visible version of the operating system (e.g. "1.2.3").
40+
// If the version detection fails, this metric gets set to Unknown.
41+
readonly osVersion?: string,
3242
}
3343

3444
// Important: the `Configuration` should only be used internally by the Glean singleton.
@@ -41,6 +51,12 @@ export class Configuration implements ConfigurationInterface {
4151
readonly appDisplayVersion?: string;
4252
// The server pings are sent to.
4353
readonly serverEndpoint: string;
54+
// The architecture of the device (e.g. "arm", "x86").
55+
readonly architecture?: string;
56+
// The user-visible version of the operating system (e.g. "1.2.3").
57+
// If the version detection fails, this metric gets set to Unknown.
58+
readonly osVersion?: string;
59+
4460
// Debug configuration.
4561
debug: DebugOptions;
4662
// The HTTP client implementation to use for uploading pings.
@@ -50,6 +66,8 @@ export class Configuration implements ConfigurationInterface {
5066
this.channel = config?.channel;
5167
this.appBuild = config?.appBuild;
5268
this.appDisplayVersion = config?.appDisplayVersion;
69+
this.architecture = config?.architecture;
70+
this.osVersion = config?.osVersion;
5371

5472
this.debug = Configuration.sanitizeDebugOptions(config?.debug);
5573

glean/src/core/internal_metrics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ export class CoreMetrics {
114114
await this.initializeClientId();
115115
await this.initializeFirstRunDate();
116116
await StringMetricType._private_setUndispatched(this.os, await platform.info.os());
117-
await StringMetricType._private_setUndispatched(this.osVersion, await platform.info.osVersion());
118-
await StringMetricType._private_setUndispatched(this.architecture, await platform.info.arch());
117+
await StringMetricType._private_setUndispatched(this.osVersion, await platform.info.osVersion(config.osVersion));
118+
await StringMetricType._private_setUndispatched(this.architecture, await platform.info.arch(config.architecture));
119119
await StringMetricType._private_setUndispatched(this.locale, await platform.info.locale());
120120
await StringMetricType._private_setUndispatched(this.appBuild, config.appBuild || "Unknown");
121121
await StringMetricType._private_setUndispatched(this.appDisplayVersion, config.appDisplayVersion || "Unknown");

glean/src/core/platform_info.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,18 @@ interface PlatformInfo {
3939
/**
4040
* Gets and returns the current OS system version.
4141
*
42+
* @param fallback A fallback value in case Glean is unable to retrive this value from the environment.
4243
* @returns The current OS version.
4344
*/
44-
osVersion(): Promise<string>;
45+
osVersion(fallback?: string): Promise<string>;
4546

4647
/**
4748
* Gets and returnst the current system architecture.
4849
*
50+
* @param fallback A fallback value in case Glean is unable to retrive this value from the environment.
4951
* @returns The current system architecture.
5052
*/
51-
arch(): Promise<string>;
53+
arch(fallback?: string): Promise<string>;
5254

5355
/**
5456
* Gets and returnst the current system / browser locale.

glean/src/index/base.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import Glean from "../core/glean.js";
66
import type { ConfigurationInterface } from "../core/config.js";
77
import type Platform from "../platform/index.js";
88

9+
// Strip the configuration interface of the Qt-only fields.
10+
type RestictedConfigurationInterface = Omit<
11+
ConfigurationInterface,
12+
"architecture" | "osVersion"
13+
>;
14+
915
export default (platform: Platform): {
1016
initialize(
1117
applicationId: string,
@@ -36,7 +42,7 @@ export default (platform: Platform): {
3642
initialize(
3743
applicationId: string,
3844
uploadEnabled: boolean,
39-
config?: ConfigurationInterface
45+
config?: RestictedConfigurationInterface
4046
): void {
4147
Glean.setPlatform(platform);
4248
Glean.initialize(applicationId, uploadEnabled, config);
@@ -132,7 +138,7 @@ export default (platform: Platform): {
132138
async testResetGlean(
133139
applicationId: string,
134140
uploadEnabled = true,
135-
config?: ConfigurationInterface
141+
config?: RestictedConfigurationInterface
136142
): Promise<void> {
137143
return Glean.testResetGlean(applicationId, uploadEnabled, config);
138144
}

glean/src/platform/qt/platform_info.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ const QtPlatformInfo: PlatformInfo = {
3636
}
3737
},
3838

39-
async osVersion(): Promise<string> {
39+
async osVersion(fallback?: string): Promise<string> {
4040
// This data point is not available in Qt QML.
41-
return Promise.resolve("Unknown");
41+
return Promise.resolve(fallback || "Unknown");
4242
},
4343

44-
async arch(): Promise<string> {
44+
async arch(fallback?: string): Promise<string> {
4545
// This data point is not available in Qt QML.
46-
return Promise.resolve("Unknown");
46+
return Promise.resolve(fallback || "Unknown");
4747
},
4848

4949
async locale(): Promise<string> {

0 commit comments

Comments
 (0)