Skip to content

Commit

Permalink
Migrate Automatically Check for Updates toggle from About tab to Gene…
Browse files Browse the repository at this point in the history
…ral Tab (#444)

* perf(UI): migrate auto check for updates to advanced tab

* perf(UI): add check for updates in general tab

* perf(UI): refine display strings for check for updates

* perf(UI): unify translations for check_for_update

---------

Co-authored-by: Tisfeng <tisfeng@gmail.com>
  • Loading branch information
Jerry23011 and tisfeng authored Mar 10, 2024
1 parent 838b1d3 commit 3dff50f
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 35 deletions.
66 changes: 65 additions & 1 deletion Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,23 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Automatically check for App updates"
"value" : "Automatically check for app updates"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "自动检查应用更新"
}
}
}
},
"auto_check_update " : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Automatically check for app updates"
}
},
"zh-Hans" : {
Expand Down Expand Up @@ -636,6 +652,38 @@
}
}
},
"check_for_updates" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Check for updates"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "检查更新"
}
}
}
},
"check_now" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Check Now"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "立即检查"
}
}
}
},
"check_updates" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -1712,6 +1760,22 @@
}
}
},
"lastest_version %@" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Latest version %@"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "最新版本 %@"
}
}
}
},
"launch" : {
"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
1 change: 1 addition & 0 deletions Easydict/NewApp/View/SettingView/Tabs/AdvancedTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct AdvancedTab: View {
Toggle(isOn: $enableBetaNewApp) {
Text("enable_beta_new_app")
}

} header: {
Text("setting.general.advance.header")
}
Expand Down
47 changes: 47 additions & 0 deletions Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ struct GeneralTab: View {

@Environment(\.colorScheme) var colorScheme

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 Down Expand Up @@ -150,6 +172,17 @@ struct GeneralTab: View {
}

Section {
LabeledContent {
Button("check_now") {
Configuration.shared.updater.checkForUpdates()
}
} label: {
Text("check_for_updates")
Text("lastest_version \(lastestVersion ?? version)")
}
Toggle(isOn: $checkUpdaterViewModel.autoChecksForUpdates) {
Text("auto_check_update ")
}
Toggle(isOn: $launchAtStartup) {
Text("launch_at_startup")
}
Expand Down Expand Up @@ -184,6 +217,12 @@ struct GeneralTab: View {
}
}
.formStyle(.grouped)
.task {
let version = await EZMenuItemManager.shared().fetchRepoLatestVersion(EZGithubRepoEasydict)
await MainActor.run {
lastestVersion = version
}
}
.alert("hide_menu_bar_icon", isPresented: $showRefuseAlert) {
Button("ok") {
showRefuseAlert = false
Expand Down Expand Up @@ -254,6 +293,14 @@ struct GeneralTab: View {
@State private var showRefuseAlert = false
@State private var showHideMenuBarIconAlert = false

@StateObject private var checkUpdaterViewModel = CheckUpdaterViewModel()

@State private var lastestVersion: String?

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

private var shortcutsHaveSetuped: Bool {
Defaults[.inputShortcut] != nil || Defaults[.selectionShortcut] != nil
}
Expand Down

0 comments on commit 3dff50f

Please sign in to comment.