Skip to content

Commit

Permalink
补齐添加更多菜单项
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Dec 28, 2023
1 parent 0b45d00 commit 000292c
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 5 deletions.
29 changes: 28 additions & 1 deletion Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,16 @@
}
}
},
"check_updates" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "检查更新"
}
}
}
},
"chinese_phonetic" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -1945,6 +1955,16 @@
}
}
},
"quit" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "退出"
}
}
}
},
"replace_text" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -2059,7 +2079,14 @@
}
},
"Settings..." : {

"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "设置..."
}
}
}
},
"shortcut_select_translate_window_type" : {
"localizations" : {
Expand Down
71 changes: 67 additions & 4 deletions Easydict/NewApp/View/MenuItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,90 @@
// Copyright © 2023 izual. All rights reserved.
//

import Sparkle
import SwiftUI

@available(macOS 13, *)
struct MenuItemView: View {
var body: some View {
settingItem
Group {
versionItem
Divider()
settingItem
.keyboardShortcut(.init(","))
checkUpdateItem
Divider()
quitItem
.keyboardShortcut(.init("q"))
}
.task {
let version = await EZMenuItemManager.shared().fetchRepoLatestVersion(EZGithubRepoEasydict)
await MainActor.run {
latestVersion = version
}
}
}

@State
private var currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""

@State
private var latestVersion: String?

@Environment(\.openURL)
private var openURL

@ViewBuilder
private var versionItem: some View {
Button(versionString) {
guard let versionURL = URL(string: "\(EZGithubRepoEasydictURL)/releases") else {
return
}
openURL(versionURL)
}
}

private var versionString: String {
let defaultLabel = "Easydict \(currentVersion)"
if let latestVersion,
currentVersion.compare(latestVersion, options: .numeric) == .orderedAscending
{
return defaultLabel + " (✨ \(latestVersion)"
} else {
return defaultLabel
}
}

@ViewBuilder
private var settingItem: some View {
if #available(macOS 14.0, *) {
SettingsLink()
} else {
Button {
Button("Settings...") {
NSLog("打开设置")
NSApplication.shared.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
} label: {
Text("Settings...")
}
}
}

@ViewBuilder
private var checkUpdateItem: some View {
Button("check_updates") {
NSLog("检查更新")
SPUStandardUpdaterController(updaterDelegate: nil, userDriverDelegate: nil).checkForUpdates(nil)
}
}

@ViewBuilder
private var quitItem: some View {
Button("quit") {
NSLog("退出应用")
NSApplication.shared.terminate(nil)
}
}
}

@available(macOS 13, *)
#Preview {
MenuItemView()
}

0 comments on commit 000292c

Please sign in to comment.