-
Notifications
You must be signed in to change notification settings - Fork 391
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7d9ad15
feat: add keyholder 3rd package
AkaShark 69dc6fb
feat: add shortcut section view
AkaShark 4612e2c
feat: add keyholder UI
AkaShark a6e649d
feat: setting shortcut UI finish
AkaShark 32141ee
Merge branch 'dev' into shortcut
AkaShark 419f851
chore: merge error
AkaShark cea4cda
feat: keyholder wrapper
AkaShark 62e6e9a
Merge branch 'dev' into shortcut
AkaShark 23c4a4c
chore: merge
AkaShark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
Easydict/NewApp/View/SettingView/Tabs/View/Genearl/GeneralKeyHolderWrapper.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) {} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
Easydict/NewApp/View/SettingView/Tabs/View/Genearl/GeneralOtherSetting.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
@AppStorage(kLaunchAtStartupKey) private var launchAtStartup = false | ||
@AppStorage(kHideMenuBarIconKey) private var hideMenuBarIcon = false | ||
@AppStorage(kEnableBetaNewAppKey) private var enableBetaNewApp = false | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Easydict/NewApp/View/SettingView/Tabs/View/Genearl/GeneralShortcutSetting.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay I got it