mirror of
https://github.com/carey314/mio-plugin-clipper.git
synced 2026-08-10 07:44:32 +00:00
Quick AI actions on clipboard or selected text. Four actions: - 翻译 (中/英/日) - 总结 (3-bullet Chinese) - 改语气 (正式/口语/友好/严谨) - 邮件回复 Powered by DeepSeek with Server-Sent Events streaming for typewriter feedback (~600ms first byte). Two source modes: clipboard (no permission) and selected-text via NSAccessibility (graceful fallback to clipboard + permission banner if denied). Five-state UI machine: idle → input → loading (cancellable) → result → missing-config. Last 20 actions persisted to UserDefaults. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
42 lines
1.4 KiB
Swift
42 lines
1.4 KiB
Swift
//
|
|
// ClipperDebugLog.swift
|
|
// 划词侠 plugin
|
|
//
|
|
// Mirrors the FundDebugLog pattern — plugin-bundle NSLog calls don't
|
|
// reliably surface in `log show` from the host process. This helper
|
|
// appends timestamped lines to /tmp/clipper-plugin.log so we can
|
|
// `tail -f` during debugging.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
enum ClipperDebugLog {
|
|
static let path = "/tmp/clipper-plugin.log"
|
|
private static let queue = DispatchQueue(label: "clipper.debug.log")
|
|
private static let dateFmt: DateFormatter = {
|
|
let f = DateFormatter()
|
|
f.locale = Locale(identifier: "en_US_POSIX")
|
|
f.timeZone = TimeZone.current
|
|
f.dateFormat = "HH:mm:ss.SSS"
|
|
return f
|
|
}()
|
|
|
|
static func write(_ message: String) {
|
|
let stamp = dateFmt.string(from: Date())
|
|
let line = "[\(stamp)] \(message)\n"
|
|
queue.async {
|
|
if let data = line.data(using: .utf8) {
|
|
if FileManager.default.fileExists(atPath: path) {
|
|
if let handle = try? FileHandle(forWritingTo: URL(fileURLWithPath: path)) {
|
|
try? handle.seekToEnd()
|
|
try? handle.write(contentsOf: data)
|
|
try? handle.close()
|
|
}
|
|
} else {
|
|
try? data.write(to: URL(fileURLWithPath: path))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|