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

Replace Shortcut With KeyHolder #337

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 45 additions & 0 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@
62E2BF4C2B4082BA00E42D38 /* AliTranslateType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62E2BF492B4082BA00E42D38 /* AliTranslateType.swift */; };
62ED29A22B15F1F500901F51 /* EZWrapView.m in Sources */ = {isa = PBXBuildFile; fileRef = 62ED29A12B15F1F500901F51 /* EZWrapView.m */; };
9672D7D22B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m in Sources */ = {isa = PBXBuildFile; fileRef = 9672D7D12B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m */; };
969885D32B564041005C8ECB /* KeyHolder in Frameworks */ = {isa = PBXBuildFile; productRef = 969885D22B564041005C8ECB /* KeyHolder */; };
969885D92B5640BB005C8ECB /* GeneralShortcutSetting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 969885D62B5640BB005C8ECB /* GeneralShortcutSetting.swift */; };
969885DA2B5640BB005C8ECB /* GeneralKeyHolderWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 969885D72B5640BB005C8ECB /* GeneralKeyHolderWrapper.swift */; };
969885DB2B5640BB005C8ECB /* GeneralOtherSetting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 969885D82B5640BB005C8ECB /* GeneralOtherSetting.swift */; };
A0B65CA0F31AC8ECFB8347CC /* Pods_EasydictTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 378E73A7EA8FC8FB9C975A63 /* Pods_EasydictTests.framework */; };
B87AC7E36367075BA5D13234 /* Pods_Easydict.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6372B33DFF803C7096A82250 /* Pods_Easydict.framework */; };
C4DD01E92B12B3C80025EE8E /* TencentService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4DD01E82B12B3C80025EE8E /* TencentService.swift */; };
Expand Down Expand Up @@ -745,6 +749,9 @@
91E3E579C6DB88658B4BB102 /* Pods-Easydict.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Easydict.release.xcconfig"; path = "Target Support Files/Pods-Easydict/Pods-Easydict.release.xcconfig"; sourceTree = "<group>"; };
9672D7D02B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MASShortcutBinder+EZMASShortcutBinder.h"; sourceTree = "<group>"; };
9672D7D12B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "MASShortcutBinder+EZMASShortcutBinder.m"; sourceTree = "<group>"; };
969885D62B5640BB005C8ECB /* GeneralShortcutSetting.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneralShortcutSetting.swift; sourceTree = "<group>"; };
969885D72B5640BB005C8ECB /* GeneralKeyHolderWrapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneralKeyHolderWrapper.swift; sourceTree = "<group>"; };
969885D82B5640BB005C8ECB /* GeneralOtherSetting.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneralOtherSetting.swift; sourceTree = "<group>"; };
A230E9A2358C7FBC7FB26189 /* Pods-EasydictTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-EasydictTests.debug.xcconfig"; path = "Target Support Files/Pods-EasydictTests/Pods-EasydictTests.debug.xcconfig"; sourceTree = "<group>"; };
C4DD01E82B12B3C80025EE8E /* TencentService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TencentService.swift; sourceTree = "<group>"; };
C4DD01EA2B12BA250025EE8E /* TencentResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TencentResponse.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -806,6 +813,7 @@
EA3B81FC2B52555C004C0E8B /* Defaults in Frameworks */,
03CF27FE2B3DA7D500E19B57 /* Realm in Frameworks */,
03A830902B4073E700112834 /* AppCenterAnalytics in Frameworks */,
969885D32B564041005C8ECB /* KeyHolder in Frameworks */,
03B63ABF2A86967800E155ED /* CoreServices.framework in Frameworks */,
038030972B4106800009230C /* CocoaLumberjackSwift in Frameworks */,
038EA1AA2B41169C008A6DD1 /* ZipArchive in Frameworks */,
Expand Down Expand Up @@ -2072,6 +2080,7 @@
27FE980C2B3DD749000AD654 /* Tabs */ = {
isa = PBXGroup;
children = (
969885D42B5640BA005C8ECB /* View */,
278540332B3DE04F004E9488 /* GeneralTab.swift */,
0A057D6C2B499A000025C51D /* ServiceTab.swift */,
276742042B3DC230002A2C75 /* PrivacyTab.swift */,
Expand Down Expand Up @@ -2128,6 +2137,24 @@
name = Frameworks;
sourceTree = "<group>";
};
969885D42B5640BA005C8ECB /* View */ = {
isa = PBXGroup;
children = (
969885D52B5640BB005C8ECB /* Genearl */,
);
path = View;
sourceTree = "<group>";
};
969885D52B5640BB005C8ECB /* Genearl */ = {
isa = PBXGroup;
children = (
969885D62B5640BB005C8ECB /* GeneralShortcutSetting.swift */,
969885D72B5640BB005C8ECB /* GeneralKeyHolderWrapper.swift */,
969885D82B5640BB005C8ECB /* GeneralOtherSetting.swift */,
);
path = Genearl;
sourceTree = "<group>";
};
9CB57B9B45EC322A11ED8865 /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2321,6 +2348,7 @@
038EA1A92B41169C008A6DD1 /* ZipArchive */,
038EA1AC2B41282F008A6DD1 /* MJExtension */,
EA3B81FB2B52555C004C0E8B /* Defaults */,
969885D22B564041005C8ECB /* KeyHolder */,
);
productName = Bob;
productReference = C99EEB182385796700FEE666 /* Easydict-debug.app */;
Expand Down Expand Up @@ -2380,6 +2408,7 @@
038EA1A82B41169C008A6DD1 /* XCRemoteSwiftPackageReference "ZipArchive" */,
038EA1AB2B41282F008A6DD1 /* XCRemoteSwiftPackageReference "MJExtension" */,
EA3B81FA2B52555C004C0E8B /* XCRemoteSwiftPackageReference "Defaults" */,
969885D12B564040005C8ECB /* XCRemoteSwiftPackageReference "KeyHolder" */,
);
productRefGroup = C99EEB192385796700FEE666 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -2651,6 +2680,7 @@
03542A432937B45E00C34C33 /* EZBaiduTranslate.m in Sources */,
03BB2DEB29F57DC000447EDD /* NSImage+EZSymbolmage.m in Sources */,
03B0230629231FA6001C7E63 /* EZLabel.m in Sources */,
969885DA2B5640BB005C8ECB /* GeneralKeyHolderWrapper.swift in Sources */,
03F25CB329327BC200E66A12 /* EZShortcut.m in Sources */,
033B7134293CE2430096E2DF /* EZWebViewTranslator.m in Sources */,
03CF88632B137F650030C199 /* Array+Convenience.swift in Sources */,
Expand Down Expand Up @@ -2702,6 +2732,7 @@
03BB2DEF29F59C8A00447EDD /* EZSymbolImageButton.m in Sources */,
0A2BA9642B4A3CCD002872A4 /* Notification+Name.swift in Sources */,
62A2D03F2A82967F007EEB01 /* EZBingRequest.m in Sources */,
969885D92B5640BB005C8ECB /* GeneralShortcutSetting.swift in Sources */,
03BDA7BE2A26DA280079D04F /* XPMCountedArgument.m in Sources */,
03D35DAA2AA6C49B00B023FE /* NSString+EZRegex.m in Sources */,
03B022FE29231FA6001C7E63 /* EZBaseQueryViewController.m in Sources */,
Expand Down Expand Up @@ -2775,6 +2806,7 @@
037852B02957FEB200D0E2CF /* EZServiceViewController.m in Sources */,
6220AD5B2A82812300BBFB52 /* EZBingService.m in Sources */,
039F5508294B6E29004AB940 /* EZAboutViewController.m in Sources */,
969885DB2B5640BB005C8ECB /* GeneralOtherSetting.swift in Sources */,
03D8A6592A42A1A300D9A968 /* EZAppModel.m in Sources */,
036E7D7B293F4FC8002675DF /* EZOpenLinkButton.m in Sources */,
276742092B3DC230002A2C75 /* AboutTab.swift in Sources */,
Expand Down Expand Up @@ -3351,6 +3383,14 @@
minimumVersion = 5.8.1;
};
};
969885D12B564040005C8ECB /* XCRemoteSwiftPackageReference "KeyHolder" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Clipy/KeyHolder.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 4.2.0;
};
};
EA3B81FA2B52555C004C0E8B /* XCRemoteSwiftPackageReference "Defaults" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/sindresorhus/Defaults.git";
Expand Down Expand Up @@ -3437,6 +3477,11 @@
package = 2721E4CE2AFE920700A059AC /* XCRemoteSwiftPackageReference "Alamofire" */;
productName = Alamofire;
};
969885D22B564041005C8ECB /* KeyHolder */ = {
isa = XCSwiftPackageProductDependency;
package = 969885D12B564040005C8ECB /* XCRemoteSwiftPackageReference "KeyHolder" */;
productName = KeyHolder;
};
EA3B81FB2B52555C004C0E8B /* Defaults */ = {
isa = XCSwiftPackageProductDependency;
package = EA3B81FA2B52555C004C0E8B /* XCRemoteSwiftPackageReference "Defaults" */;
Expand Down
37 changes: 32 additions & 5 deletions Easydict.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
"identity" : "alamofire",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/Alamofire",
"location" : "https://github.com/Alamofire/Alamofire.git",
"state" : {
"revision" : "3dc6a42c7727c49bf26508e29b0a0b35f9c7e1ad",
"version" : "5.8.1"
Expand Down Expand Up @@ -50,8 +50,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/krzyzanowskim/CryptoSwift",
"state" : {
"revision" : "db51c407d3be4a051484a141bf0bff36c43d3b1e",
"version" : "1.8.0"
"revision" : "7892a123f7e8d0fe62f9f03728b17bbd4f94df5c",
"version" : "1.8.1"
}
},
{
Expand Down Expand Up @@ -135,6 +135,15 @@
"version" : "100.0.0"
}
},
{
"identity" : "keyholder",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Clipy/KeyHolder.git",
"state" : {
"revision" : "5da0ee06fd8709f7d812504bff1555462a3f6956",
"version" : "4.2.0"
}
},
{
"identity" : "leveldb",
"kind" : "remoteSourceControl",
Expand All @@ -144,6 +153,15 @@
"version" : "1.22.3"
}
},
{
"identity" : "magnet",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Clipy/Magnet",
"state" : {
"revision" : "26d672a031fd33eac94887b4e19aca0ab4761f45",
"version" : "3.4.0"
}
},
{
"identity" : "mjextension",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -198,13 +216,22 @@
"version" : "10.45.2"
}
},
{
"identity" : "sauce",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Clipy/Sauce",
"state" : {
"revision" : "8f8fabaa8509c1a653d6c2c3c87396a4c493d876",
"version" : "2.4.0"
}
},
{
"identity" : "snapkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SnapKit/SnapKit",
"state" : {
"revision" : "f222cbdf325885926566172f6f5f06af95473158",
"version" : "5.6.0"
"revision" : "e74fe2a978d1216c3602b129447c7301573cc2d8",
"version" : "5.7.0"
}
},
{
Expand Down
17 changes: 17 additions & 0 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -2849,6 +2849,23 @@
}
}
},
"shortcut_setting" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Shortcut Setting"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "快捷键设置"
}
}
}
},
"show" : {
"localizations" : {
"en" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// GeneralKeyHolderWrapper.swift
// Easydict
//
// Created by Sharker on 2024/1/2.
// Copyright © 2024 izual. All rights reserved.
//

import AppKit
import KeyHolder
import Magnet
import SwiftUI

struct GeneralKeyHolderWrapper: NSViewRepresentable {
func makeCoordinator() -> Coordinator {
.init()
}

func makeNSView(context: Context) -> some NSView {
let recordView = RecordView(frame: CGRect.zero)
recordView.tintColor = NSColor(red: 0.164, green: 0.517, blue: 0.823, alpha: 1)
recordView.delegate = context.coordinator
recordView.layer?.cornerRadius = 6.0
recordView.layer?.masksToBounds = true
return recordView
}

func updateNSView(_: NSViewType, context _: Context) {}
}

extension GeneralKeyHolderWrapper {
class Coordinator: NSObject, RecordViewDelegate {
func recordViewShouldBeginRecording(_: KeyHolder.RecordView) -> Bool {
true
}

func recordView(_: KeyHolder.RecordView, canRecordKeyCombo _: Magnet.KeyCombo) -> Bool {
true
}

func recordView(_: KeyHolder.RecordView, didChangeKeyCombo _: Magnet.KeyCombo?) {}

func recordViewDidEndRecording(_: KeyHolder.RecordView) {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// GeneralOtherSetting.swift
// Easydict
//
// Created by Sharker on 2024/1/1.
// Copyright © 2024 izual. All rights reserved.
//

import SwiftUI

@available(macOS 13.0, *)
extension GeneralTab {
struct OtherSettingView: View {
var body: some View {
Section {
HStack {
Text("show_main_window")
Toggle(isOn: $hideMainWindow) {
Text("hide_main_window")
}
}
HStack {
Text("launch")
Toggle(isOn: $launchAtStartup) {
Text("launch_at_startup")
}
}
HStack {
Text("menu_bar_icon")
Toggle(isOn: $hideMenuBarIcon) {
Text("hide_menu_bar_icon")
}
}
HStack {
Text("beta_new_app")
Toggle(isOn: $enableBetaNewApp) {
Text("enable_beta_new_app")
}
}
} header: {
Text("other")
}
}

@AppStorage(kHideMainWindowKey) private var hideMainWindow = false
Copy link
Collaborator

@CanglongCl CanglongCl Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can replace this with @Default(.hideMainWindow) private var hideMainWindow. Defaults package can provide global default value setting in UserDefaults management so it is recommended to use it instead of @AppStorage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay I got it

@AppStorage(kLaunchAtStartupKey) private var launchAtStartup = false
@AppStorage(kHideMenuBarIconKey) private var hideMenuBarIcon = false
@AppStorage(kEnableBetaNewAppKey) private var enableBetaNewApp = false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// GeneralShortcutSetting.swift
// Easydict
//
// Created by Sharker on 2024/1/1.
// Copyright © 2024 izual. All rights reserved.
//

import SwiftUI

@available(macOS 13, *)
extension GeneralTab {
struct ShortcutSettingView: View {
var body: some View {
Section {
HStack {
Text("input_translate")
GeneralKeyHolderWrapper()
}
HStack {
Text("snip_translate")
GeneralKeyHolderWrapper()
}
HStack {
Text("select_translate")
GeneralKeyHolderWrapper()
}
HStack {
Text("silent_screenshot_ocr")
GeneralKeyHolderWrapper()
}
} header: {
Text("shortcut_setting")
}
}
}
}