Skip to content

Commit

Permalink
Merge branch 'feautre_tips_view' of github.com:AkaShark/Easydict into…
Browse files Browse the repository at this point in the history
… feautre_tips_view
  • Loading branch information
AkaShark committed Feb 22, 2024
2 parents d592723 + a582f58 commit f56785c
Show file tree
Hide file tree
Showing 21 changed files with 102 additions and 74 deletions.
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.9
4 changes: 4 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md

# file options
--exclude Pods
2 changes: 1 addition & 1 deletion Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2687,7 +2687,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\nif [ \"${ENABLE_PREVIEWS}\" = \"YES\" ]; then\n echo \"SwiftFormat skipped for Xcode Previews.\"\n exit 0;\nfi\n\"${PODS_ROOT}/SwiftFormat/CommandLineTool/swiftformat\" \"$SRCROOT/$TARGET_NAME\" --swiftversion 5.7\n";
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\nif [ \"${ENABLE_PREVIEWS}\" = \"YES\" ]; then\n echo \"SwiftFormat skipped for Xcode Previews.\"\n exit 0;\nfi\n\"${PODS_ROOT}/SwiftFormat/CommandLineTool/swiftformat\" \"$SRCROOT/$TARGET_NAME\"\n";
};
124D690EE7236D6430CF945E /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
18 changes: 17 additions & 1 deletion Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,22 @@
}
}
},
"menu_feedback" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Feedback"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "反馈"
}
}
}
},
"menu_input_translate" : {
"extractionState" : "manual",
"localizations" : {
Expand Down Expand Up @@ -3357,7 +3373,7 @@
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "划词内容为空时"
"value" : "禁用空复制提示音"
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions Easydict/Feature/Configuration/Appearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ import Foundation
var title: String {
switch self {
case .followSystem:
return NSLocalizedString("appearenceType_followSystem", comment: "")
NSLocalizedString("appearenceType_followSystem", comment: "")
case .light:
return NSLocalizedString("appearenceType_light", comment: "")
NSLocalizedString("appearenceType_light", comment: "")
case .dark:
return NSLocalizedString("appearenceType_dark", comment: "")
NSLocalizedString("appearenceType_dark", comment: "")
}
}

var appearence: NSAppearance? {
switch self {
case .followSystem:
return nil
nil
case .light:
return NSAppearance(named: .aqua)
NSAppearance(named: .aqua)
case .dark:
return NSAppearance(named: .darkAqua)
NSAppearance(named: .darkAqua)
}
}

Expand Down
4 changes: 2 additions & 2 deletions Easydict/Feature/Service/Ali/AliResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ enum AnyCodable: Codable {
var stringValue: String? {
switch self {
case let .int(i):
return String(i)
String(i)
case let .string(s):
return s
s
}
}
}
26 changes: 13 additions & 13 deletions Easydict/Feature/Service/Ali/AliService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class AliService: QueryService {

private var hasToken: (has: Bool, token: String, parameterName: String) {
if let token = tokenResponse?.token, let parameterName = tokenResponse?.parameterName, !token.isEmpty, !parameterName.isEmpty {
return (true, token, parameterName)
(true, token, parameterName)
} else {
return (false, "", "")
(false, "", "")
}
}

Expand All @@ -46,7 +46,7 @@ class AliService: QueryService {
override public func supportLanguagesDictionary() -> MMOrderedDictionary<AnyObject, AnyObject> {
// TODO: Replace MMOrderedDictionary in the API
let orderedDict = MMOrderedDictionary<AnyObject, AnyObject>()
AliTranslateType.supportLanguagesDictionary.forEach { key, value in
for (key, value) in AliTranslateType.supportLanguagesDictionary {
orderedDict.setObject(value as NSString, forKey: key.rawValue as NSString)
}
return orderedDict
Expand Down Expand Up @@ -102,12 +102,12 @@ class AliService: QueryService {
guard let self else { return }
switch response.result {
case let .success(value):
self.tokenResponse = value
tokenResponse = value
case let .failure(error):
print("ali translate get token error: \(error)")
}

self.requestByWeb(transType: transType, text: text, from: from, to: to, completion: completion)
requestByWeb(transType: transType, text: text, from: from, to: to, completion: completion)
}

queryModel.setStop({
Expand Down Expand Up @@ -194,7 +194,7 @@ class AliService: QueryService {
.validate()
.responseDecodable(of: AliAPIResponse.self) { [weak self] response in
guard let self else { return }
let result = self.result
let result = result

switch response.result {
case let .success(value):
Expand Down Expand Up @@ -247,7 +247,7 @@ class AliService: QueryService {
.validate()
.responseDecodable(of: AliWebResponse.self) { [weak self] response in
guard let self else { return }
let result = self.result
let result = result

switch response.result {
case let .success(value):
Expand All @@ -262,18 +262,18 @@ class AliService: QueryService {
let ezError = EZError(type: .API, description: value.code?.stringValue, errorDataMessage: value.message)
completion(result, ezError)
}
self.canWebRetry = true
canWebRetry = true
case let .failure(error):
// The result returned when the token expires is HTML.
if hasToken.has, error.isResponseSerializationError {
print("ali web token invaild")
self.tokenResponse = nil
if self.canWebRetry {
self.canWebRetry = false
tokenResponse = nil
if canWebRetry {
canWebRetry = false
// Request token again.
self.translate(text, from: from, to: to, completion: completion)
translate(text, from: from, to: to, completion: completion)
} else {
self.requestByWeb(transType: transType, text: text, from: from, to: to, completion: completion)
requestByWeb(transType: transType, text: text, from: from, to: to, completion: completion)
}

} else {
Expand Down
4 changes: 2 additions & 2 deletions Easydict/Feature/Service/Caiyun/CaiyunService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class CaiyunService: QueryService {
override public func supportLanguagesDictionary() -> MMOrderedDictionary<AnyObject, AnyObject> {
// TODO: Replace MMOrderedDictionary.
let orderedDict = MMOrderedDictionary<AnyObject, AnyObject>()
CaiyunTranslateType.supportLanguagesDictionary.forEach { key, value in
for (key, value) in CaiyunTranslateType.supportLanguagesDictionary {
orderedDict.setObject(value as NSString, forKey: key.rawValue as NSString)
}
return orderedDict
Expand Down Expand Up @@ -92,7 +92,7 @@ public final class CaiyunService: QueryService {
.validate()
.responseDecodable(of: CaiyunResponse.self) { [weak self] response in
guard let self else { return }
let result = self.result
let result = result

switch response.result {
case let .success(value):
Expand Down
4 changes: 2 additions & 2 deletions Easydict/Feature/Service/Tencent/TencentService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class TencentService: QueryService {
override public func supportLanguagesDictionary() -> MMOrderedDictionary<AnyObject, AnyObject> {
// TODO: Replace MMOrderedDictionary in the API
let orderedDict = MMOrderedDictionary<AnyObject, AnyObject>()
TencentTranslateType.supportLanguagesDictionary.forEach { key, value in
for (key, value) in TencentTranslateType.supportLanguagesDictionary {
orderedDict.setObject(value as NSString, forKey: key.rawValue as NSString)
}
return orderedDict
Expand Down Expand Up @@ -116,7 +116,7 @@ public final class TencentService: QueryService {
.validate()
.responseDecodable(of: TencentResponse.self) { [weak self] response in
guard let self else { return }
let result = self.result
let result = result

switch response.result {
case let .success(value):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ import Hue
setupUI()

NotificationCenter.default.addObserver(forName: .init(Self.changeFontSizeNotificationName), object: nil, queue: .main) { [weak self] noti in
guard let self, let index = noti.object as? Int, index != self.selectedIndex else { return }
self.selectedIndex = index
self.updateSelectedLineFrame()
guard let self, let index = noti.object as? Int, index != selectedIndex else { return }
selectedIndex = index
updateSelectedLineFrame()
}
}

Expand Down Expand Up @@ -78,7 +78,7 @@ import Hue
stackView.heightAnchor.constraint(equalToConstant: scaleLineHeight),
])

scaleLines.enumerated().forEach { _, view in
for (_, view) in scaleLines.enumerated() {
view.layer?.cornerRadius = scaleLineWidth / 2
view.layer?.backgroundColor = scaleLineColor.cgColor

Expand Down
4 changes: 2 additions & 2 deletions Easydict/NewApp/Feature/Shortcut/Shortcut.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ struct KeyboardShortcut: ViewModifier {

private func fetchShortcutKeyEquivalent(_ keyCombo: KeyCombo) -> KeyEquivalent {
if keyCombo.doubledModifiers {
return KeyEquivalent(Character(keyCombo.keyEquivalentModifierMaskString))
KeyEquivalent(Character(keyCombo.keyEquivalentModifierMaskString))
} else {
return KeyEquivalent(Character(keyCombo.keyEquivalent))
KeyEquivalent(Character(keyCombo.keyEquivalent))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ extension DeepLAPIUsagePriority: EnumLocalizedStringConvertible {
var title: String {
switch self {
case .webFirst:
return NSLocalizedString("service.configuration.deepl.web_first.title", bundle: .main, comment: "")
NSLocalizedString("service.configuration.deepl.web_first.title", bundle: .main, comment: "")
case .authKeyFirst:
return NSLocalizedString("service.configuration.deepl.authkey_first.title", bundle: .main, comment: "")
NSLocalizedString("service.configuration.deepl.authkey_first.title", bundle: .main, comment: "")
case .authKeyOnly:
return NSLocalizedString("service.configuration.deepl.authkey_only.title", bundle: .main, comment: "")
NSLocalizedString("service.configuration.deepl.authkey_only.title", bundle: .main, comment: "")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ extension OpenAIUsageStats: EnumLocalizedStringConvertible {
var title: String {
switch self {
case .default:
return NSLocalizedString(
NSLocalizedString(
"service.configuration.openai.usage_status_default.title",
bundle: .main,
comment: ""
)
case .alwaysOff:
return NSLocalizedString(
NSLocalizedString(
"service.configuration.openai.usage_status_always_off.title",
bundle: .main,
comment: ""
)
case .alwaysOn:
return NSLocalizedString(
NSLocalizedString(
"service.configuration.openai.usage_status_always_on.title",
bundle: .main,
comment: ""
Expand Down
10 changes: 10 additions & 0 deletions Easydict/NewApp/View/MenuView/MainMenuCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@
import SwiftUI

struct EasyDictMainMenu: Commands {
@Environment(\.openURL)
private var openURL

var body: some Commands {
// shortcut
MainMenuShortcutCommand()

// Help
CommandGroup(replacing: CommandGroupPlacement.help, addition: {
Button("menu_feedback") {
openURL(URL(string: "\(EZGithubRepoEasydictURL)/issues")!)
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,48 +86,47 @@ extension KeyHolderWrapper {
}

func restoreKeyCombo(_ recordView: RecordView) {
var keyCombo: KeyCombo?
switch type {
let keyCombo: KeyCombo? = switch type {
case .inputTranslate:
keyCombo = Defaults[.inputShortcut]
Defaults[.inputShortcut]
case .snipTranslate:
keyCombo = Defaults[.snipShortcut]
Defaults[.snipShortcut]
case .selectTranslate:
keyCombo = Defaults[.selectionShortcut]
Defaults[.selectionShortcut]
case .silentScreenshotOcr:
keyCombo = Defaults[.screenshotOCRShortcut]
Defaults[.screenshotOCRShortcut]
case .showMiniWindow:
keyCombo = Defaults[.showMiniWindowShortcut]
Defaults[.showMiniWindowShortcut]
case .clearInput:
keyCombo = Defaults[.clearInputShortcut]
Defaults[.clearInputShortcut]
case .clearAll:
keyCombo = Defaults[.clearAllShortcut]
Defaults[.clearAllShortcut]
case .copy:
keyCombo = Defaults[.copyShortcut]
Defaults[.copyShortcut]
case .copyFirstResult:
keyCombo = Defaults[.copyFirstResultShortcut]
Defaults[.copyFirstResultShortcut]
case .focus:
keyCombo = Defaults[.focusShortcut]
Defaults[.focusShortcut]
case .play:
keyCombo = Defaults[.playShortcut]
Defaults[.playShortcut]
case .retry:
keyCombo = Defaults[.retryShortcut]
Defaults[.retryShortcut]
case .toggle:
keyCombo = Defaults[.toggleShortcut]
Defaults[.toggleShortcut]
case .pin:
keyCombo = Defaults[.pinShortcut]
Defaults[.pinShortcut]
case .hide:
keyCombo = Defaults[.hideShortcut]
Defaults[.hideShortcut]
case .increaseFontSize:
keyCombo = Defaults[.increaseFontSize]
Defaults[.increaseFontSize]
case .decreaseFontSize:
keyCombo = Defaults[.decreaseFontSize]
Defaults[.decreaseFontSize]
case .google:
keyCombo = Defaults[.googleShortcut]
Defaults[.googleShortcut]
case .eudic:
keyCombo = Defaults[.eudicShortcut]
Defaults[.eudicShortcut]
case .appleDic:
keyCombo = Defaults[.appleDictionaryShortcut]
Defaults[.appleDictionaryShortcut]
}
recordView.keyCombo = keyCombo
Shortcut.shared.bindingShortcut(keyCombo: keyCombo, type: type)
Expand Down
4 changes: 1 addition & 3 deletions EasydictSwiftTests/EasydictSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import XCTest

final class EasydictSwiftTests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
Expand All @@ -25,7 +24,7 @@ final class EasydictSwiftTests: XCTestCase {
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}

func testAES() {
let text = "123"
let encryptedText = text.encryptAES()
Expand All @@ -39,5 +38,4 @@ final class EasydictSwiftTests: XCTestCase {
// Put the code you want to measure the time of here.
}
}

}
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ target 'Easydict' do
pod 'JLRoutes', '~> 2.1'

# Swift format
pod 'SwiftFormat/CLI', '~> 0.52.11'
pod 'SwiftFormat/CLI', '~> 0.53.2'

end

Expand Down
Loading

0 comments on commit f56785c

Please sign in to comment.