perf(menubar): 降低绘制驻留并复用原生进程表与缩略图

This commit is contained in:
2026-11-04 10:39:15 +08:00
parent 1c26fc18f3
commit 065c53622a
28 changed files with 964 additions and 160 deletions
+16 -6
View File
@@ -24,10 +24,18 @@ CHECKS.update({
"SensorScheduleChecks": ["kymo/Core/Services/SensorSchedule.swift"],
"TrendScrollChecks": CORE + ["kymo/UI/Charts/TrendScroll.swift"],
"CPUCoreGridChecks": ["kymo/Features/MenuBar/CPUCoreGrid.swift", "kymo/Core/Services/CPUCoreTopology.swift",
"kymo/Core/Extensions/MetricFormat.swift", "kymo/UI/Components/MetricProgressBar.swift"],
"kymo/Core/Extensions/MetricFormat.swift", "kymo/UI/Components/MetricProgressBar.swift", "kymo/UI/Components/NativeMetricRing.swift"],
"CPUTemperatureChecks": ["kymo/Core/Monitors/CPUTemperatureMonitor.swift"],
"DiskHealthChecks": ["kymo/Core/Models/DiskHealthMetrics.swift", "kymo/Core/Monitors/DiskHealthReport.swift"],
"PublicIPAddressChecks": ["kymo/Core/Services/PublicIPAddressService.swift"],
"NativeMetricDrawingChecks": ["kymo/UI/Charts/NativePanelCurve.swift", "kymo/UI/Charts/PanelCurveFrame.swift",
"kymo/UI/Charts/PanelCurveGeometry.swift", "kymo/UI/Components/NativeMetricRing.swift"],
"NetworkAddressChecks": ["kymo/Core/Monitors/NetworkMonitor.swift"],
"ProcessIconCacheChecks": ["kymo/Features/MenuBar/ProcessIconCache.swift"],
"NativeProcessTableChecks": ["kymo/Core/Models/ProcessMetrics.swift", "kymo/Features/MenuBar/ProcessTableProjection.swift",
"kymo/Features/MenuBar/NativeProcessTable.swift", "kymo/Features/MenuBar/ProcessIconCache.swift",
"kymo/Core/Services/LanguagePreferences.swift", "kymo/UI/Components/AppLocalization.swift",
"kymoTests/Support/ProcessTableAuditStub.swift"],
"ProcessSelectionChecks": ["kymo/Core/Models/ProcessMetrics.swift", "kymo/Features/MenuBar/ProcessTableProjection.swift"],
"PanelLayoutChecks": ["kymo/Core/Models/ProcessMetrics.swift", "kymo/Features/MenuBar/PanelLayout.swift",
"kymo/Features/MenuBar/ProcessTableProjection.swift"],
@@ -47,7 +55,7 @@ CHECKS.update({
"kymo/UI/Components/IntervalControl.swift"],
"SandboxNetworkChecks": [],
})
GUI = {"LanguageScopeChecks", "SettingsWindowChecks", "PanelWindowChecks"}
GUI = {"NativeMetricDrawingChecks", "NativeProcessTableChecks", "LanguageScopeChecks", "SettingsWindowChecks", "PanelWindowChecks"}
NETWORK = {"SandboxNetworkChecks"}
@@ -72,7 +80,7 @@ def entitlements(app):
return value
def test_bundle(work, name, executable, host_entitlements=None):
def test_bundle(work, name, executable, host_entitlements=None, resources=None):
app = work / (name + ".app")
contents = app / "Contents"
(contents / "MacOS").mkdir(parents=True)
@@ -80,8 +88,10 @@ def test_bundle(work, name, executable, host_entitlements=None):
(contents / "Info.plist").write_bytes(plistlib.dumps({
"CFBundleIdentifier": "cn.airnan.kymo.checks." + uuid.uuid4().hex,
"CFBundleExecutable": name, "CFBundlePackageType": "APPL",
"LSUIElement": name in {"PanelWindowChecks", "SandboxNetworkChecks"},
"LSUIElement": name in {"PanelWindowChecks", "NativeMetricDrawingChecks", "NativeProcessTableChecks", "NetworkAddressChecks", "SandboxNetworkChecks"},
}))
if resources:
shutil.copytree(resources, contents / "Resources")
command = ["codesign", "--force", "--sign", "-"]
if host_entitlements:
path = work / "network.entitlements"
@@ -141,7 +151,7 @@ def main():
run(["swiftc", "-parse-as-library", "-module-cache-path", work / "cache", *CHECKS[name],
f"kymoTests/{name}.swift", "-o", executable])
if name in GUI:
bundle = test_bundle(work, name, executable)
bundle = test_bundle(work, name, executable, resources=app / "Contents/Resources" if name == "NativeProcessTableChecks" else None)
# Open the complete app for native activation semantics, while collecting its output.
output = work / (name + ".out")
error = work / (name + ".err")
@@ -162,7 +172,7 @@ def main():
print(text.strip(), flush=True)
if "PASS:" not in text:
raise RuntimeError(f"{name} did not report success\n" + (error.read_text() if error.exists() else ""))
elif name in NETWORK:
elif name in NETWORK or name == "NetworkAddressChecks":
bundle = test_bundle(work, name, executable, host_entitlements)
run([bundle / "Contents/MacOS" / name], timeout=15)
else: