Skip to content

Commit

Permalink
Merge branch 'dev' into feautre_tips_view
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng authored Feb 25, 2024
2 parents 0e28158 + c9f735a commit e5b8307
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 132 deletions.
20 changes: 8 additions & 12 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@
278322622B0FB8EF0026644C /* CaiyunTranslateType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 278322612B0FB8EF0026644C /* CaiyunTranslateType.swift */; };
278540342B3DE04F004E9488 /* GeneralTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 278540332B3DE04F004E9488 /* GeneralTab.swift */; };
27FE95272B3DC55F000AD654 /* EasydictApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27FE95262B3DC55F000AD654 /* EasydictApp.swift */; };
27FE98052B3DCB09000AD654 /* NewAppManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27FE98042B3DCB09000AD654 /* NewAppManager.swift */; };
27FE98092B3DD536000AD654 /* SettingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27FE98082B3DD536000AD654 /* SettingView.swift */; };
27FE980B2B3DD5D1000AD654 /* MenuItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27FE980A2B3DD5D1000AD654 /* MenuItemView.swift */; };
6220AD5B2A82812300BBFB52 /* EZBingService.m in Sources */ = {isa = PBXBuildFile; fileRef = 6220AD5A2A82812300BBFB52 /* EZBingService.m */; };
Expand Down Expand Up @@ -776,7 +775,6 @@
27B791A02AEC3A5C006E07C6 /* Easydict-debug.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = "Easydict-debug.entitlements"; sourceTree = "<group>"; };
27FE95262B3DC55F000AD654 /* EasydictApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EasydictApp.swift; sourceTree = "<group>"; };
27FE95282B3DC666000AD654 /* entry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = entry.h; sourceTree = "<group>"; };
27FE98042B3DCB09000AD654 /* NewAppManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewAppManager.swift; sourceTree = "<group>"; };
27FE98082B3DD536000AD654 /* SettingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingView.swift; sourceTree = "<group>"; };
27FE980A2B3DD5D1000AD654 /* MenuItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuItemView.swift; sourceTree = "<group>"; };
357E179B303EF855EF4561FB /* Pods-EasydictTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-EasydictTests.release.xcconfig"; path = "Target Support Files/Pods-EasydictTests/Pods-EasydictTests.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2145,7 +2143,6 @@
EA9943DD2B534BAE00EE7B97 /* Utility */,
EA3B81F72B52549B004C0E8B /* Configuration */,
27FE95262B3DC55F000AD654 /* EasydictApp.swift */,
27FE98042B3DCB09000AD654 /* NewAppManager.swift */,
27FE98062B3DD525000AD654 /* View */,
);
path = NewApp;
Expand Down Expand Up @@ -2978,7 +2975,6 @@
03BB2DE329F5772F00447EDD /* EZAudioButton.m in Sources */,
03262C2529EFE97B00EFECA0 /* NSViewController+EZWindow.m in Sources */,
03008B2729408BF50062B821 /* NSObject+EZDarkMode.m in Sources */,
27FE98052B3DCB09000AD654 /* NewAppManager.swift in Sources */,
0399116A292AA2EF00E1B06D /* EZLayoutManager.m in Sources */,
0320C5872B29F35700861B3D /* QueryServiceRecord.swift in Sources */,
9643D9422B6FE4AF000FBEA6 /* Shortcut+Bind.swift in Sources */,
Expand Down Expand Up @@ -3212,7 +3208,7 @@
CODE_SIGN_IDENTITY = $CODE_SIGN_IDENTITY;
CODE_SIGN_STYLE = $CODE_SIGN_STYLE;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 32;
CURRENT_PROJECT_VERSION = 33;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -3223,7 +3219,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 2.6.0;
MARKETING_VERSION = 2.6.1;
PRODUCT_BUNDLE_IDENTIFIER = "com.izual.EasydictHelper-debug";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand All @@ -3238,7 +3234,7 @@
CODE_SIGN_IDENTITY = $CODE_SIGN_IDENTITY;
CODE_SIGN_STYLE = $CODE_SIGN_STYLE;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 32;
CURRENT_PROJECT_VERSION = 33;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -3249,7 +3245,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 2.6.0;
MARKETING_VERSION = 2.6.1;
PRODUCT_BUNDLE_IDENTIFIER = com.izual.EasydictHelper;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -3395,7 +3391,7 @@
CODE_SIGN_STYLE = $CODE_SIGN_STYLE;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 32;
CURRENT_PROJECT_VERSION = 33;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -3410,7 +3406,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 2.6.0;
MARKETING_VERSION = 2.6.1;
PRODUCT_BUNDLE_IDENTIFIER = "com.izual.Easydict-debug";
PRODUCT_MODULE_NAME = Easydict;
PRODUCT_NAME = "Easydict-debug";
Expand All @@ -3435,7 +3431,7 @@
CODE_SIGN_STYLE = $CODE_SIGN_STYLE;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 32;
CURRENT_PROJECT_VERSION = 33;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -3450,7 +3446,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 2.6.0;
MARKETING_VERSION = 2.6.1;
PRODUCT_BUNDLE_IDENTIFIER = com.izual.Easydict;
PRODUCT_MODULE_NAME = Easydict;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
2 changes: 1 addition & 1 deletion Easydict/App/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[EZLog setupCrashLogService];
[EZLog logAppInfo];

