warning fixes

This commit is contained in:
Peter Steinberger 2025-07-31 02:21:18 +02:00
parent fe2f30ed73
commit e9a1ce0555
11 changed files with 92 additions and 81 deletions

View file

@ -136,7 +136,8 @@ final class EventSource: NSObject {
} }
// Dispatch event // Dispatch event
logger.debug("🎯 Dispatching event - type: \(event.event ?? "default"), data: \(event.data ?? "none")") logger
.debug("🎯 Dispatching event - type: \(event.event ?? "default"), data: \(event.data ?? "none")")
DispatchQueue.main.async { DispatchQueue.main.async {
self.onMessage?(event) self.onMessage?(event)
} }
@ -228,7 +229,7 @@ extension EventSource: URLSessionDataDelegate {
// Check if data might be compressed // Check if data might be compressed
if data.count > 2 { if data.count > 2 {
let header = [UInt8](data.prefix(2)) let header = [UInt8](data.prefix(2))
if header[0] == 0x1f && header[1] == 0x8b { if header[0] == 0x1F && header[1] == 0x8B {
logger.error("❌ Received gzip compressed data! SSE should not be compressed.") logger.error("❌ Received gzip compressed data! SSE should not be compressed.")
return return
} }

View file

@ -423,7 +423,6 @@ final class NotificationService: NSObject {
// This prevents dual-path connection attempts // This prevents dual-path connection attempts
} }
private func connect() { private func connect() {
logger.info("🔌 NotificationService.connect() called - isConnected: \(self.isConnected)") logger.info("🔌 NotificationService.connect() called - isConnected: \(self.isConnected)")
guard !isConnected else { guard !isConnected else {
@ -434,7 +433,8 @@ final class NotificationService: NSObject {
// When auth mode is "none", we can connect without a token. // When auth mode is "none", we can connect without a token.
// In any other auth mode, a token is required for the local Mac app to connect. // In any other auth mode, a token is required for the local Mac app to connect.
if serverManager.authMode != "none", serverManager.localAuthToken == nil { if serverManager.authMode != "none", serverManager.localAuthToken == nil {
logger.error("No auth token available for notification service in auth mode '\(self.serverManager.authMode)'") logger
.error("No auth token available for notification service in auth mode '\(self.serverManager.authMode)'")
return return
} }
@ -489,7 +489,10 @@ final class NotificationService: NSObject {
eventSource?.onMessage = { [weak self] event in eventSource?.onMessage = { [weak self] event in
Task { @MainActor in Task { @MainActor in
self?.logger.info("🎯 EventSource onMessage fired! Event type: \(event.event ?? "default"), Has data: \(event.data != nil)") self?.logger
.info(
"🎯 EventSource onMessage fired! Event type: \(event.event ?? "default"), Has data: \(event.data != nil)"
)
self?.handleEvent(event) self?.handleEvent(event)
} }
} }
@ -733,7 +736,7 @@ final class NotificationService: NSObject {
let content = UNMutableNotificationContent() let content = UNMutableNotificationContent()
content.title = title content.title = title
content.body = body content.body = body
if let message = message { if let message {
content.subtitle = message content.subtitle = message
} }
content.sound = getNotificationSound() content.sound = getNotificationSound()
@ -821,7 +824,10 @@ final class NotificationService: NSObject {
} }
// Log server info // Log server info
logger.info("Server info - Port: \(self.serverManager.port), Running: \(self.serverManager.isRunning), SSE Connected: \(self.isConnected)") logger
.info(
"Server info - Port: \(self.serverManager.port), Running: \(self.serverManager.isRunning), SSE Connected: \(self.isConnected)"
)
guard let url = serverManager.buildURL(endpoint: "/api/test-notification") else { guard let url = serverManager.buildURL(endpoint: "/api/test-notification") else {
logger.error("❌ Failed to build test notification URL") logger.error("❌ Failed to build test notification URL")
@ -870,4 +876,3 @@ final class NotificationService: NSObject {
// NotificationCenter observers are automatically removed on deinit in modern Swift // NotificationCenter observers are automatically removed on deinit in modern Swift
} }
} }

View file

@ -134,7 +134,7 @@ final class SessionMonitor {
private func fetchSessions() async { private func fetchSessions() async {
do { do {
// Snapshot previous sessions for exit notifications // Snapshot previous sessions for exit notifications
let _ = sessions _ = sessions
let sessionsArray = try await serverManager.performRequest( let sessionsArray = try await serverManager.performRequest(
endpoint: APIEndpoints.sessions, endpoint: APIEndpoints.sessions,

View file

@ -74,11 +74,13 @@ final class TailscaleServeStatusService {
let decoder = JSONDecoder() let decoder = JSONDecoder()
// Use custom date decoder to handle ISO8601 with fractional seconds // Use custom date decoder to handle ISO8601 with fractional seconds
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
decoder.dateDecodingStrategy = .custom { decoder in decoder.dateDecodingStrategy = .custom { decoder in
let container = try decoder.singleValueContainer() let container = try decoder.singleValueContainer()
let dateString = try container.decode(String.self) let dateString = try container.decode(String.self)
// Create formatter inside the closure to avoid Sendable warning
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
if let date = formatter.date(from: dateString) { if let date = formatter.date(from: dateString) {
return date return date
} }
@ -87,7 +89,10 @@ final class TailscaleServeStatusService {
if let date = formatter.date(from: dateString) { if let date = formatter.date(from: dateString) {
return date return date
} }
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Cannot decode date string \(dateString)") throw DecodingError.dataCorruptedError(
in: container,
debugDescription: "Cannot decode date string \(dateString)"
)
} }
let status = try decoder.decode(TailscaleServeStatus.self, from: data) let status = try decoder.decode(TailscaleServeStatus.self, from: data)
@ -98,7 +103,6 @@ final class TailscaleServeStatusService {
startTime = status.startTime startTime = status.startTime
logger.debug("Tailscale Serve status - Running: \(status.isRunning), Error: \(status.lastError ?? "none")") logger.debug("Tailscale Serve status - Running: \(status.isRunning), Error: \(status.lastError ?? "none")")
} catch { } catch {
logger.error("Failed to fetch Tailscale Serve status: \(error.localizedDescription)") logger.error("Failed to fetch Tailscale Serve status: \(error.localizedDescription)")
// On error, assume not running // On error, assume not running

View file

@ -1,6 +1,6 @@
import SwiftUI
import AppKit import AppKit
import os.log import os.log
import SwiftUI
/// Authentication configuration section for remote access settings /// Authentication configuration section for remote access settings
struct AuthenticationSection: View { struct AuthenticationSection: View {

View file

@ -80,7 +80,8 @@ struct NotificationSettingsView: View {
} }
.help(sseConnectionStatus .help(sseConnectionStatus
? "Real-time notification stream is connected" ? "Real-time notification stream is connected"
: "Real-time notification stream is disconnected. Check if the server is running.") : "Real-time notification stream is disconnected. Check if the server is running."
)
// Show warning when disconnected // Show warning when disconnected
if showNotifications && !sseConnectionStatus { if showNotifications && !sseConnectionStatus {

View file

@ -94,7 +94,8 @@ struct RemoteAccessSettingsView: View {
onAppearSetup() onAppearSetup()
updateLocalIPAddress() updateLocalIPAddress()
// Initialize authentication mode from stored value // Initialize authentication mode from stored value
let storedMode = UserDefaults.standard.string(forKey: AppConstants.UserDefaultsKeys.authenticationMode) ?? "os" let storedMode = UserDefaults.standard
.string(forKey: AppConstants.UserDefaultsKeys.authenticationMode) ?? "os"
authMode = AuthenticationMode(rawValue: storedMode) ?? .osAuth authMode = AuthenticationMode(rawValue: storedMode) ?? .osAuth
// Start monitoring Tailscale Serve status // Start monitoring Tailscale Serve status
tailscaleServeStatus.startMonitoring() tailscaleServeStatus.startMonitoring()
@ -628,7 +629,6 @@ private struct ErrorView: View {
} }
} }
// MARK: - Previews // MARK: - Previews
#Preview("Remote Access Settings") { #Preview("Remote Access Settings") {