Skip to content

Commit

Permalink
fix: unable to set updater
Browse files Browse the repository at this point in the history
  • Loading branch information
CanglongCl committed Jan 27, 2024
1 parent 47849ff commit 28c9c02
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions Easydict/NewApp/View/SettingView/Tabs/AboutTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -46,12 +46,7 @@ struct AboutTab: View {
}
}

private var autoChecksForUpdates: Binding<Bool> {
.init(
get: { Configuration.shared.automaticallyChecksForUpdates },
set: { newValue in Configuration.shared.automaticallyChecksForUpdates = newValue }
)
}
@StateObject private var checkUpdaterViewModel = CheckUpdaterViewModel()

@State
private var lastestVersion: String?
Expand All @@ -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, *)
Expand Down

0 comments on commit 28c9c02

Please sign in to comment.