Skip to content

Commit

Permalink
perf(UI): migrate auto check for updates to advanced tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry23011 committed Mar 6, 2024
1 parent 1c97870 commit 938853a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 34 deletions.
16 changes: 16 additions & 0 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,22 @@
}
}
},
"auto_check_update (lastest_version %@)" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Automatically check for application updates (Latest version %@)"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "自动检查应用程序更新(最新版本 %@)"
}
}
}
},
"auto_copy_first_translated_text" : {
"localizations" : {
"en" : {
Expand Down
34 changes: 0 additions & 34 deletions Easydict/NewApp/View/SettingView/Tabs/AboutTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,6 @@ import SwiftUI
struct AboutTab: View {
// MARK: Internal

class CheckUpdaterViewModel: ObservableObject {
// MARK: Lifecycle

init() {
updater
.publisher(for: \.automaticallyChecksForUpdates)
.assign(to: &$autoChecksForUpdates)
}

// MARK: Internal

@Published var autoChecksForUpdates = true {
didSet {
updater.automaticallyChecksForUpdates = autoChecksForUpdates
}
}

// MARK: Private

private let updater = Configuration.shared.updater
}

var body: some View {
ScrollView {
VStack(spacing: 15) {
Expand All @@ -45,8 +23,6 @@ struct AboutTab: View {
.font(.system(size: 26, weight: .semibold))
Text("current_version") + Text(verbatim: " \(version)")
.font(.system(size: 14))
Toggle("auto_check_update", isOn: $checkUpdaterViewModel.autoChecksForUpdates)
Text(verbatim: "(") + Text("lastest_version") + Text(verbatim: " \(lastestVersion ?? version))")

HStack {
Text("author")
Expand All @@ -62,20 +38,10 @@ struct AboutTab: View {
.frame(maxWidth: .infinity)
}
.scrollIndicators(.hidden)
.task {
let version = await EZMenuItemManager.shared().fetchRepoLatestVersion(EZGithubRepoEasydict)
await MainActor.run {
lastestVersion = version
}
}
}

// MARK: Private

@StateObject private var checkUpdaterViewModel = CheckUpdaterViewModel()

@State private var lastestVersion: String?

private var appName: String {
Bundle.main.infoDictionary?["CFBundleName"] as? String ?? ""
}
Expand Down
41 changes: 41 additions & 0 deletions Easydict/NewApp/View/SettingView/Tabs/AdvancedTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@ import SwiftUI
struct AdvancedTab: View {
// MARK: Internal

class CheckUpdaterViewModel: ObservableObject {
// MARK: Lifecycle

init() {
updater
.publisher(for: \.automaticallyChecksForUpdates)
.assign(to: &$autoChecksForUpdates)
}

// MARK: Internal

@Published var autoChecksForUpdates = true {
didSet {
updater.automaticallyChecksForUpdates = autoChecksForUpdates
}
}

// MARK: Private

private let updater = Configuration.shared.updater
}

var body: some View {
Form {
Section {
Expand All @@ -26,18 +48,37 @@ struct AdvancedTab: View {
Toggle(isOn: $enableBetaNewApp) {
Text("enable_beta_new_app")
}

Toggle(isOn: $checkUpdaterViewModel.autoChecksForUpdates) {
Text("auto_check_update (lastest_version \(lastestVersion ?? version))")
}

} header: {
Text("setting.general.advance.header")
}
}
.formStyle(.grouped)
.task {
let version = await EZMenuItemManager.shared().fetchRepoLatestVersion(EZGithubRepoEasydict)
await MainActor.run {
lastestVersion = version
}
}
}

// MARK: Private

@Default(.defaultTTSServiceType) private var defaultTTSServiceType
@Default(.enableBetaFeature) private var enableBetaFeature
@Default(.enableBetaNewApp) private var enableBetaNewApp

@StateObject private var checkUpdaterViewModel = CheckUpdaterViewModel()

@State private var lastestVersion: String?

private var version: String {
Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
}
}

@available(macOS 13, *)
Expand Down

0 comments on commit 938853a

Please sign in to comment.