Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[Full changelog](https://github.com/mozilla/glean.js/compare/v0.11.0...main)

* [#279](https://github.com/mozilla/glean.js/pull/279): BUGFIX: Ensure only empty pings triggers logging of "empty ping" messages.
* [#288](https://github.com/mozilla/glean.js/pull/288): Support collecting `PlatformInfo` from `Qt` applications. Only OS name and locale are supported.

# v0.11.0 (2021-05-03)

Expand Down
5 changes: 5 additions & 0 deletions glean/src/core/platform_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export const enum KnownOperatingSystems {
Solaris = "Solaris",
// ChromeOS is not listed in the Glean SDK because it is not a possibility there.
ChromeOS = "ChromeOS",
// The following additions might be reported by Qt.
TvOS = "tvOS", // https://developer.apple.com/tvos/
Qnx = "QNX", // BlackBerry QNX
Wasm = "Wasm",
// The Qt-specific additions end here.
Unknown = "Unknown",
}

Expand Down
18 changes: 15 additions & 3 deletions glean/src/platform/qt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// Qt does not have its implementations yet,
// we leave this here so that the sample will still work.
export { default } from "../test";
// Qt does not have its implementations yet, we use pieces of
// the `TestPlatform` so that the sample will still work.
import TestPlatform from "../test";

import info from "./platform_info.js";
import type Platform from "../index.js";

const QtPlatform: Platform = {
Storage: TestPlatform.Storage,
uploader: TestPlatform.uploader,
info,
name: "Qt"
};

export default QtPlatform;
55 changes: 55 additions & 0 deletions glean/src/platform/qt/platform_info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import type PlatformInfo from "../../core/platform_info.js";
import { KnownOperatingSystems } from "../../core/platform_info.js";

// The `Qt` symbol can be used in this file without TS compiler errors
// because that symbol is described as a constant in `./types/Qt/index.d.ts`.

const QtPlatformInfo: PlatformInfo = {
// eslint-disable-next-line @typescript-eslint/require-await
async os(): Promise<KnownOperatingSystems> {
// Possible values are listed in https://doc.qt.io/qt-5/qml-qtqml-qt.html#platform-prop
const osName = Qt.platform.os;
switch(osName) {
case "android":
return KnownOperatingSystems.Android;
case "ios":
return KnownOperatingSystems.iOS;
case "tvos":
return KnownOperatingSystems.TvOS;
case "linux":
return KnownOperatingSystems.Linux;
case "osx":
return KnownOperatingSystems.MacOS;
case "qnx":
return KnownOperatingSystems.Qnx;
case "windows":
case "winrt":
return KnownOperatingSystems.Windows;
case "wasm":
return KnownOperatingSystems.Wasm;
default:
return KnownOperatingSystems.Unknown;
}
},

async osVersion(): Promise<string> {
// This data point is not available in Qt QML.
return Promise.resolve("Unknown");
},

async arch(): Promise<string> {
// This data point is not available in Qt QML.
return Promise.resolve("Unknown");
},
Comment on lines +39 to +47
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bakulf do you know any way to get this in Qt-QML?


async locale(): Promise<string> {
const locale = Qt.locale();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this: https://doc.qt.io/qt-5/qml-qtqml-qt.html#locale-method it seems that if name is not valid, QT uses the 'C' locale. Have you tested if this works with non-'C' locales?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, this seems to behave as expected, thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the docs, so for understanding: this will give us the dash-separated locale like es-ES or en-US?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the docs, so for understanding: this will give us the dash-separated locale like es-ES or en-US?

Good thing you mentioned this, I double checked and I missed that we were sending es_ES and not es-ES. I twaked the code to fix this :)

return Promise.resolve(locale ? locale.name.replace("_", "-") : "und");
}
};

export default QtPlatformInfo;
2 changes: 1 addition & 1 deletion glean/tests/core/glean.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import CounterMetricType from "../../src/core/metrics/types/counter";
import PingType from "../../src/core/pings/ping_type";
import type { JSONObject } from "../../src/core/utils";
import { isObject } from "../../src/core/utils";
import TestPlatform from "../../src/platform/qt";
import TestPlatform from "../../src/platform/test";
import Plugin from "../../src/plugins";
import { Lifetime } from "../../src/core/metrics/lifetime";
import { Context } from "../../src/core/context";
Expand Down
2 changes: 1 addition & 1 deletion glean/tests/plugins/encryption.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import compactDecrypt from "jose/jwe/compact/decrypt";
import Glean from "../../src/core/glean";
import PingType from "../../src/core/pings/ping_type";
import type { JSONObject } from "../../src/core/utils";
import TestPlatform from "../../src/platform/qt";
import TestPlatform from "../../src/platform/test";
import PingEncryptionPlugin from "../../src/plugins/encryption";
import collectAndStorePing, { makePath } from "../../src/core/pings/maker";
import type { UploadResult} from "../../src/core/upload/uploader";
Expand Down
6 changes: 5 additions & 1 deletion glean/tsconfig/qt.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"extends": "./base.json",
"compilerOptions": {
"target": "ES5"
"target": "ES5",
"typeRoots": [
"../node_modules/@types",
"../types"
]
},
"include": ["../src/index/qt.ts" ]
}
20 changes: 20 additions & 0 deletions glean/types/Qt/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// This file was created from the template offered on the TS website:
// https://www.typescriptlang.org/docs/handbook/declaration-files/templates/global-d-ts.html

declare namespace Qt {
interface Locale {
name: string;
}

interface Platform {
os: string;
}

const platform: Platform;

function locale(): Locale | undefined;
}