From 1cb031f7930ab4f6cd7c2f4bec3014b0cc912d8e Mon Sep 17 00:00:00 2001 From: chenhang Date: Wed, 1 Jul 2026 19:36:26 +0800 Subject: [PATCH] fix(platform): require OnePlus PKC110 fallback match --- src/utils/__tests__/platform-detect.test.ts | 32 +++++++++++++++++++++ src/utils/platform-detect.ts | 6 ++++ 2 files changed, 38 insertions(+) create mode 100644 src/utils/__tests__/platform-detect.test.ts diff --git a/src/utils/__tests__/platform-detect.test.ts b/src/utils/__tests__/platform-detect.test.ts new file mode 100644 index 00000000..b9722b42 --- /dev/null +++ b/src/utils/__tests__/platform-detect.test.ts @@ -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); + }); +}); diff --git a/src/utils/platform-detect.ts b/src/utils/platform-detect.ts index a2a77526..11f568ff 100644 --- a/src/utils/platform-detect.ts +++ b/src/utils/platform-detect.ts @@ -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); }