mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-11-22 05:25:41 +00:00
Migrate SilentLaunchStore from its versioned JSON file to the app's standard defaults domain (key `silentLaunch`), the platform's canonical home for GUI-scalar preferences, so the GUI preference category stops growing one file per item. Reads stay safe-side strict: a missing key or a value not bridgeable to Bool loads as not silent (plain bool(forKey:) would coerce "yes" to true). The file-form persistence-failure naming path is dropped — UserDefaults.set reports no failure — so SilentLaunchController keeps its persist-then-flip seam while errorMessage and its SettingsView presentation go away. The legacy file never shipped in any release; migrateLegacyFileIfPresent runs in the production composition root only, preserves the value on developer machines, and deletes the file (no-op when absent). The test composition uses a dedicated suite cleared at assembly; unit tests use per-test suites with removePersistentDomain teardown, never the standard domain. ADR-0017 carries a dated amendment (Status plus the affected consequence line); the settings.json separation rationale stands unchanged.
25 lines
995 B
Swift
25 lines
995 B
Swift
import SwiftUI
|
|
|
|
/// 静默启动偏好(ADR 0017):启动时不呈现主窗口,直接以菜单栏形态后台运行。
|
|
/// 默认关;切换即持久化,当次会话无影响,下次启动生效。代理运行时恢复与
|
|
/// 登录项注册都不依赖它。持久化走 defaults 域而非 settings.json:代理控制器
|
|
/// 按内存快照整写该文件,旁路字段会被下一次整写覆盖。
|
|
@MainActor
|
|
final class SilentLaunchController: ObservableObject {
|
|
@Published private(set) var isEnabled: Bool
|
|
|
|
private let store: SilentLaunchStore
|
|
|
|
init(store: SilentLaunchStore) {
|
|
self.store = store
|
|
isEnabled = store.loadSilentLaunchEnabled()
|
|
}
|
|
|
|
/// 先落盘后翻转内存态:开关呈现不得与下次启动的实际行为脱节。UserDefaults
|
|
/// 无失败信号(cfprefsd 尽力而为),文件版的失败点名路径随迁移移除。
|
|
func setEnabled(_ enabled: Bool) {
|
|
store.save(silentLaunchEnabled: enabled)
|
|
isEnabled = enabled
|
|
}
|
|
}
|