From 3dff50f6a81dfe9e0166a7d1bd4efcc03a2e244d Mon Sep 17 00:00:00 2001 From: Jerry Zhang Date: Sat, 9 Mar 2024 21:31:23 -0800 Subject: [PATCH] Migrate Automatically Check for Updates toggle from About tab to General 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 --- Easydict/App/Localizable.xcstrings | 66 ++++++++++++++++++- .../View/SettingView/Tabs/AboutTab.swift | 34 ---------- .../View/SettingView/Tabs/AdvancedTab.swift | 1 + .../View/SettingView/Tabs/GeneralTab.swift | 47 +++++++++++++ 4 files changed, 113 insertions(+), 35 deletions(-) diff --git a/Easydict/App/Localizable.xcstrings b/Easydict/App/Localizable.xcstrings index 57b1ffa4e..b7f0ca931 100644 --- a/Easydict/App/Localizable.xcstrings +++ b/Easydict/App/Localizable.xcstrings @@ -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" : { @@ -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" : { @@ -1712,6 +1760,22 @@ } } }, + "lastest_version %@" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Latest version %@" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "最新版本 %@" + } + } + } + }, "launch" : { "localizations" : { "en" : { diff --git a/Easydict/NewApp/View/SettingView/Tabs/AboutTab.swift b/Easydict/NewApp/View/SettingView/Tabs/AboutTab.swift index 6a123a935..f761cf664 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/AboutTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/AboutTab.swift @@ -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) { @@ -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") @@ -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 ?? "" } diff --git a/Easydict/NewApp/View/SettingView/Tabs/AdvancedTab.swift b/Easydict/NewApp/View/SettingView/Tabs/AdvancedTab.swift index 34e6c964b..c53648b10 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/AdvancedTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/AdvancedTab.swift @@ -26,6 +26,7 @@ struct AdvancedTab: View { Toggle(isOn: $enableBetaNewApp) { Text("enable_beta_new_app") } + } header: { Text("setting.general.advance.header") } diff --git a/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift b/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift index 699101f5d..1a1554198 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift @@ -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 { @@ -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") } @@ -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 @@ -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 }