Initial commit

This commit is contained in:
Felipe M 2025-09-18 19:56:06 +02:00
commit 1db16227b2
Signed by: fmartingr
GPG key ID: CCFBC5637D4000A8
31 changed files with 2175 additions and 0 deletions

View file

@ -0,0 +1,24 @@
import Foundation
public enum AppState: String, CaseIterable {
case idle = "idle"
case listening = "listening"
case processing = "processing"
case injecting = "injecting"
case error = "error"
public var displayName: String {
switch self {
case .idle:
return NSLocalizedString("menubar.idle", comment: "Idle state")
case .listening:
return NSLocalizedString("menubar.listening", comment: "Listening state")
case .processing:
return NSLocalizedString("menubar.processing", comment: "Processing state")
case .injecting:
return "Injecting" // Not shown in menu bar
case .error:
return "Error" // Not shown in menu bar
}
}
}

View file

@ -0,0 +1,51 @@
import Foundation
import os.log
public enum LogLevel: String, CaseIterable {
case debug = "DEBUG"
case info = "INFO"
case warning = "WARNING"
case error = "ERROR"
}
public class Logger {
private let osLog: OSLog
private let category: String
public init(category: String) {
self.category = category
self.osLog = OSLog(subsystem: "com.menuwhisper.app", category: category)
}
public func debug(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {
log(level: .debug, message: message, file: file, function: function, line: line)
}
public func info(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {
log(level: .info, message: message, file: file, function: function, line: line)
}
public func warning(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {
log(level: .warning, message: message, file: file, function: function, line: line)
}
public func error(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {
log(level: .error, message: message, file: file, function: function, line: line)
}
private func log(level: LogLevel, message: String, file: String, function: String, line: Int) {
let fileName = URL(fileURLWithPath: file).lastPathComponent
let logMessage = "[\(category)] \(message) (\(fileName):\(function):\(line))"
switch level {
case .debug:
os_log("%{public}@", log: osLog, type: .debug, logMessage)
case .info:
os_log("%{public}@", log: osLog, type: .info, logMessage)
case .warning:
os_log("%{public}@", log: osLog, type: .default, logMessage)
case .error:
os_log("%{public}@", log: osLog, type: .error, logMessage)
}
}
}