if (!EasydictNewAppManager.shared.enable) {
if (!Configuration.shared.enableBetaNewApp) {
[EZMenuItemManager.shared setup];
[EZShortcut setup];
} else {
Expand Down
6 changes: 3 additions & 3 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -533,13 +533,13 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "[Beta] SwiftUI App mode"
"value" : "SwiftUI App mode:"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "[Beta] SwiftUI App模式"
"value" : "SwiftUI App模式"
}
}
}
Expand Down Expand Up @@ -1775,7 +1775,7 @@
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"state" : "translated",
"value" : "反馈"
}
}
Expand Down
2 changes: 1 addition & 1 deletion Easydict/Feature/Configuration/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ private extension Configuration {
}

func didSetHideMenuBarIcon() {
if !NewAppManager.shared.enable {
if !Configuration.shared.enableBetaNewApp {
hideMenuBarIcon(hidden: hideMenuBarIcon)
}

Expand Down
2 changes: 1 addition & 1 deletion Easydict/Feature/Configuration/EZConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ - (void)setHideMenuBarIcon:(BOOL)hideMenuBarIcon {

[NSUserDefaults mm_write:@(hideMenuBarIcon) forKey:kHideMenuBarIconKey];

if (!EasydictNewAppManager.shared.enable) {
if (!Configuration.shared.enableBetaNewApp) {
[self hideMenuBarIcon:hideMenuBarIcon];
}

Expand Down
9 changes: 8 additions & 1 deletion Easydict/NewApp/Configuration/Configuration+Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,20 @@ extension Defaults.Keys {
static let clearInput = Key<Bool>("EZConfiguration_kClearInputKey", default: true)
static let keepPrevResultWhenEmpty = Key<Bool>("EZConfiguration_kKeepPrevResultKey", default: true)
static let selectQueryTextWhenWindowActivate = Key<Bool>("EZConfiguration_kSelectQueryTextWhenWindowActivate", default: false)
static let enableBetaNewApp = Key<Bool>("EZConfiguration_kEnableBetaNewAppKey", default: true)

static let enableBetaFeature = Key<Bool>("EZBetaFeatureKey", default: false)

static let appearanceType = Key<AppearenceType>("EZConfiguration_kApperanceKey", default: .followSystem)
static let fontSizeOptionIndex = Key<UInt>("EZConfiguration_kTranslationControllerFontKey", default: 0)
static let selectedMenuBarIcon = Key<MenuBarIconType>("EZConfiguration_kSelectedMenuBarIconKey", default: .square)

static var enableBetaNewApp: Key<Bool> {
if #available(macOS 13.0, *) {
Key("EZConfiguration_kEnableBetaNewAppKey", default: true)
} else {
Key("EZConfiguration_kEnableBetaNewAppKey", default: false)
}
}
}

extension Defaults.Keys {
Expand Down
2 changes: 1 addition & 1 deletion Easydict/NewApp/EasydictApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import SwiftUI
enum EasydictCmpatibilityEntry {
static func main() {
parseArmguments()
if NewAppManager.shared.enable {
if Configuration.shared.enableBetaNewApp {
EasydictApp.main()
} else {
_ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)
Expand Down
25 changes: 0 additions & 25 deletions Easydict/NewApp/NewAppManager.swift

This file was deleted.

36 changes: 23 additions & 13 deletions Easydict/NewApp/View/SettingView/Tabs/ServiceTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,29 @@ private struct ServiceItems: View {
}
}

private class ServiceItemViewModel: ObservableObject {
@Published var isEnable = false

init(isEnable: Bool) {
self.isEnable = isEnable
}
}

@available(macOS 13.0, *)
private struct ServiceItemView: View {
let service: QueryService

@EnvironmentObject private var viewModel: ServiceTabViewModel

private var enabled: Binding<Bool> {
.init {
service.enabled
} set: { newValue in
guard service.enabled != newValue else { return }
service.enabled = newValue
if newValue {
service.enabledQuery = newValue
}
EZLocalStorage.shared().setService(service, windowType: viewModel.windowType)
viewModel.postUpdateServiceNotification()
}
@ObservedObject private var serviceItemViewModel: ServiceItemViewModel

init(service: QueryService) {
self.service = service
serviceItemViewModel = ServiceItemViewModel(isEnable: service.enabled)
}

var body: some View {
Toggle(isOn: enabled) {
Toggle(isOn: $serviceItemViewModel.isEnable) {
HStack {
Image(service.serviceType().rawValue)
.resizable()
Expand All @@ -153,6 +154,15 @@ private struct ServiceItemView: View {
.fixedSize()
}
}
.onReceive(serviceItemViewModel.$isEnable) { newValue in
guard service.enabled != newValue else { return }
service.enabled = newValue
if newValue {
service.enabledQuery = newValue
}
EZLocalStorage.shared().setService(service, windowType: viewModel.windowType)
viewModel.postUpdateServiceNotification()
}
.padding(4.0)
.toggleStyle(.switch)
.controlSize(.small)
Expand Down
57 changes: 20 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

## Easydict

`Easydict` 是一个简洁易用的词典翻译 macOS App,能够轻松优雅地查找单词或翻译文本。Easydict 开箱即用,能自动识别输入文本语言,支持输入翻译,划词翻译和 OCR 截图翻译,可同时查询多个翻译服务结果,目前支持 [有道词典](https://www.youdao.com/)[**🍎 苹果系统词典**](./docs/How-to-use-macOS-system-dictionary-in-Easydict-zh.md)[🍎 **苹果系统翻译**](./docs/How-to-use-macOS-system-translation-in-Easydict-zh.md)[OpenAI (ChatGPT)](https://chat.openai.com/)[DeepL](https://www.deepl.com/translator)[Google](https://translate.google.com)[腾讯](https://fanyi.qq.com/)[Bing](https://www.bing.com/translator)[百度](https://fanyi.baidu.com/)[小牛翻译](https://niutrans.com/)[彩云小译](https://fanyi.caiyunapp.com/)[阿里翻译](https://translate.alibaba.com/)[火山翻译](https://translate.volcengine.com/translate)
`Easydict` 是一个简洁易用的词典翻译 macOS App,能够轻松优雅地查找单词或翻译文本。Easydict 开箱即用,能自动识别输入文本语言,支持输入翻译,划词翻译和 OCR 截图翻译,可同时查询多个翻译服务结果,目前支持 [有道词典](https://www.youdao.com/)[**🍎 苹果系统词典**](./docs/How-to-use-macOS-system-dictionary-in-Easydict-zh.md)[🍎 **苹果系统翻译**](./docs/How-to-use-macOS-system-translation-in-Easydict-zh.md)[OpenAI (ChatGPT)](https://chat.openai.com/)[Gemini](https://gemini.google.com/)[DeepL](https://www.deepl.com/translator)[Google](https://translate.google.com)[腾讯](https://fanyi.qq.com/)[Bing](https://www.bing.com/translator)[百度](https://fanyi.baidu.com/)[小牛翻译](https://niutrans.com/)[彩云小译](https://fanyi.caiyunapp.com/)[阿里翻译](https://translate.alibaba.com/)[火山翻译](https://translate.volcengine.com/translate)

![Log](https://raw.githubusercontent.com/tisfeng/ImageBed/main/uPic/Log-1688378715.png)

Expand All @@ -42,7 +42,7 @@
- [x] 支持系统 TTS,支持 Bing,Google,有道和百度在线 TTS 服务。
- [x] 支持 [🍎 苹果系统词典](./docs/How-to-use-macOS-system-dictionary-in-Easydict-zh.md),支持第三方词典,可手动导入 mdict 词典。
- [x] 支持 macOS 系统翻译。详情请看 [如何在 Easydict 中使用 🍎 macOS 系统翻译?](./docs/How-to-use-macOS-system-translation-in-Easydict-zh.md)
- [x] 支持有道词典,OpenAI (ChatGPT),DeepL,Google,Bing,腾讯,百度,小牛,彩云,阿里和火山翻译。
- [x] 支持有道词典,OpenAI (ChatGPT),Gemini,DeepL,Google,Bing,腾讯,百度,小牛,彩云,阿里和火山翻译。
- [x] 支持 48 种语言。

**如果觉得这个应用还不错,给个 [Star](https://github.com/tisfeng/Easydict) ⭐️ 支持一下吧 (^-^)**
Expand All @@ -64,7 +64,6 @@
- [2. Homebrew 安装](#2-homebrew-安装)
- [开发者构建](#开发者构建)
- [构建环境](#构建环境)
- [签名问题 ⚠️](#签名问题-️)
- [使用](#使用)
- [鼠标划词](#鼠标划词)
- [关于权限](#关于权限)
Expand All @@ -74,10 +73,11 @@
- [查询服务](#查询服务)
- [🍎 苹果系统词典](#-苹果系统词典)
- [OpenAI(ChatGPT)翻译](#openaichatgpt翻译)
- [使用内置 Gemini key](#使用内置-gemini-key)
- [使用内置 APIKey](#使用内置-apikey)
- [配置个人的 APIKey](#配置个人的-apikey)
- [OpenAI 查询模式](#openai-查询模式)
- [OpenAI 自定义参数](#openai-自定义参数)
- [Gemini 翻译](#gemini-翻译)
- [DeepL 翻译](#deepl-翻译)
- [配置 AuthKey](#配置-authkey)
- [自定义 DeepL 接口地址](#自定义-deepl-接口地址)
Expand Down Expand Up @@ -160,36 +160,6 @@ Xcode 13+, macOS Big Sur 11.3+。为避免不必要的问题,建议使用最

</details>

### 签名问题 ⚠️

Easydict 是开源软件,本身是安全的,但由于苹果严格的检查机制,打开时可能会遇到警告拦截。

常见问题

1. 如果遇到下面 [无法打开 Easydict 问题](https://github.com/tisfeng/Easydict/issues/2),请参考苹果使用手册 [打开来自身份不明开发者的 Mac App](https://support.apple.com/zh-cn/guide/mac-help/mh40616/mac)

> 无法打开“Easydict.dmg”,因为它来自身份不明的开发者。
<div>
<img src="https://user-images.githubusercontent.com/25194972/219873635-46e9d318-7237-462b-be69-44ad7a3ea760.png" width="30%">
<img src="https://user-images.githubusercontent.com/25194972/219873670-7ce67946-87c2-4d45-84fd-3cc59936f7be.png" width="30%">
<img src="https://user-images.githubusercontent.com/25194972/219873722-2e780565-fe26-4ce3-9648-f1cbdd393843.png" width="30%">
</div>

<div style="display: flex; justify-content: space-between;">
<img src="https://user-images.githubusercontent.com/25194972/219873809-2b407852-7f77-4aef-9206-3f6393cb7c31.png" width="100%" />
</div>

2. 如果提示应用已损坏,请参考 [macOS 绕过公证和应用签名方法](https://www.5v13.com/sz/31695.html)

> “Easydict”已损坏,无法打开。
在终端里输入以下命令,并输入密码即可。

```bash
sudo xattr -rd com.apple.quarantine /Applications/Easydict.app
```

---

## 使用
Expand Down Expand Up @@ -350,11 +320,16 @@ Easydict 自动支持词典 App 中系统自带的词典,如牛津英汉汉英

例如 [one-api](https://github.com/songquanpeng/one-api),one-api 是一个很好的 OpenAI 接口管理开源项目,支持多家 LLM 接口,包括 Azure、Anthropic Claude、Google PaLM 2 & Gemini、智谱 ChatGLM、百度文心一言、讯飞星火认知、阿里通义千问、360 智脑以及腾讯混元等,可用于二次分发管理 key,仅单可执行文件,已打包好 Docker 镜像,一键部署,开箱即用。

目前 GUI 方式配置 API key 功能还在开发中 [[#227](https://github.com/tisfeng/Easydict/issues/227)],暂时需要在 Easydict 的输入框中使用命令方式配置。
[2.6.0](https://github.com/tisfeng/Easydict/releases) 版本实现了新的 SwiftUI 设置页(支持 macOS 13+),支持 GUI 方式配置服务 API key,其他则需要在 Easydict 的输入框中使用命令方式配置。

> [!NOTE]
> 如果电脑硬件支持的话,建议升级到最新的 macOS 系统,以享受更好的用户体验。
![](https://github.com/tisfeng/Easydict/assets/25194972/5b8f2785-b0ee-4a9e-bd41-1a9dd56b0231)

#### 使用内置 Gemini key
#### 使用内置 APIKey

目前 Google 的 Gemini API 免费,实测下来翻译效果不错,由于项目对 Gemini 支持 [#270](https://github.com/tisfeng/Easydict/issues/270) 还在开发中,可能需要一点时间,因此我内置了一个 key,方便用户直接使用 Gemini 模型来翻译。但请注意,这个 key 有一定使用限制且不稳定,因此如果有能力部署 one-api,建议优先使用自己的 APIKey。
目前 Google 的 Gemini API 免费,实测下来翻译效果不错,为方便用户使用,我内置了一个 key。但请注意,这个 key 有一定使用限制且不稳定,因此如果有能力部署 one-api,建议优先使用自己的 APIKey。

在 Beta 模式下,并且没有设置自己的 APIKey,这样就会自动使用内置的 Gemini key。

Expand Down Expand Up @@ -425,6 +400,14 @@ easydict://writeKeyValue?EZOpenAIModelKey=xxx

由于 OpenAI 官方接口对用户 IP 有限制,因此如果你需要反向代理,可以参考这个反代项目 [cloudflare-reverse-proxy](https://github.com/gaboolic/cloudflare-reverse-proxy)

### Gemini 翻译

[Gemini 翻译](https://gemini.google.com/) 需要 API key,可在官网[控制台](https://makersuite.google.com/app/apikey)免费获取。

```bash
easydict://writeKeyValue?EZGeminiAPIKey=xxx
```

### DeepL 翻译

DeepL 免费版网页 API 对用户单个 IP 有频率限制,频繁使用会触发 429 too many requests 报错,因此 1.3.0 版本增加了对 DeepL 官方 API 的支持,暂时还没写界面,需通过命令方式启用。
Expand Down
Loading

0 comments on commit e5b8307

Please sign in to comment.