fix(platform): require OnePlus PKC110 fallback match

This commit is contained in:
2026-07-01 19:36:26 +08:00
parent 994c368f2d
commit 1cb031f793
2 changed files with 38 additions and 0 deletions
@@ -0,0 +1,32 @@
import { describe, expect, it } from "vitest";
import { PlatformDetector } from "../platform-detect";
describe("PlatformDetector", () => {
it("treats OnePlus PKC110 as an OPPO-family keyboard fallback device", () => {
const ua =
"Mozilla/5.0 (Linux; Android 15; OnePlus PKC110 Build/AP3A.240617.008; wv) " +
"AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 " +
"Chrome/126.0.0.0 Mobile Safari/537.36 FBAN/FB4A";
expect(PlatformDetector.isOppoFamilyDevice(ua)).toBe(true);
});
it("does not treat other OnePlus models as OPPO-family fallback devices", () => {
const ua =
"Mozilla/5.0 (Linux; Android 15; NE2210 Build/AP3A.240617.008; wv) " +
"AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 " +
"Chrome/126.0.0.0 Mobile Safari/537.36 FBAN/FB4A";
expect(PlatformDetector.isOppoFamilyDevice(ua)).toBe(false);
});
it("keeps OPPO CPH models as OPPO-family fallback devices", () => {
const ua =
"Mozilla/5.0 (Linux; Android 15; OPPO CPH2609 Build/AP3A.240617.008; wv) " +
"AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 " +
"Chrome/126.0.0.0 Mobile Safari/537.36 FBAN/FB4A";
expect(PlatformDetector.isOppoFamilyDevice(ua)).toBe(true);
});
});
+6
View File
@@ -94,6 +94,12 @@ export class PlatformDetector {
static isOppoFamilyDevice(ua: string | null = null): boolean {
const info = PlatformDetector.getPlatformInfo(ua);
const target = `${info.deviceVendor} ${info.deviceModel} ${info.userAgent}`;
const isOnePlusFamily = /\bOnePlus\b/i.test(
`${info.deviceVendor} ${info.userAgent}`,
);
if (isOnePlusFamily) {
return /\bPKC110\b/i.test(`${info.deviceModel} ${info.userAgent}`);
}
return /\b(OPPO|OPlus|ColorOS|CPH\d{3,})\b/i.test(target);
}