diff --git a/Sources/MWBMac/SettingsWindow/SettingsWindow.swift b/Sources/MWBMac/SettingsWindow/SettingsWindow.swift index e0963b0..09fc700 100644 --- a/Sources/MWBMac/SettingsWindow/SettingsWindow.swift +++ b/Sources/MWBMac/SettingsWindow/SettingsWindow.swift @@ -27,7 +27,9 @@ import SwiftUI public func show(pane: SettingsPane? = nil) { if let pane { self.pane.selected = pane } model.storeChanged() - model.refreshDrafts() + // Re-opening starts from what is saved; bringing an already-open window + // forward must not throw away what the user is halfway through typing. + if !isVisible { model.refreshDrafts() } let window = window ?? makeWindow() self.window = window NSApp.activate(ignoringOtherApps: true) diff --git a/Sources/MWBMac/StatusItem.swift b/Sources/MWBMac/StatusItem.swift index 34643dd..a4f24dc 100644 --- a/Sources/MWBMac/StatusItem.swift +++ b/Sources/MWBMac/StatusItem.swift @@ -119,12 +119,6 @@ public struct StatusModel: Sendable, Equatable { /// An empty model. public init() {} - - /// True when anything is wrong enough to badge the icon. - public var hasProblem: Bool { - hostnameProblem != nil || !missingPermissions.isEmpty || !canInject || !tapRunning - || rows.contains { !$0.isLocal && $0.status != .connected && $0.status != .na } - } } /// What the menu can ask the app to do. @@ -340,14 +334,9 @@ enum StatusIcon { static func image(badge: NSColor?) -> NSImage { let size = NSSize(width: 18, height: 14) let image = NSImage(size: size, flipped: false) { _ in - let stroke = badge == nil ? NSColor.black : NSColor.labelColor - stroke.setStroke() - back(in: size).stroke() - let front = NSBezierPath( - roundedRect: NSRect(x: 5.5, y: 1.5, width: 11, height: 8), xRadius: 2, yRadius: 2) - front.lineWidth = 1.2 - NSColor.clear.setFill() - front.stroke() + (badge == nil ? NSColor.black : NSColor.labelColor).setStroke() + screen(x: 1.5, y: 4.5).stroke() + screen(x: 5.5, y: 1.5).stroke() if let badge { badge.setFill() NSBezierPath(ovalIn: NSRect(x: 12, y: 0, width: 5, height: 5)).fill() @@ -358,9 +347,10 @@ enum StatusIcon { return image } - private static func back(in size: NSSize) -> NSBezierPath { + /// One of the two rounded rectangles, with its bottom-left corner at `x, y`. + private static func screen(x: CGFloat, y: CGFloat) -> NSBezierPath { let path = NSBezierPath( - roundedRect: NSRect(x: 1.5, y: 4.5, width: 11, height: 8), xRadius: 2, yRadius: 2) + roundedRect: NSRect(x: x, y: y, width: 11, height: 8), xRadius: 2, yRadius: 2) path.lineWidth = 1.2 return path } diff --git a/Sources/mwb/UIBridge.swift b/Sources/mwb/UIBridge.swift index 0bf5e84..87424a5 100644 --- a/Sources/mwb/UIBridge.swift +++ b/Sources/mwb/UIBridge.swift @@ -27,6 +27,7 @@ import MWBNet private var statusItem: StatusItemController? private var lastStatuses: [String: SocketStatus] = [:] + private var lastNames: [String: String] = [:] private var notificationsEnabled: Bool? init(engine: Engine, store: SettingsStore, localName: String) { @@ -173,10 +174,19 @@ import MWBNet notifier.invalidKey(for: name) } } + // A row can vanish outright — the channel drops it when the connection is + // gone and the name is not in the matrix to be re-dialled. for (key, previous) in lastStatuses where current[key] == nil && previous == .connected { - notifier.lost(key) + notifier.lost(lastNames[key] ?? key) } lastStatuses = current + // Remember the spelling, not just the key: a peer that vanished cannot be + // looked up in the snapshot any more. Two connections can carry the same + // name, so this is a loop rather than `Dictionary(uniqueKeysWithValues:)`, + // which traps on a duplicate. + for peer in snapshot.peers where !peer.name.isEmpty { + lastNames[peer.name.lowercased()] = peer.name + } } private func displayName(_ key: String, _ snapshot: EngineSnapshot) -> String? {