程序坞默认不再显示图标:主窗口开着也只在菜单栏运行,通用设置可打开“在程序坞显示图标”

This commit is contained in:
gentpan committed 2026-09-17 21:39:34 +05:00
1 parent 76e7427dfe
commit 33baa71470
11 files changed
+55 -29

No files matched your search

@@ -372,6 +372,7 @@ npm 缓存 npm Cache
圆环表示当前占用比例 A ring shows current usage
在 cleanip.io 查看这个 IP 的完整报告 Open this IP's full report on cleanip.io
在主窗口打开“{}” Open “{}” in the main window
在程序坞显示图标 Show Icon in Dock
在线升级 Online Updates
在线升级:发现新版本时显示更新摘要,一键安装并自动重启 Online updates: see what's new, install in one click and relaunch automatically
在菜单栏显示 Show in Menu Bar
@@ -1030,6 +1031,7 @@ npm 缓存 npm Cache
高负载 Heavy load
高负载时着色 Color High Load
高风险 High risk
默认只在菜单栏运行;打开后,主窗口开着时图标出现在程序坞与 ⌘Tab 中 OpenStats lives in the menu bar by default. Turn this on to show its icon in the Dock and ⌘Tab while the main window is open
({}) ({})
, ,
,{} 项未能移动 , {} couldn't be moved
@@ -159,10 +159,10 @@ public final class AppController: NSObject, NSApplicationDelegate {
updateTimer?.tolerance = 5 * 60
}
/// 有窗口打开时显示在程序坞与 ⌘Tab 里,全部关闭后回到仅菜单栏
/// 默认只在菜单栏运行、不占程序坞;打开了“在程序坞显示图标”时,有窗口开着才出现在程序坞与 ⌘Tab 里
private func updateActivationPolicy() {
let hasWindow = mainWindow.isVisible
let policy: NSApplication.ActivationPolicy = hasWindow ? .regular : .accessory
let policy: NSApplication.ActivationPolicy = hasWindow && model.settings.showDockIcon ? .regular : .accessory
guard NSApp.activationPolicy() != policy else { return }
NSApp.setActivationPolicy(policy)
if hasWindow { NSApp.activate() }
@@ -186,6 +186,7 @@ public final class AppController: NSObject, NSApplicationDelegate {
_ = model.settings.expandedPopoverSections
_ = model.keepAwake.isActive
_ = model.settings.appearance
_ = model.settings.showDockIcon
_ = model.isNetworkDetailVisible
_ = model.settings.probeEnabled
_ = model.settings.probeInBackground
@@ -199,6 +200,7 @@ public final class AppController: NSObject, NSApplicationDelegate {
await self.model.hub.update(self.model.demand)
self.model.bluetooth.setDemand(self.model.bluetoothDemand)
self.applyAppearance()
self.updateActivationPolicy()
self.menuBar.update()
self.menuBar.refreshPopoverHeight()
self.updateNetworkVisibility()
@@ -1,7 +1,7 @@
import AppKit
import SwiftUI
/// 主窗口。打开时应用出现在程序坞与 ⌘Tab 中,关闭后回到仅菜单栏运行
/// 主窗口。应用默认只在菜单栏运行,窗口开着也不占程序坞;设置里打开“在程序坞显示图标”后才出现在程序坞与 ⌘Tab 中
@MainActor
final class MainWindowController: NSObject, NSWindowDelegate {
private let model: AppModel
@@ -73,6 +73,11 @@ struct GeneralSettings: View {
label: tr("登录时启动"))
}
}
GroupRow {
SettingRow(title: tr("在程序坞显示图标"), subtitle: tr("默认只在菜单栏运行;打开后,主窗口开着时图标出现在程序坞与 ⌘Tab 中")) {
DSToggle(isOn: $settings.showDockIcon, label: tr("在程序坞显示图标"))
}
}
GroupRow {
SettingRow(title: tr("刷新频率"), subtitle: tr("只显示菜单栏时的采样间隔;打开弹窗或主窗口时为 1 秒(进程页 2 秒)")) {
SegmentedControl(selection: $settings.refreshSeconds,
@@ -421,6 +421,10 @@ public final class AppSettings {
public var appearance: AppearanceMode {
didSet { defaults.set(appearance.rawValue, forKey: Keys.appearance) }
}
/// 主窗口开着时在程序坞与 ⌘Tab 中显示图标;默认关闭,和其他菜单栏工具一样只在菜单栏运行
public var showDockIcon: Bool {
didSet { defaults.set(showDockIcon, forKey: Keys.showDockIcon) }
}
public var menuBarLayout: MenuBarLayout {
didSet { defaults.set(menuBarLayout.rawValue, forKey: Keys.menuBarLayout) }
}
@@ -520,6 +524,7 @@ public final class AppSettings {
? defaults.integer(forKey: Keys.fanSafetyTemperature) : 95
panelTab = defaults.string(forKey: Keys.panelTab).flatMap(PanelTab.init(rawValue:)) ?? .overview
appearance = defaults.string(forKey: Keys.appearance).flatMap(AppearanceMode.init(rawValue:)) ?? .system
showDockIcon = defaults.bool(forKey: Keys.showDockIcon)
cleanPrefersTrash = defaults.bool(forKey: Keys.cleanPrefersTrash)
menuBarLayout = defaults.string(forKey: Keys.menuBarLayout).flatMap(MenuBarLayout.init(rawValue:)) ?? .separate
expandedPopoverSections = Set((defaults.stringArray(forKey: Keys.expandedPopoverSections) ?? []).compactMap(PopoverSection.init(rawValue:)))
@@ -590,6 +595,7 @@ public final class AppSettings {
static let fanSafetyTemperature = "fanSafetyTemperature"
static let panelTab = "panelTab"
static let appearance = "appearance"
static let showDockIcon = "showDockIcon"
static let cleanPrefersTrash = "cleanPrefersTrash"
static let menuBarLayout = "menuBarLayout"
static let hiddenPopoverSections = "hiddenPopoverSections"
@@ -17,6 +17,7 @@ public struct SettingsDocument: Codable, Equatable, Sendable {
public var lidModeBatteryFloor: Int?
public var fanSafetyTemperature: Int?
public var appearance: String?
public var showDockIcon: Bool?
public var menuBarLayout: String?
public var hiddenPopoverSections: [String]?
public var probeEnabled: Bool?
@@ -50,6 +51,7 @@ extension AppSettings {
doc.lidModeBatteryFloor = lidModeBatteryFloor
doc.fanSafetyTemperature = fanSafetyTemperature
doc.appearance = appearance.rawValue
doc.showDockIcon = showDockIcon
doc.menuBarLayout = menuBarLayout.rawValue
doc.hiddenPopoverSections = hiddenPopoverSections.map(\.rawValue).sorted()
doc.probeEnabled = probeEnabled
@@ -93,6 +95,7 @@ extension AppSettings {
assign(\.lidModeBatteryFloor, option(doc.lidModeBatteryFloor, in: Self.batteryFloorOptions))
assign(\.fanSafetyTemperature, option(doc.fanSafetyTemperature, in: Self.fanSafetyOptions))
assign(\.appearance, doc.appearance.flatMap(AppearanceMode.init(rawValue:)))
assign(\.showDockIcon, doc.showDockIcon)
assign(\.menuBarLayout, doc.menuBarLayout.flatMap(MenuBarLayout.init(rawValue:)))
assign(\.hiddenPopoverSections, doc.hiddenPopoverSections.map { Set($0.compactMap(PopoverSection.init(rawValue:))) })
assign(\.probeEnabled, doc.probeEnabled)