From 28c9c02d8ef713fc2143334be02243190d7166cd Mon Sep 17 00:00:00 2001 From: Lava <34743145+CanglongCl@users.noreply.github.com> Date: Fri, 26 Jan 2024 20:06:58 -0800 Subject: [PATCH] fix: unable to set updater --- .../View/SettingView/Tabs/AboutTab.swift | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/Easydict/NewApp/View/SettingView/Tabs/AboutTab.swift b/Easydict/NewApp/View/SettingView/Tabs/AboutTab.swift index 54e1203dc..4c68ce1b0 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/AboutTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/AboutTab.swift @@ -21,7 +21,7 @@ struct AboutTab: View { .font(.system(size: 26, weight: .semibold)) Text("current_version") + Text(verbatim: " \(version)") .font(.system(size: 14)) - Toggle("auto_check_update", isOn: autoChecksForUpdates) + Toggle("auto_check_update", isOn: $checkUpdaterViewModel.autoChecksForUpdates) Text(verbatim: "(") + Text("lastest_version") + Text(verbatim: " \(lastestVersion ?? version))") HStack { @@ -46,12 +46,7 @@ struct AboutTab: View { } } - private var autoChecksForUpdates: Binding { - .init( - get: { Configuration.shared.automaticallyChecksForUpdates }, - set: { newValue in Configuration.shared.automaticallyChecksForUpdates = newValue } - ) - } + @StateObject private var checkUpdaterViewModel = CheckUpdaterViewModel() @State private var lastestVersion: String? @@ -62,6 +57,27 @@ struct AboutTab: View { private var version: String { Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "" } + + class CheckUpdaterViewModel: ObservableObject { + @Published var autoChecksForUpdates: Bool = false { + didSet { + GlobalContext + .shared + .updaterController + .updater + .automaticallyChecksForUpdates = autoChecksForUpdates + } + } + + init() { + GlobalContext + .shared + .updaterController + .updater + .publisher(for: \.automaticallyChecksForUpdates) + .assign(to: &$autoChecksForUpdates) + } + } } @available(macOS 13, *)