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

Refactor Setting - Service and provide service configuration view #326

Merged
merged 23 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
40 changes: 36 additions & 4 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@
03FD68BB2B1DC59600FD388E /* CryptoSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 03FD68BA2B1DC59600FD388E /* CryptoSwift */; };
03FD68BE2B1E151A00FD388E /* String+EncryptAES.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03FD68BD2B1E151A00FD388E /* String+EncryptAES.swift */; };
0A057D6D2B499A000025C51D /* ServiceTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A057D6C2B499A000025C51D /* ServiceTab.swift */; };
0A057D6F2B499A0B0025C51D /* ServiceItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A057D6E2B499A0B0025C51D /* ServiceItemView.swift */; };
0A2BA9602B49A989002872A4 /* Binding+DidSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A2BA95F2B49A989002872A4 /* Binding+DidSet.swift */; };
0A2BA9642B4A3CCD002872A4 /* Notification+Name.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A2BA9632B4A3CCD002872A4 /* Notification+Name.swift */; };
0AC11B222B4D16A500F07198 /* WindowAccessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AC11B212B4D16A500F07198 /* WindowAccessor.swift */; };
Expand Down Expand Up @@ -273,6 +272,9 @@
EA9943EE2B5353AB00EE7B97 /* WindowTypeExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9943ED2B5353AB00EE7B97 /* WindowTypeExtensions.swift */; };
EA9943F02B5354C400EE7B97 /* ShowWindowPositionExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9943EF2B5354C400EE7B97 /* ShowWindowPositionExtensions.swift */; };
EA9943F22B5358BF00EE7B97 /* LanguageExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9943F12B5358BF00EE7B97 /* LanguageExtensions.swift */; };
EAED41EC2B54AA920005FE0A /* ServiceConfigurationSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAED41EB2B54AA920005FE0A /* ServiceConfigurationSection.swift */; };
EAED41EF2B54B1430005FE0A /* ConfigurableService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAED41EE2B54B1430005FE0A /* ConfigurableService.swift */; };
EAED41F22B54B39D0005FE0A /* OpenAIService+ConfigurableService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAED41F12B54B39D0005FE0A /* OpenAIService+ConfigurableService.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -702,7 +704,6 @@
03FD68BD2B1E151A00FD388E /* String+EncryptAES.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+EncryptAES.swift"; sourceTree = "<group>"; };
06E15747A7BD34D510ADC6A8 /* Pods-Easydict.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Easydict.debug.xcconfig"; path = "Target Support Files/Pods-Easydict/Pods-Easydict.debug.xcconfig"; sourceTree = "<group>"; };
0A057D6C2B499A000025C51D /* ServiceTab.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServiceTab.swift; sourceTree = "<group>"; };
0A057D6E2B499A0B0025C51D /* ServiceItemView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServiceItemView.swift; sourceTree = "<group>"; };
0A2BA95F2B49A989002872A4 /* Binding+DidSet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Binding+DidSet.swift"; sourceTree = "<group>"; };
0A2BA9632B4A3CCD002872A4 /* Notification+Name.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Notification+Name.swift"; sourceTree = "<group>"; };
0AC11B212B4D16A500F07198 /* WindowAccessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowAccessor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -761,6 +762,9 @@
EA9943ED2B5353AB00EE7B97 /* WindowTypeExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowTypeExtensions.swift; sourceTree = "<group>"; };
EA9943EF2B5354C400EE7B97 /* ShowWindowPositionExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShowWindowPositionExtensions.swift; sourceTree = "<group>"; };
EA9943F12B5358BF00EE7B97 /* LanguageExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LanguageExtensions.swift; sourceTree = "<group>"; };
EAED41EB2B54AA920005FE0A /* ServiceConfigurationSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceConfigurationSection.swift; sourceTree = "<group>"; };
EAED41EE2B54B1430005FE0A /* ConfigurableService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurableService.swift; sourceTree = "<group>"; };
EAED41F12B54B39D0005FE0A /* OpenAIService+ConfigurableService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OpenAIService+ConfigurableService.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -2051,7 +2055,6 @@
isa = PBXGroup;
children = (
27FE980A2B3DD5D1000AD654 /* MenuItemView.swift */,
0A057D6E2B499A0B0025C51D /* ServiceItemView.swift */,
0AC11B212B4D16A500F07198 /* WindowAccessor.swift */,
0AC11B232B4E46B300F07198 /* TapHandlerView.swift */,
27FE98072B3DD52B000AD654 /* SettingView */,
Expand All @@ -2071,6 +2074,7 @@
27FE980C2B3DD749000AD654 /* Tabs */ = {
isa = PBXGroup;
children = (
EAED41EA2B54A4900005FE0A /* ServiceConfiguration */,
278540332B3DE04F004E9488 /* GeneralTab.swift */,
0A057D6C2B499A000025C51D /* ServiceTab.swift */,
276742042B3DC230002A2C75 /* PrivacyTab.swift */,
Expand Down Expand Up @@ -2203,6 +2207,7 @@
EA9943DD2B534BAE00EE7B97 /* Utility */ = {
isa = PBXGroup;
children = (
EAED41ED2B54B1390005FE0A /* Protocol */,
EA9943E62B534D7C00EE7B97 /* Extensions */,
);
path = Utility;
Expand All @@ -2219,6 +2224,7 @@
EA9943E62B534D7C00EE7B97 /* Extensions */ = {
isa = PBXGroup;
children = (
EAED41F02B54B1A60005FE0A /* QueryService+ConfigurableService */,
EA9943E72B534D8900EE7B97 /* LanguageDetectOptimizeExtensions.swift */,
EA9943ED2B5353AB00EE7B97 /* WindowTypeExtensions.swift */,
EA9943EF2B5354C400EE7B97 /* ShowWindowPositionExtensions.swift */,
Expand All @@ -2227,6 +2233,30 @@
path = Extensions;
sourceTree = "<group>";
};
EAED41EA2B54A4900005FE0A /* ServiceConfiguration */ = {
isa = PBXGroup;
children = (
EAED41EB2B54AA920005FE0A /* ServiceConfigurationSection.swift */,
);
path = ServiceConfiguration;
sourceTree = "<group>";
};
EAED41ED2B54B1390005FE0A /* Protocol */ = {
isa = PBXGroup;
children = (
EAED41EE2B54B1430005FE0A /* ConfigurableService.swift */,
);
path = Protocol;
sourceTree = "<group>";
};
EAED41F02B54B1A60005FE0A /* QueryService+ConfigurableService */ = {
isa = PBXGroup;
children = (
EAED41F12B54B39D0005FE0A /* OpenAIService+ConfigurableService.swift */,
);
path = "QueryService+ConfigurableService";
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -2602,7 +2632,6 @@
03991166292A8A4400E1B06D /* EZTitleBarMoveView.m in Sources */,
03542A582937CC3200C34C33 /* EZConfiguration.m in Sources */,
27FE98092B3DD536000AD654 /* SettingView.swift in Sources */,
0A057D6F2B499A0B0025C51D /* ServiceItemView.swift in Sources */,
035E37E72A0953120061DFAF /* EZToast.m in Sources */,
03542A492937B5CF00C34C33 /* EZGoogleTranslate.m in Sources */,
03D0435A2928C4C800E7559E /* EZWindowManager.m in Sources */,
Expand Down Expand Up @@ -2634,6 +2663,7 @@
03F14A3B2956016B00CB7379 /* EZVolcanoTranslate.m in Sources */,
03B0230429231FA6001C7E63 /* EZHoverButton.m in Sources */,
0342A9812AD64924002A9F5F /* NSString+EZSplit.m in Sources */,
EAED41EF2B54B1430005FE0A /* ConfigurableService.swift in Sources */,
03BD2825294875AE00F5891A /* EZMyLabel.m in Sources */,
03B0233029231FA6001C7E63 /* MMCrashUncaughtExceptionHandler.m in Sources */,
03D5FCFF2A5EF4E400AD26BE /* EZDeviceSystemInfo.m in Sources */,
Expand Down Expand Up @@ -2775,6 +2805,7 @@
039F5508294B6E29004AB940 /* EZAboutViewController.m in Sources */,
03D8A6592A42A1A300D9A968 /* EZAppModel.m in Sources */,
036E7D7B293F4FC8002675DF /* EZOpenLinkButton.m in Sources */,
EAED41EC2B54AA920005FE0A /* ServiceConfigurationSection.swift in Sources */,
276742092B3DC230002A2C75 /* AboutTab.swift in Sources */,
03008B2E2941956D0062B821 /* EZURLSchemeHandler.m in Sources */,
DC6D9C872B352EBC0055EFFC /* FontSizeHintView.swift in Sources */,
Expand All @@ -2790,6 +2821,7 @@
03008B3F29444B0A0062B821 /* NSView+EZAnimatedHidden.m in Sources */,
03B022FD29231FA6001C7E63 /* EZFixedQueryWindow.m in Sources */,
03B0232C29231FA6001C7E63 /* NSView+MM.m in Sources */,
EAED41F22B54B39D0005FE0A /* OpenAIService+ConfigurableService.swift in Sources */,
033C31002A74CECE0095926A /* EZAppleDictionary.m in Sources */,
03E2BF752A298F2B00E010F3 /* NSString+EZUtils.m in Sources */,
03B022F529231FA6001C7E63 /* EZDetectManager.m in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Easydict/App/Easydict-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@
#import "NSString+EZConvenience.h"
#import "EZWindowManager.h"
#import "NSViewController+EZWindow.h"

#import "EZOpenAIService.h"
148 changes: 135 additions & 13 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
{
"sourceLanguage" : "en",
"strings" : {
"" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : ""
}
}
}
},
"about" : {
"comment" : "about",
"localizations" : {
Expand Down Expand Up @@ -505,7 +495,7 @@
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"state" : "translated",
"value" : "[Beta] SwiftUI App模式"
}
}
Expand Down Expand Up @@ -1827,7 +1817,14 @@
}
},
"none_window" : {

"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : ""
}
}
}
},
"ocr_result_is_empty" : {
"localizations" : {
Expand Down Expand Up @@ -2316,6 +2313,92 @@
}
}
},
"service.configuration.openai.api_key.footer" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "API Key的一些说明或者加入链接"
}
}
}
},
"service.configuration.openai.api_key.header" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "OpenAI API Key"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "OpenAI API Key"
}
}
}
},
"service.configuration.openai.api_key.prompt" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
}
}
},
"service.configuration.openai.api_key.title" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "OpenAI API Key"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "OpenAI API Key"
}
}
}
},
"service.configuration.openai.translation.footer" : {

},
"service.configuration.openai.translation.header" : {

},
"service.configuration.openai.translation.prompt" : {

},
"service.configuration.openai.translation.title" : {

},
"service.service_configuration.reset" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Reset"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "重置"
}
}
}
},
"setting_general" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -2780,6 +2863,38 @@
}
}
},
"setting.service.detail.no_configuration %@" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "No configuration for %@"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "%@没有可供配置的选项"
}
}
}
},
"setting.service.detail.no_selection" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Select a service to show configuration"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "选择服务以查看配置"
}
}
}
},
"setting.tts_service.options.apple" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -3205,7 +3320,14 @@
}
},
"unknown_option" : {

"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : ""
}
}
}
},
"unpin" : {
"localizations" : {
Expand Down
7 changes: 5 additions & 2 deletions Easydict/Feature/Service/Ali/AliService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Alamofire
import CryptoKit
import Defaults
import Foundation

@objc(EZAliService)
Expand Down Expand Up @@ -76,8 +77,10 @@ class AliService: QueryService {
easydict://writeKeyValue?EZAliAccessKeyId=
easydict://writeKeyValue?EZAliAccessKeySecret=
*/
if let id = UserDefaults.standard.string(forKey: EZAliAccessKeyId),
let secret = UserDefaults.standard.string(forKey: EZAliAccessKeySecret), !id.isEmpty, !secret.isEmpty
if let id = Defaults[.aliAccessKeyId],
let secret = Defaults[.aliAccessKeySecret],
!id.isEmpty,
!secret.isEmpty
{
requestByAPI(id: id, secret: secret, transType: transType, text: text, from: from, to: to, completion: completion)
} else { // use web api
Expand Down
3 changes: 2 additions & 1 deletion Easydict/Feature/Service/Caiyun/CaiyunService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Alamofire
import Defaults
import Foundation

@objc(EZCaiyunService)
Expand Down Expand Up @@ -44,7 +45,7 @@ public final class CaiyunService: QueryService {

// easydict://writeKeyValue?EZCaiyunToken=
private var token: String {
let token = UserDefaults.standard.string(forKey: EZCaiyunToken)
let token = Defaults[.caiyunToken]
if let token, !token.isEmpty {
return token
} else {
Expand Down
1 change: 1 addition & 0 deletions Easydict/Feature/Service/OpenAI/EZOpenAIService.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ @interface EZOpenAIService ()

@end


@implementation EZOpenAIService

- (instancetype)init {
Expand Down
5 changes: 3 additions & 2 deletions Easydict/Feature/Service/Tencent/TencentService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Alamofire
import Defaults
import Foundation

@objc(EZTencentService)
Expand Down Expand Up @@ -64,7 +65,7 @@ public final class TencentService: QueryService {

// easydict://writeKeyValue?EZTencentSecretId=xxx
private var secretId: String {
let secretId = UserDefaults.standard.string(forKey: EZTencentSecretId)
let secretId = Defaults[.tencentSecretId]
if let secretId, !secretId.isEmpty {
return secretId
} else {
Expand All @@ -74,7 +75,7 @@ public final class TencentService: QueryService {

// easydict://writeKeyValue?EZTencentSecretKey=xxx
private var secretKey: String {
let secretKey = UserDefaults.standard.string(forKey: EZTencentSecretKey)
let secretKey = Defaults[.tencentSecretKey]
if let secretKey, !secretKey.isEmpty {
return secretKey
} else {
Expand Down
Loading
Loading