mirror of
https://github.com/carey314/mio-plugin-worker.git
synced 2026-08-10 07:04:32 +00:00
Office-survival toolkit. Five tabs in the notch: - 🍅 番茄钟: 25/5 focus/break with circular ring timer + tally. - 🪑 久坐: count-up since last break, dock-bounce alert at 45min. - 💧 喝水: animated cup, daily goal tracking with progress dots. - 🏃 下班: H:M:S countdown to clock-out hour with gradient bar. - 🎉 周末: 天/时/分 to next Saturday + rotating 打工语录. 100% local. UNUserNotificationCenter for alerts, dock-bounce fallback when authorization denied. UserDefaults persistence. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
45 lines
1.5 KiB
Swift
45 lines
1.5 KiB
Swift
//
|
|
// WorkerDebugLog.swift
|
|
// 摸鱼侠 plugin
|
|
//
|
|
// Plugin-bundle NSLog calls don't reliably surface in `log show` from
|
|
// the host process. This helper writes timestamped lines to a known
|
|
// file so we can `tail -f` it during debugging.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
enum WorkerDebugLog {
|
|
static let path = "/tmp/worker-plugin.log"
|
|
private static let queue = DispatchQueue(label: "worker.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)) {
|
|
do {
|
|
try handle.seekToEnd()
|
|
try handle.write(contentsOf: data)
|
|
try handle.close()
|
|
} catch {
|
|
// best-effort log: ignore write failures.
|
|
}
|
|
}
|
|
} else {
|
|
try? data.write(to: URL(fileURLWithPath: path))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|