Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Automatically Check for Updates toggle from About tab to General Tab #444

Merged
merged 5 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 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 " : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Automatically check for app updates"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "自动检查应用程序更新"
tisfeng marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
},
"auto_copy_first_translated_text" : {
"localizations" : {
"en" : {
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