fix(chat): replace Android keyboard workaround

This commit is contained in:
2026-07-16 13:18:26 +08:00
parent 1c8a6afce1
commit 5934d48034
17 changed files with 621 additions and 532 deletions
@@ -1,61 +0,0 @@
import { describe, expect, it } from "vitest";
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 = 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 = createOnePlusFacebookUa("NE2210");
expect(
isOnePlusKeyboardFallbackDevice({
model: "NE2210",
vendor: "OnePlus",
}),
).toBe(false);
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);
});
});
-32
View File
@@ -1,7 +1,5 @@
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 {
@@ -87,27 +85,6 @@ export class PlatformDetector {
return PlatformDetector.getPlatformInfo(ua).isDesktop;
}
static isXiaomiFamilyDevice(ua: string | null = null): boolean {
const info = PlatformDetector.getPlatformInfo(ua);
const target = `${info.deviceVendor} ${info.deviceModel} ${info.userAgent}`;
return /\b(Xiaomi|Redmi|POCO|Mi\s|MIX|MIUI)\b/i.test(target);
}
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 isOnePlusKeyboardFallbackDevice({
model: info.deviceModel,
vendor: info.deviceVendor,
});
}
return /\b(OPPO|OPlus|ColorOS|CPH\d{3,})\b/i.test(target);
}
private static getUserAgent(ua: string | null = null): string {
if (ua) return ua;
if (typeof navigator === "undefined") return "";
@@ -119,12 +96,3 @@ 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(),
);
}