Skip to content

Commit c093058

Browse files
author
Beatriz Rizental
authored
Merge pull request #825 from brizental/1734879-qt-arch-os
Bug 1734879 - Accept arch and os version as init params on Qt
2 parents aa96372 + 174b192 commit c093058

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

glean/src/core/config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ 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+
readonly osVersion?: string,
3241
}
3342

3443
// Important: the `Configuration` should only be used internally by the Glean singleton.
@@ -41,6 +50,11 @@ export class Configuration implements ConfigurationInterface {
4150
readonly appDisplayVersion?: string;
4251
// The server pings are sent to.
4352
readonly serverEndpoint: string;
53+
// The architecture of the device (e.g. "arm", "x86").
54+
readonly architecture?: string;
55+
// The user-visible version of the operating system (e.g. "1.2.3").
56+
readonly osVersion?: string;
57+
4458
// Debug configuration.
4559
debug: DebugOptions;
4660
// The HTTP client implementation to use for uploading pings.
@@ -50,6 +64,8 @@ export class Configuration implements ConfigurationInterface {
5064
this.channel = config?.channel;
5165
this.appBuild = config?.appBuild;
5266
this.appDisplayVersion = config?.appDisplayVersion;
67+
this.architecture = config?.architecture;
68+
this.osVersion = config?.osVersion;
5369

5470
this.debug = Configuration.sanitizeDebugOptions(config?.debug);
5571

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);
@@ -130,7 +136,7 @@ export default (platform: Platform): {
130136
async testResetGlean(
131137
applicationId: string,
132138
uploadEnabled = true,
133-
config?: ConfigurationInterface
139+
config?: RestictedConfigurationInterface
134140
): Promise<void> {
135141
return Glean.testResetGlean(applicationId, uploadEnabled, config);
136142
}

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)