Skip to content

Commit

Permalink
perf(UI): add check for updates in general tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry23011 committed Mar 9, 2024
1 parent 5ec1703 commit afd16f4
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 49 deletions.
42 changes: 33 additions & 9 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
}
}
},
"(lastest_version %@)" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "(最新版本 %@)"
}
}
}
},
"about" : {
"comment" : "about",
"localizations" : {
Expand Down Expand Up @@ -309,18 +319,12 @@
}
}
},
"auto_check_update (lastest_version %@)" : {
"auto_check_update " : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Automatically check for application updates (Latest version %@)"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "自动检查应用程序更新(最新版本 %@)"
"state" : "translated",
"value" : "自动检查应用程序更新"
}
}
}
Expand Down Expand Up @@ -652,6 +656,26 @@
}
}
},
"check_for_updates" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "检查更新"
}
}
}
},
"check_now" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "立即检查"
}
}
}
},
"check_updates" : {
"localizations" : {
"en" : {
Expand Down
40 changes: 0 additions & 40 deletions Easydict/NewApp/View/SettingView/Tabs/AdvancedTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,6 @@ 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 @@ -49,36 +27,18 @@ struct AdvancedTab: View {
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
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 afd16f4

Please sign in to comment.