Skip to content

Commit

Permalink
Merge branch 'dev' into fix/tips_view_blank
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng authored Apr 26, 2024
2 parents 90edad1 + 9eaab98 commit 9003335
Show file tree
Hide file tree
Showing 24 changed files with 168 additions and 143 deletions.
12 changes: 2 additions & 10 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2474,7 +2474,6 @@
isa = PBXGroup;
children = (
EAE3D34F2B62E9DE001EE3E3 /* GlobalContext.swift */,
EAED41ED2B54B1390005FE0A /* Protocol */,
EA9943E62B534D7C00EE7B97 /* Extensions */,
);
path = Utility;
Expand Down Expand Up @@ -2507,6 +2506,8 @@
isa = PBXGroup;
children = (
EAED41F02B54B1A60005FE0A /* QueryService+ConfigurableService */,
EAED41EE2B54B1430005FE0A /* ConfigurableService.swift */,
0AC8A83E2B689E68006DA5CC /* ServiceSecretConfigreValidatable.swift */,
0AC8A83C2B6685EE006DA5CC /* SecureTextField.swift */,
EAED41EB2B54AA920005FE0A /* ServiceConfigurationSection.swift */,
0AC8A8462B6A4E3F006DA5CC /* ServiceConfigurationSecretSectionView.swift */,
Expand All @@ -2515,15 +2516,6 @@
path = ServiceConfigurationView;
sourceTree = "<group>";
};
EAED41ED2B54B1390005FE0A /* Protocol */ = {
isa = PBXGroup;
children = (
EAED41EE2B54B1430005FE0A /* ConfigurableService.swift */,
0AC8A83E2B689E68006DA5CC /* ServiceSecretConfigreValidatable.swift */,
);
path = Protocol;
sourceTree = "<group>";
};
EAED41F02B54B1A60005FE0A /* QueryService+ConfigurableService */ = {
isa = PBXGroup;
children = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scale" : "1x"
},
{
"filename" : "OpenAI.png",
"filename" : "OpenAI Translator.png",
"idiom" : "universal",
"scale" : "2x"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
10 changes: 5 additions & 5 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Custom OpenAI Translate"
"value" : "Custom OpenAI"
}
},
"zh-Hans" : {
Expand Down Expand Up @@ -2096,13 +2096,13 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "No results found"
"value" : "No results found"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "未查询到结果"
"value" : "未查询到结果"
}
}
}
Expand Down Expand Up @@ -2438,13 +2438,13 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Query failed"
"value" : "💥 Failed"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "查询失败"
"value" : "💥 失败"
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions Easydict/Swift/Feature/Configuration/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,10 @@ class Configuration: NSObject {
}
.store(in: &cancellables)

