bluetoothPrinterAllowlist.ts 1.04 KB
/** 扫描/配对列表仅展示以下蓝牙名称(大小写不敏感,须完整匹配) */
export const ALLOWED_BLUETOOTH_PRINTER_NAMES = [
  'GP-D320FX-spp_A7FO',
  'Virtual BT Printer',
] as const

const ALLOWED_BLUETOOTH_PRINTER_NAME_SET = new Set(
  ALLOWED_BLUETOOTH_PRINTER_NAMES.map((name) => name.toLowerCase()),
)

export function normalizeBluetoothPrinterName (name: string | undefined | null): string {
  return String(name ?? '').trim()
}

/** 仅允许白名单内的蓝牙打印机名称出现在连接列表 */
export function isAllowedBluetoothPrinterName (name: string | undefined | null): boolean {
  const normalized = normalizeBluetoothPrinterName(name)
  if (!normalized) return false
  return ALLOWED_BLUETOOTH_PRINTER_NAME_SET.has(normalized.toLowerCase())
}

/** 一体机虚拟蓝牙名(走整页光栅与预览一致,不走 native printTemplate) */
export function isVirtualBtPrinterDeviceName (name: string | undefined | null): boolean {
  return normalizeBluetoothPrinterName(name).toLowerCase() === 'virtual bt printer'
}