app-ui: three fixes found re-reading the first pass
- UIBridge remembered only the lowercased key of a peer, so a "Lost X" notification for a row that vanished printed the name in lower case; and the spelling map was built with Dictionary(uniqueKeysWithValues:), which traps when a peer pair has two connections carrying one name. - SettingsWindowController.show() refreshed the drafts unconditionally, so opening the Advanced pane from the menu threw away a half-typed security key. It now refreshes only when the window was not visible. - StatusItem: dropped the unused StatusModel.hasProblem and the dead fill/size argument in the icon drawing. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
1 parent
6b2b3fc65a
commit
716c5be5c5
3 files changed
+20
-18
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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? {
|
||||
|
||||
Reference in new issue
Block a user