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

translation service api key config #379

Merged
merged 41 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
126ecb6
feat: add tencent service config
phlpsong Jan 28, 2024
2e20515
feat: add niuTrans api key config
phlpsong Jan 28, 2024
9f467c8
feat: add caiyun token config
phlpsong Jan 28, 2024
37a64c2
feat: update service config view
phlpsong Jan 29, 2024
0201676
feat: update service localized strings
phlpsong Jan 29, 2024
438b9d5
feat: update config view
phlpsong Jan 29, 2024
59446b7
feat: update validation disable according to input
phlpsong Jan 30, 2024
fd402f4
feat: update some localized string keys
phlpsong Jan 30, 2024
009df05
feat: update openAI config
phlpsong Jan 30, 2024
db4cc13
feat: add bing and deepL config
phlpsong Jan 30, 2024
4e4c9ca
fix: update view structure and fix reload issue
phlpsong Jan 31, 2024
1d9e8bb
fix: remove unused code
phlpsong Jan 31, 2024
2ab02b8
fix: remove unused code
phlpsong Jan 31, 2024
0540f46
feat: add deepL api priority config
phlpsong Jan 31, 2024
9a11fa8
feat: add gemini key config
phlpsong Jan 31, 2024
ad4b861
Merge branch 'dev' into service_api_key_config
phlpsong Jan 31, 2024
4fd55ee
Merge branch 'dev' into service_api_key_config
tisfeng Feb 1, 2024
8c567c5
perf: adjust settings page window size
tisfeng Feb 1, 2024
87f5cc0
Update Easydict/App/Localizable.xcstrings
phlpsong Feb 1, 2024
3b41f86
Update Easydict/App/Localizable.xcstrings
phlpsong Feb 1, 2024
1109f1f
Update Easydict/App/Localizable.xcstrings
phlpsong Feb 1, 2024
9579b3e
fix: remove openai domain config
phlpsong Feb 1, 2024
586b8ca
Merge branch 'dev' into service_api_key_config
phlpsong Feb 2, 2024
4d14744
fix: toggle configuration reset after switch tab issue
phlpsong Feb 2, 2024
8b1652c
Update Easydict/App/Localizable.xcstrings
phlpsong Feb 3, 2024
633ab52
fix: change OpenAI UsageStatus option
phlpsong Feb 3, 2024
97d933e
Merge branch 'service_api_key_config' of https://github.com/phlpsong/…
phlpsong Feb 3, 2024
cf22a27
fix: update OpenAI models
phlpsong Feb 3, 2024
91b216d
fix: validation warning
phlpsong Feb 3, 2024
2f88560
Merge branch 'dev' into service_api_key_config
phlpsong Feb 3, 2024
9d0ca65
Merge branch 'dev' into service_api_key_config
phlpsong Feb 4, 2024
0a3b126
Merge branch 'dev' into service_api_key_config
phlpsong Feb 4, 2024
dbf9177
Merge branch 'dev' into service_api_key_config
tisfeng Feb 4, 2024
5333ac2
fix: `Publishing changes from within view updates is not allowed, thi…
CanglongCl Feb 5, 2024
d5bf0a1
fix: picker selection issue
phlpsong Feb 5, 2024
423e570
fix: remove unused code
phlpsong Feb 5, 2024
8d7d091
fix: optimize defaults with picker cell
phlpsong Feb 5, 2024
334ef7a
Update Easydict/NewApp/Configuration/Configuration+Defaults.swift
tisfeng Feb 5, 2024
b73a2a6
Update Easydict/NewApp/Configuration/Configuration+Defaults.swift
tisfeng Feb 5, 2024
6ff4806
Update Easydict/NewApp/Configuration/Configuration+Defaults.swift
tisfeng Feb 5, 2024
293180b
Update Easydict/NewApp/Configuration/Configuration+Defaults.swift
tisfeng Feb 5, 2024
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
2 changes: 1 addition & 1 deletion Easydict/NewApp/Configuration/Configuration+Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ extension Defaults.Keys {

// DEEPL
static let deepLAuth = Key<String?>("EZDeepLAuthKey")
static let deepLTranslation = Key<String>("EZDeepLTranslationAPIKey", default: DeepLAPIUsagePriority.webFirst.rawValue)
static let deepLTranslation = Key<DeepLAPIUsagePriority>("EZDeepLTranslationAPIKey", default: DeepLAPIUsagePriority.webFirst)
static let deepLTranslateEndPointKey = Key<String?>("EZDeepLTranslateEndPointKey")

// BING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2024 izual. All rights reserved.
//

import Defaults
import Foundation
import SwiftUI

Expand All @@ -15,6 +16,26 @@ enum DeepLAPIUsagePriority: String, CaseIterable, Hashable {
case authKeyOnly = "2"
}

extension DeepLAPIUsagePriority: Defaults.Serializable {
public static var bridge: Bridge = .init()

public struct Bridge: Defaults.Bridge {
public func serialize(_ value: DeepLAPIUsagePriority?) -> String? {
guard let value else { return DeepLAPIUsagePriority.webFirst.rawValue }
return "\(value.rawValue)"
}

public func deserialize(_ object: String?) -> DeepLAPIUsagePriority? {
guard let object else { return DeepLAPIUsagePriority.webFirst }
return DeepLAPIUsagePriority(rawValue: object) ?? DeepLAPIUsagePriority.webFirst
}

public typealias Value = DeepLAPIUsagePriority

public typealias Serializable = String
}
}

extension DeepLAPIUsagePriority: EnumLocalizedStringConvertible {
var title: String {
switch self {
Expand All @@ -31,7 +52,18 @@ extension DeepLAPIUsagePriority: EnumLocalizedStringConvertible {
@available(macOS 13.0, *)
extension EZDeepLTranslate: ConfigurableService {
func configurationListItems() -> some View {
ServiceConfigurationSecretSectionView(service: self, observeKeys: [.deepLAuth]) {
EZDeepLTranslateConfigurationView(service: self)
}
}

@available(macOS 13.0, *)
private struct EZDeepLTranslateConfigurationView: View {
let service: EZDeepLTranslate

@Default(.deepLTranslation) var apiUsagePriority

var body: some View {
ServiceConfigurationSecretSectionView(service: service, observeKeys: [.deepLAuth]) {
ServiceConfigurationSecureInputCell(
textFieldTitleKey: "service.configuration.deepl.auth_key.title",
key: .deepLAuth
Expand All @@ -43,11 +75,13 @@ extension EZDeepLTranslate: ConfigurableService {
placeholder: "service.configuration.deepl.endpoint.placeholder"
)

ServiceConfigurationPickerCell(
titleKey: "service.configuration.deepl.translation.title",
key: .deepLTranslation,
values: DeepLAPIUsagePriority.allCases
)
Picker("service.configuration.deepl.translation.title", selection: $apiUsagePriority) {
ForEach(DeepLAPIUsagePriority.allCases, id: \.rawValue) { value in
Text(value.title)
.tag(value)
}
}
.padding(10)
}
}
}