refactor(menubar): 精简内存卡片并对齐双列底部
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import Foundation
|
||||
|
||||
@main struct MemoryHeaderChecks {
|
||||
static func main() {
|
||||
let bundle = Bundle(path: CommandLine.arguments[1])!
|
||||
for (language, titles) in [("en", ["Normal", "Elevated", "Critical"]),
|
||||
("zh-Hans", ["正常", "偏高", "严重"]),
|
||||
("zh-Hant", ["正常", "偏高", "嚴重"])] {
|
||||
let locale = Locale(identifier: language)
|
||||
func localized(_ key: String) -> String { AppLocalization.string(key, locale: locale, bundle: bundle) }
|
||||
for (pressure, title) in zip([1, 2, 4], titles) {
|
||||
let memory = MemoryMetrics(total: 48 << 30, used: 20 << 30, wired: 3 << 30,
|
||||
compressed: 2 << 30, swapUsed: 0, pressure: pressure, cached: 12 << 30)
|
||||
let header = MemoryHeaderInfo(memory: memory, locale: locale, bundle: bundle)
|
||||
precondition(header.title == title)
|
||||
precondition(header.help.components(separatedBy: "\n") == [
|
||||
"\(localized("memory.pressure")): \(title)",
|
||||
"\(localized("memory.cached")): 12.0 GiB",
|
||||
"\(localized("memory.swap")): 0 B"
|
||||
], "Hover details must retain the selected language, current cache and valid zero Swap")
|
||||
}
|
||||
for pressure: Int? in [nil, 8] {
|
||||
let unknown = MemoryMetrics(total: 0, used: 0, wired: 0, compressed: 0,
|
||||
swapUsed: nil, pressure: pressure)
|
||||
let header = MemoryHeaderInfo(memory: unknown, locale: locale, bundle: bundle)
|
||||
precondition(header.title == "--")
|
||||
precondition(header.help.components(separatedBy: "\n").allSatisfy { $0.hasSuffix(": --") })
|
||||
}
|
||||
let absent = MemoryHeaderInfo(memory: nil, locale: locale, bundle: bundle)
|
||||
precondition(absent.title == "--" && absent.help.components(separatedBy: "\n").allSatisfy { $0.hasSuffix(": --") },
|
||||
"Unavailable samples must not become a normal pressure or zero usage")
|
||||
}
|
||||
print("PASS: three-language pressure and hover details, current cache, valid zero Swap and unknown/unavailable samples")
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,11 @@ import CoreGraphics
|
||||
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 500), heights: compact))
|
||||
precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 2400), heights: compact))
|
||||
}
|
||||
precondition(PanelLayout.columnHeights(columns: 2, heights: compact) == [612, 564])
|
||||
precondition(PanelLayout.preferredHeight(width: 640, heights: compact) == 706)
|
||||
precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 706), heights: compact))
|
||||
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 680), heights: compact))
|
||||
precondition(PanelLayout.columnHeights(columns: 2, heights: compact) == [564, 564],
|
||||
"The compact memory card must align ordinary two-column bottoms")
|
||||
precondition(PanelLayout.preferredHeight(width: 640, heights: compact) == 658)
|
||||
precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 658), heights: compact))
|
||||
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 640), heights: compact))
|
||||
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 480, height: 800), heights: compact))
|
||||
precondition(PanelLayout.columns(width: 640) == 2 && PanelLayout.columns(width: 559) == 1)
|
||||
let tallerCPU = PanelLayout.cardHeights(coreRows: 6, fanCount: 2)
|
||||
@@ -39,7 +40,9 @@ import CoreGraphics
|
||||
let moreFans = PanelLayout.cardHeights(coreRows: 2, fanCount: 6)
|
||||
precondition(moreFans[.gpu]! > compact[.gpu]! && moreFans[.storage] == compact[.storage])
|
||||
let noFans = PanelLayout.cardHeights(coreRows: 2, fanCount: 0)
|
||||
precondition(noFans[.gpu] == 124 && PanelLayout.preferredHeight(width: 640, heights: noFans) < 706)
|
||||
precondition(noFans[.gpu] == 124 && PanelLayout.columnHeights(columns: 2, heights: noFans) == [524, 564])
|
||||
precondition(PanelLayout.preferredHeight(width: 640, heights: noFans) == 658,
|
||||
"The right column owns the height when the GPU has no fan section")
|
||||
precondition(PanelLayout.cardHeights(coreRows: 2, fanCount: nil) == compact,
|
||||
"Discovery placeholders must reserve the ordinary fan row")
|
||||
let manyCores = PanelLayout.cardHeights(coreRows: 30, fanCount: 10)
|
||||
|
||||
Reference in New Issue
Block a user