fix(keyboard): support OnePlus PLB110 fallback
This commit is contained in:
@@ -1,23 +1,52 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { PlatformDetector } from "../platform-detect";
|
||||
import {
|
||||
isOnePlusKeyboardFallbackDevice,
|
||||
PlatformDetector,
|
||||
} from "../platform-detect";
|
||||
|
||||
function createOnePlusFacebookUa(model: string): string {
|
||||
return (
|
||||
`Mozilla/5.0 (Linux; Android 15; ${model} 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"
|
||||
);
|
||||
}
|
||||
|
||||
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";
|
||||
const ua = createOnePlusFacebookUa("PKC110");
|
||||
|
||||
expect(
|
||||
isOnePlusKeyboardFallbackDevice({
|
||||
model: "PKC110",
|
||||
vendor: "OnePlus",
|
||||
}),
|
||||
).toBe(true);
|
||||
expect(PlatformDetector.isOppoFamilyDevice(ua)).toBe(true);
|
||||
});
|
||||
|
||||
it("treats OnePlus PLB110 as an OPPO-family keyboard fallback device", () => {
|
||||
const ua = createOnePlusFacebookUa("PLB110");
|
||||
|
||||
expect(
|
||||
isOnePlusKeyboardFallbackDevice({
|
||||
model: "PLB110",
|
||||
vendor: "OnePlus",
|
||||
}),
|
||||
).toBe(true);
|
||||
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";
|
||||
const ua = createOnePlusFacebookUa("NE2210");
|
||||
|
||||
expect(
|
||||
isOnePlusKeyboardFallbackDevice({
|
||||
model: "NE2210",
|
||||
vendor: "OnePlus",
|
||||
}),
|
||||
).toBe(false);
|
||||
expect(PlatformDetector.isOppoFamilyDevice(ua)).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { UAParser } from "ua-parser-js";
|
||||
|
||||
const ONEPLUS_KEYBOARD_FALLBACK_MODELS = new Set(["PKC110", "PLB110"]);
|
||||
|
||||
export type PlatformName = "ios" | "android" | "desktop" | "unknown";
|
||||
|
||||
export interface PlatformInfo {
|
||||
@@ -98,7 +100,10 @@ export class PlatformDetector {
|
||||
`${info.deviceVendor} ${info.userAgent}`,
|
||||
);
|
||||
if (isOnePlusFamily) {
|
||||
return /\bPKC110\b/i.test(`${info.deviceModel} ${info.userAgent}`);
|
||||
return isOnePlusKeyboardFallbackDevice({
|
||||
model: info.deviceModel,
|
||||
vendor: info.deviceVendor,
|
||||
});
|
||||
}
|
||||
return /\b(OPPO|OPlus|ColorOS|CPH\d{3,})\b/i.test(target);
|
||||
}
|
||||
@@ -114,3 +119,12 @@ export class PlatformDetector {
|
||||
return navigator.platform === "MacIntel" && (navigator.maxTouchPoints ?? 0) > 1;
|
||||
}
|
||||
}
|
||||
|
||||
export function isOnePlusKeyboardFallbackDevice(
|
||||
device: { model: string; vendor: string },
|
||||
): boolean {
|
||||
if (!/\bOnePlus\b/i.test(device.vendor)) return false;
|
||||
return ONEPLUS_KEYBOARD_FALLBACK_MODELS.has(
|
||||
device.model.trim().toUpperCase(),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user