genericTsc.ts 1.18 KB
import { buildTscLabelData, buildTscTestPrintData } from '../protocols/tscProtocol'
import type { PrinterCandidate, PrinterDriver } from '../types/printer'

const GENERIC_TSC_KEYWORDS = [
  'printer', 'print', 'label', 'tsc', 'zebra', 'brother', 'epson', 'godex',
  'citizen', 'ql-', 'zd', 'zt', 'ttp', 'tdp', 'bt printer', 'virtual bt printer',
]

function scoreByKeywords (device: PrinterCandidate, keywords: string[]): number {
  const text = `${device.name || ''} ${device.deviceId || ''}`.toLowerCase()
  let score = 0
  keywords.forEach((keyword) => {
    if (text.includes(keyword)) score += 10
  })
  return score
}

export const genericTscDriver: PrinterDriver = {
  key: 'generic-tsc',
  brand: 'Generic',
  model: 'TSC',
  displayName: 'Generic TSC Printer',
  protocol: 'tsc',
  preferredBleMtu: 20,
  imageMaxWidthDots: 800,
  imageDpi: 203,
  keywords: GENERIC_TSC_KEYWORDS,
  matches (device) {
    return scoreByKeywords(device, GENERIC_TSC_KEYWORDS)
  },
  resolveConnectionType (device) {
    return device.type === 'ble' ? 'ble' : 'classic'
  },
  buildTestPrintData () {
    return buildTscTestPrintData()
  },
  buildLabelData (payload) {
    return buildTscLabelData(payload)
  },
}