fix(menubar): 修正进程退出判断与公网刷新及风扇语言
This commit is contained in:
@@ -55,9 +55,12 @@ extension MenuPanelView {
|
||||
.task(id: publicIPRoute) {
|
||||
publicIPAddress = nil
|
||||
guard snapshot.networkPath == .available else { return }
|
||||
let address = await PublicIPAddressService.shared.address(route: publicIPRoute)
|
||||
guard !Task.isCancelled else { return }
|
||||
publicIPAddress = address
|
||||
await PublicIPAddressService.shared.refreshContinuously(route: publicIPRoute) { address in
|
||||
await MainActor.run {
|
||||
guard !Task.isCancelled else { return }
|
||||
publicIPAddress = address
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var publicIPRoute: String {
|
||||
|
||||
@@ -96,8 +96,8 @@ extension MenuPanelView {
|
||||
ForEach(fans) { fan in
|
||||
FanSpeedIndicator(
|
||||
title: fans.count == 2
|
||||
? (fan.id == 0 ? "gpu.fanLeft" : "gpu.fanRight")
|
||||
: LocalizedStringKey("\(String(localized: "gpu.fan")) \(fan.id + 1)"), rpm: fan.rpm)
|
||||
? (fan.id == 0 ? Text("gpu.fanLeft") : Text("gpu.fanRight"))
|
||||
: Text("gpu.fanNumber \(fan.id + 1)"), rpm: fan.rpm)
|
||||
}
|
||||
}
|
||||
.modifier(CardInset())
|
||||
|
||||
@@ -2,6 +2,13 @@ import Foundation
|
||||
|
||||
/// Compute once per data/filter/sort event, never from row rendering or scroll position.
|
||||
nonisolated enum ProcessTableProjection {
|
||||
/// Filtering hides rows without terminating processes. A failed read proves no departure.
|
||||
static func exitedSelection(_ selected: ProcessIdentity?, in snapshot: ProcessSnapshot?) -> ProcessIdentity? {
|
||||
guard let selected, let snapshot, !snapshot.failed,
|
||||
!snapshot.rows.contains(where: { $0.id == selected }) else { return nil }
|
||||
return selected
|
||||
}
|
||||
|
||||
static func rows(_ input: [ProcessMetrics], query: String, sorting: [ProcessSort], order: [ProcessIdentity]) -> [ProcessMetrics] {
|
||||
let ranks = Dictionary(uniqueKeysWithValues: order.enumerated().map { ($0.element, $0.offset) })
|
||||
return input.filter {
|
||||
|
||||
@@ -14,10 +14,9 @@ struct ProcessTableView: View {
|
||||
@State private var searchFocused = false
|
||||
|
||||
private var held: Bool { hovering || selected != nil || !search.isEmpty }
|
||||
private var selectedRow: ProcessMetrics? { rows.first { $0.id == selected } }
|
||||
private var selectedRow: ProcessMetrics? { snapshot?.rows.first { $0.id == selected } }
|
||||
private var exitedSelection: ProcessIdentity? {
|
||||
guard let selected, snapshot != nil, !rows.contains(where: { $0.id == selected }) else { return nil }
|
||||
return selected
|
||||
ProcessTableProjection.exitedSelection(selected, in: snapshot)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@@ -74,7 +73,7 @@ struct ProcessTableView: View {
|
||||
.task(id: exitedSelection) {
|
||||
guard let id = exitedSelection else { return }
|
||||
do { try await Task.sleep(for: .seconds(3)) } catch { return }
|
||||
if selected == id { selected = nil; departed = nil }
|
||||
if exitedSelection == id { selected = nil; departed = nil }
|
||||
}
|
||||
.onExitCommand {
|
||||
if !search.isEmpty { search = "" }
|
||||
|
||||
Reference in New Issue
Block a user