Defaults.publisher(.appearanceType)
Defaults.publisher(.appearanceType, options: [])
.removeDuplicates()
.sink { [weak self] change in
let newValue = change.newValue

self?.didSetAppearance(newValue)
}
.store(in: &cancellables)
Expand Down
3 changes: 1 addition & 2 deletions Easydict/Swift/Service/Ali/AliService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ class AliService: QueryService {
if let data = value.data, let translateText = data.translated {
result.translatedResults = [translateText]
completion(result, nil)
logInfo("ali api translate success")
} else {
completion(
result,
Expand All @@ -257,7 +256,7 @@ class AliService: QueryService {
msg = error.errorDescription
}

logError("ali api translate error: \(msg ?? "")")
logError("Ali translate error: \(msg ?? "")")
completion(result, EZError(nsError: error, errorDataMessage: msg))
}
}
Expand Down
21 changes: 13 additions & 8 deletions Easydict/Swift/Service/BuiltInAI/BuiltInAIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,20 @@ class BuiltInAIService: BaseOpenAIService {

override var availableModels: [String] {
[
// DashScope 限时免费开放中 https://help.aliyun.com/zh/dashscope/developer-reference/tongyi-qianwen-7b-14b-72b-metering-and-billing
"qwen1.5-32b-chat",
"qwen-turbo", // free until 8.12
"qwen-plus", // free until 8.12
"deepseek-7b-chat",
"internlm-7b-chat",

// Groq https://console.groq.com/docs/models
/**
阿里通义千问 DashScope 限时免费开放中 https://help.aliyun.com/zh/dashscope/developer-reference/tongyi-qianwen-7b-14b-72b-metering-and-billing

通义千问开源系列,开通DashScope即获赠总计 1,000,000 tokens 限时免费使用额度,有效期30天。(qwen1.5-32b-chat模型目前限时免费开放中)
*/
"qwen1.5-32b-chat", // 目前限时免费开放中
"qwen-turbo", // free total 2,000,000 tokens, until 8.12
"baichuan2-13b-chat-v1", // free until 8.12, total 1,000,000 tokens
"deepseek-7b-chat", // 开通DashScope即获赠总计 1,000,000 tokens 限时免费使用额度,有效期180天。
"internlm-7b-chat", // 开通DashScope即获赠总计 1,000,000 tokens 限时免费使用额度,有效期180天。

// Groq free models https://console.groq.com/docs/models
"mixtral-8x7b-32768",
"llama3-70b-8192",

// It seems that 5.2 will start charging 😥 https://ai.google.dev/pricing?hl=zh-cn
"gemini-pro",
Expand Down
2 changes: 1 addition & 1 deletion Easydict/Swift/Service/Gemini/GeminiService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public final class GeminiService: QueryService {
do {
let prompt = GeminiService
.translationPrompt + "Translate the following \(from.rawValue) text into \(to.rawValue): \(text)"
logInfo("gemini prompt: \(prompt)")
// logInfo("gemini prompt: \(prompt)")
let model = GenerativeModel(
name: "gemini-pro",
apiKey: apiKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,26 @@ private class CustomOpenAIViewModel: ObservableObject {

init(service: CustomOpenAIService) {
self.service = service
cancellables.append(
Defaults.publisher(.customOpenAIModel, options: [])
.removeDuplicates()
.sink { _ in
self.modelChanged()
}
)
cancellables.append(
Defaults.publisher(.customOpenAINameKey, options: [])
.removeDuplicates()
.sink { _ in
self.serviceConfigChanged()
}
)
cancellables.append(
Defaults.publisher(.customOpenAIAvailableModels)
.removeDuplicates()
.sink { _ in
self.modelsTextChanged()
}
)
Defaults.publisher(.customOpenAIModel, options: [])
.removeDuplicates()
.sink { _ in
self.modelChanged()
}
.store(in: &cancellables)
Defaults.publisher(.customOpenAINameKey, options: [])
.removeDuplicates()
.throttle(for: 0.1, scheduler: DispatchQueue.main, latest: true)
.sink { _ in
self.serviceConfigChanged()
}
.store(in: &cancellables)
Defaults.publisher(.customOpenAIAvailableModels)
.removeDuplicates()
.throttle(for: 0.1, scheduler: DispatchQueue.main, latest: true)
.sink { _ in
self.modelsTextChanged()
}
.store(in: &cancellables)
}

// MARK: Internal
Expand All @@ -150,7 +149,7 @@ private class CustomOpenAIViewModel: ObservableObject {

// MARK: Private

private var cancellables: [AnyCancellable] = []
private var cancellables: Set<AnyCancellable> = []

private func modelChanged() {
if !validModels.contains(model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,19 @@ private class OpenAIServiceViewModel: ObservableObject {

init(service: OpenAIService) {
self.service = service
cancellables.append(
Defaults.publisher(.openAIModel, options: [])
.removeDuplicates()
.sink { _ in
self.modelChanged()
}
)
cancellables.append(
Defaults.publisher(.openAIAvailableModels)
.removeDuplicates()
.sink { _ in
self.modelsTextChanged()
}
)
Defaults.publisher(.openAIModel, options: [])
.removeDuplicates()
.sink { _ in
self.modelChanged()
}
.store(in: &cancellables)
Defaults.publisher(.openAIAvailableModels)
.removeDuplicates()
.throttle(for: 0.1, scheduler: DispatchQueue.main, latest: true)
.sink { _ in
self.modelsTextChanged()
}
.store(in: &cancellables)
}

// MARK: Internal
Expand All @@ -135,7 +134,7 @@ private class OpenAIServiceViewModel: ObservableObject {

// MARK: Private

private var cancellables: [AnyCancellable] = []
private var cancellables: Set<AnyCancellable> = []

private func modelChanged() {
// Currently, user of low os versions can change OpenAI model using URL scheme, like easydict://writeKeyValue?EZOpenAIModelKey=gpt-4
Expand Down
2 changes: 1 addition & 1 deletion Easydict/objc/EventMonitor/EZEventMonitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ - (EZTriggerType)getAppSelectTextActionType:(NSString *)appBundleID
for (EZAppModel *appModel in appModelList) {
if ([appModel.appBundleID isEqualToString:appBundleID]) {
triggerType = appModel.triggerType;
MMLogInfo(@"App bundleID: %@, %@", appBundleID, @(triggerType));
MMLogInfo(@"Hit app bundleID: %@, triggerType: %@", appBundleID, @(triggerType));
}
}
return triggerType;
Expand Down
9 changes: 5 additions & 4 deletions Easydict/objc/MMKit/Log/MMLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@

import CocoaLumberjackSwift

// Only log in debug mode, like MMLog.
@inlinable
public func logInfo(
public func log(
_ message: @autoclosure () -> String,
file: StaticString = #file,
function: StaticString = #function,
line: UInt = #line,
ddlog: DDLog = MMManagerForLog.sharedDDLog()
) {
DDLogInfo(
DDLogVerbose(
message(),
level: MMDefaultLogLevel,
file: file,
Expand All @@ -32,14 +33,14 @@ public func logInfo(
}

@inlinable
public func logVerbose(
public func logInfo(
_ message: @autoclosure () -> String,
file: StaticString = #file,
function: StaticString = #function,
line: UInt = #line,
ddlog: DDLog = MMManagerForLog.sharedDDLog()
) {
DDLogVerbose(
DDLogInfo(
message(),
level: MMDefaultLogLevel,
file: file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ - (nullable NSString *)queryAllIframeHTMLResultOfWord:(NSString *)word
- (NSArray<NSString *> *)queryEntryHTMLsOfWord:(NSString *)word
inDictionary:(TTTDictionary *)dictionary
language:(nullable EZLanguage)language {
CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
// CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
NSMutableArray *entryHTMLs = [NSMutableArray array];

// Cost about ~10ms
Expand All @@ -270,8 +270,8 @@ - (nullable NSString *)queryAllIframeHTMLResultOfWord:(NSString *)word
}
}

CFAbsoluteTime endTime = CFAbsoluteTimeGetCurrent();
MMLogInfo(@"Query [%@] dict cost: %.1f ms", dictionary.name, (endTime - startTime) * 1000); // 13ms
// CFAbsoluteTime endTime = CFAbsoluteTimeGetCurrent();
// MMLog(@"Query [%@] dict cost: %.1f ms", dictionary.name, (endTime - startTime) * 1000); // 13ms

return entryHTMLs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@
// Change font size
function changeIframeBodyFontSize(fontSizeRatio) {
var percentFontSize = fontSizeRatio * 100 + "%";
console.log("fontSize: " + fontSizeRatio);
// console.log("fontSize: " + fontSizeRatio);

// change body font size
document.body.style.fontSize = percentFontSize;
Expand Down Expand Up @@ -514,4 +514,4 @@

<body></body>

</html>
</html>
7 changes: 7 additions & 0 deletions Easydict/objc/Service/Model/EZError.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ + (instancetype)errorWithType:(EZErrorType)type
}

NSString *queryFailedString = NSLocalizedString(@"query_failed", nil);
/**
FIXME: If the first character of the text is an emoji, like "💥 失败", NSTextView will render spaces incorrectly.
I don't know how to fix it, so I'm inserting an invisible special character at the beginning.
*/
NSString *zeroWidthSpace = @"\u200B";
queryFailedString = [zeroWidthSpace stringByAppendingString:queryFailedString];

if (errorString.length) {
errorString = [NSString stringWithFormat:@"%@, %@", queryFailedString, errorString];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation
// 监听 JavaScript 代码是否执行
- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler {
// JavaScript 代码执行
MMLogError(@"runJavaScriptAlertPanelWithMessage: %@", message);
MMLogInfo(@"runJavaScriptAlertPanelWithMessage: %@", message);
}


Expand Down
1 change: 1 addition & 0 deletions Easydict/objc/ViewController/Model/EZQueryModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ - (instancetype)init {
self.showAutoLanguage = NO;
self.specifiedTextLanguageDict = [NSMutableDictionary dictionary];
self.autoQuery = YES;
self.inputText = @"";
}
return self;
}
Expand Down
Loading

0 comments on commit 9003335

Please sign in to comment.