Files
OSGKeyboard/OSGKeyboardExt/Services/ClipboardPasteboardReader.swift
T
Rocky 9da32b81e9 feat(keyboard): harden clipboard command and add What's New sheet
Stabilize clipboard long-press prepare/resume across paste alerts and cold start, add an in-app release-notes sheet with remote bilingual HTML, localize typing input settings, and bump build to 55.
2026-08-08 00:20:42 +08:00

33 lines
1.2 KiB
Swift

// ClipboardPasteboardReader.swift
// OSGKeyboard · Keyboard Extension
//
// Pasteboard peeks for clipboard-command UI and long-press snapshot capture.
//
// Idle affordance must use metadata only (`hasStrings` / `changeCount`) so the
// system「允许粘贴」alert never appears while the keyboard is merely open.
// Content reads (`string`) happen only on an explicit long-press.
import UIKit
import OSGKeyboardShared
enum ClipboardPasteboardReader {
/// Metadata-only — does not trigger the paste permission prompt.
static func changeCount() -> Int {
UIPasteboard.general.changeCount
}
/// Metadata-only — whether the pasteboard currently holds string items.
static func hasStrings() -> Bool {
UIPasteboard.general.hasStrings
}
/// Content sample for long-press snapshot. May present the system paste alert.
static func sample() -> (changeCount: Int, text: String?) {
let board = UIPasteboard.general
let changeCount = board.changeCount
// Prefer plain strings; avoid forcing non-text pasteboard items.
let text = board.hasStrings ? board.string : nil
return (changeCount, text)
}
}