Skip to content

Commit

Permalink
Revert #395 and implement with alter method (#398)
Browse files Browse the repository at this point in the history
* fix: default value in short cut

* refactor: delete unused file

* Revert "refactor: delete unused file"

This reverts commit 3a2d734.

* Revert "fix: default value in short cut"

This reverts commit fdfe495.

* Add default shortcut

* split `setDefaultForAppShortcut` into 2 method

* fix: default value in short cut

* refactor: delete unused file

* Revert "refactor: delete unused file"

This reverts commit 3a2d734.

* Revert "fix: default value in short cut"

This reverts commit fdfe495.

* Add default shortcut

* split `setDefaultForAppShortcut` into 2 method

* Revert "chore: update issue templates"

This reverts commit 033e391.

* fix: correct default global shortcut keys

---------

Co-authored-by: tisfeng <[email protected]>
  • Loading branch information
CanglongCl and tisfeng authored Feb 13, 2024
1 parent 033e391 commit 319fc48
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 26 deletions.
4 changes: 1 addition & 3 deletions .github/ISSUE_TEMPLATE/cn_bug_report_zh.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 反馈问题
description: 反馈问题
title: "🐞 反馈问题:请填写标题,不要留空"
title: "🐞 反馈问题:{{请填写标题,不要留空}}"
labels: ["bug"]

body:
Expand All @@ -9,8 +9,6 @@ body:
attributes:
label: 请先确认以下事项:
options:
- label: 请务必查看 [常见问题](https://github.com/tisfeng/Easydict/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98)
required: true
- label: 已仔细阅读了 [README](https://github.com/tisfeng/Easydict#readme)
required: true
- label: 在 [issues](https://github.com/tisfeng/Easydict/issues) 页面搜索过问题(包括已关闭的 issue),但未能找到解决方法
Expand Down
4 changes: 1 addition & 3 deletions .github/ISSUE_TEMPLATE/en_bug_report.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Bug report
description: Report an issue
title: "🐞 Bug Report: Please fill in the title, don't leave it blank"
title: "🐞 Bug Report: {{Please fill in the title, don't leave it blank}} "
labels: ["bug"]

body:
Expand All @@ -9,8 +9,6 @@ body:
attributes:
label: "Please confirm the following:"
options:
- label: Be sure to check out [FAQ](https://github.com/tisfeng/Easydict/wiki/FAQ)
required: true
- label: I have carefully read the [README](https://github.com/tisfeng/Easydict#readme)
required: true
- label: I have searched through the [issues](https://github.com/tisfeng/Easydict/issues) page but couldn't find a solution.(Including issue that has been closed)
Expand Down
4 changes: 4 additions & 0 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
9643D93D2B6F829C000FBEA6 /* MainMenuCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D93C2B6F829C000FBEA6 /* MainMenuCommand.swift */; };
9643D9402B6FC426000FBEA6 /* MainMenuShortcutCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D93F2B6FC426000FBEA6 /* MainMenuShortcutCommand.swift */; };
9643D9422B6FE4AF000FBEA6 /* Shortcut+Bind.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D9412B6FE4AF000FBEA6 /* Shortcut+Bind.swift */; };
9643D9442B6FEF5F000FBEA6 /* Shortcut+Default.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D9432B6FEF5F000FBEA6 /* Shortcut+Default.swift */; };
9643D9462B71D103000FBEA6 /* KeyHolderRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D9452B71D103000FBEA6 /* KeyHolderRowView.swift */; };
9643D94A2B71EABE000FBEA6 /* KeyHolderAlterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D9492B71EABE000FBEA6 /* KeyHolderAlterView.swift */; };
9643D94C2B71F74D000FBEA6 /* MainMenuShortcutCommandItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D94B2B71F74D000FBEA6 /* MainMenuShortcutCommandItem.swift */; };
Expand Down Expand Up @@ -802,6 +803,7 @@
9643D93C2B6F829C000FBEA6 /* MainMenuCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenuCommand.swift; sourceTree = "<group>"; };
9643D93F2B6FC426000FBEA6 /* MainMenuShortcutCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenuShortcutCommand.swift; sourceTree = "<group>"; };
9643D9412B6FE4AF000FBEA6 /* Shortcut+Bind.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Shortcut+Bind.swift"; sourceTree = "<group>"; };
9643D9432B6FEF5F000FBEA6 /* Shortcut+Default.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Shortcut+Default.swift"; sourceTree = "<group>"; };
9643D9452B71D103000FBEA6 /* KeyHolderRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyHolderRowView.swift; sourceTree = "<group>"; };
9643D9492B71EABE000FBEA6 /* KeyHolderAlterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyHolderAlterView.swift; sourceTree = "<group>"; };
9643D94B2B71F74D000FBEA6 /* MainMenuShortcutCommandItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenuShortcutCommandItem.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2270,6 +2272,7 @@
isa = PBXGroup;
children = (
967712ED2B5B943400105E0F /* Shortcut.swift */,
9643D9432B6FEF5F000FBEA6 /* Shortcut+Default.swift */,
9643D9412B6FE4AF000FBEA6 /* Shortcut+Bind.swift */,
9608354F2B6791F200C6A931 /* Shortcut+Validator.swift */,
9643D9552B73B3CD000FBEA6 /* Shortcut+Menu.swift */,
Expand Down Expand Up @@ -3000,6 +3003,7 @@
03BDA7B92A26DA280079D04F /* NSProcessInfo+XPMArgumentParser.m in Sources */,
03542A4F2937B64B00C34C33 /* EZYoudaoOCRResponse.m in Sources */,
03B0233929231FA6001C7E63 /* MMTool.m in Sources */,
9643D9442B6FEF5F000FBEA6 /* Shortcut+Default.swift in Sources */,
03542A552937B7DE00C34C33 /* EZError.m in Sources */,
17BCAEF72B0DFF9000A7D372 /* EZNiuTransTranslateResponse.m in Sources */,
03BDA7B82A26DA280079D04F /* XPMValuedArgument.m in Sources */,
Expand Down
46 changes: 26 additions & 20 deletions Easydict/NewApp/Configuration/Configuration+Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import Defaults
import Foundation
import Magnet

/// Utils
extension Defaults.Keys {
/// is first launch
static let firstLaunch = Key<Bool>("EZConfiguration_kFirstLaunch", default: true)
}

// Setting
extension Defaults.Keys {
// rename `from`
Expand Down Expand Up @@ -172,26 +178,26 @@ extension Defaults.Keys {
/// shortcut
extension Defaults.Keys {
// Global
static let selectionShortcut = Key<KeyCombo?>("EZSelectionShortcutKey_keyHolder", default: KeyCombo(key: .d, cocoaModifiers: .option))
static let snipShortcut = Key<KeyCombo?>("EZSnipShortcutKey_keyHolder", default: KeyCombo(key: .s, cocoaModifiers: .option))
static let inputShortcut = Key<KeyCombo?>("EZInputShortcutKey_keyHolder", default: KeyCombo(key: .a, cocoaModifiers: .option))
static let screenshotOCRShortcut = Key<KeyCombo?>("EZScreenshotOCRShortcutKey_keyHolder", default: KeyCombo(key: .f, cocoaModifiers: [.option, .shift]))
static let showMiniWindowShortcut = Key<KeyCombo?>("EZShowMiniShortcutKey_keyHolder", default: KeyCombo(key: .s, cocoaModifiers: .option))
static let selectionShortcut = Key<KeyCombo?>("EZSelectionShortcutKey_keyHolder")
static let snipShortcut = Key<KeyCombo?>("EZSnipShortcutKey_keyHolder")
static let inputShortcut = Key<KeyCombo?>("EZInputShortcutKey_keyHolder")
static let screenshotOCRShortcut = Key<KeyCombo?>("EZScreenshotOCRShortcutKey_keyHolder")
static let showMiniWindowShortcut = Key<KeyCombo?>("EZShowMiniShortcutKey_keyHolder")

// App
static let clearInputShortcut = Key<KeyCombo?>("EZClearInputShortcutKey_keyHolder", default: KeyCombo(key: .k, cocoaModifiers: .command))
static let clearAllShortcut = Key<KeyCombo?>("EZClearAllShortcutKey_keyHolder", default: KeyCombo(key: .k, cocoaModifiers: [.command, .shift]))
static let copyShortcut = Key<KeyCombo?>("EZCopyShortcutKey_keyHolder", default: KeyCombo(key: .c, cocoaModifiers: [.command, .shift]))
static let copyFirstResultShortcut = Key<KeyCombo?>("EZCopyFirstResultShortcutKey_keyHolder", default: KeyCombo(key: .j, cocoaModifiers: [.command, .shift]))
static let focusShortcut = Key<KeyCombo?>("EZFocusShortcutKey_keyHolder", default: KeyCombo(key: .i, cocoaModifiers: .command))
static let playShortcut = Key<KeyCombo?>("EZPlayShortcutKey_keyHolder", default: KeyCombo(key: .s, cocoaModifiers: .command))
static let retryShortcut = Key<KeyCombo?>("EZRetryShortcutKey_keyHolder", default: KeyCombo(key: .r, cocoaModifiers: .command))
static let toggleShortcut = Key<KeyCombo?>("EZToggleShortcutKey_keyHolder", default: KeyCombo(key: .t, cocoaModifiers: .command))
static let pinShortcut = Key<KeyCombo?>("EZPinShortcutKey_keyHolder", default: KeyCombo(key: .p, cocoaModifiers: .command))
static let hideShortcut = Key<KeyCombo?>("EZHideShortcutKey_keyHolder", default: KeyCombo(key: .y, cocoaModifiers: .command))
static let increaseFontSize = Key<KeyCombo?>("EZIncreaseFontSizeShortcutKey_keyHolder", default: KeyCombo(key: .keypadPlus, cocoaModifiers: .command))
static let decreaseFontSize = Key<KeyCombo?>("EZDecreaseFontSizeShortcutKey_keyHolder", default: KeyCombo(key: .keypadMinus, cocoaModifiers: .command))
static let googleShortcut = Key<KeyCombo?>("EZGoogleShortcutKey_keyHolder", default: KeyCombo(key: .return, cocoaModifiers: .command))
static let eudicShortcut = Key<KeyCombo?>("EZEudicShortcutKey_keyHolder", default: KeyCombo(key: .return, cocoaModifiers: [.command, .shift]))
static let appleDictionaryShortcut = Key<KeyCombo?>("EZAppleDictionaryShortcutKey_keyHolder", default: KeyCombo(key: .d, cocoaModifiers: [.command, .shift]))
static let clearInputShortcut = Key<KeyCombo?>("EZClearInputShortcutKey_keyHolder")
static let clearAllShortcut = Key<KeyCombo?>("EZClearAllShortcutKey_keyHolder")
static let copyShortcut = Key<KeyCombo?>("EZCopyShortcutKey_keyHolder")
static let copyFirstResultShortcut = Key<KeyCombo?>("EZCopyFirstResultShortcutKey_keyHolder")
static let focusShortcut = Key<KeyCombo?>("EZFocusShortcutKey_keyHolder")
static let playShortcut = Key<KeyCombo?>("EZPlayShortcutKey_keyHolder")
static let retryShortcut = Key<KeyCombo?>("EZRetryShortcutKey_keyHolder")
static let toggleShortcut = Key<KeyCombo?>("EZToggleShortcutKey_keyHolder")
static let pinShortcut = Key<KeyCombo?>("EZPinShortcutKey_keyHolder")
static let hideShortcut = Key<KeyCombo?>("EZHideShortcutKey_keyHolder")
static let increaseFontSize = Key<KeyCombo?>("EZIncreaseFontSizeShortcutKey_keyHolder")
static let decreaseFontSize = Key<KeyCombo?>("EZDecreaseFontSizeShortcutKey_keyHolder")
static let googleShortcut = Key<KeyCombo?>("EZGoogleShortcutKey_keyHolder")
static let eudicShortcut = Key<KeyCombo?>("EZEudicShortcutKey_keyHolder")
static let appleDictionaryShortcut = Key<KeyCombo?>("EZAppleDictionaryShortcutKey_keyHolder")
}
46 changes: 46 additions & 0 deletions Easydict/NewApp/Feature/Shortcut/Shortcut+Default.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Shortcut+Default.swift
// Easydict
//
// Created by Sharker on 2024/2/5.
// Copyright © 2024 izual. All rights reserved.
//

import Defaults
import Magnet

extension Shortcut {
// set defalut for app shortcut
func setDefaultForShortcut() {
setDefaultForGlobalShortcut()
setDefaultForAppShortcut()
}

private func setDefaultForGlobalShortcut() {
Defaults[.inputShortcut] = KeyCombo(key: .a, cocoaModifiers: .option)
Defaults[.snipShortcut] = KeyCombo(key: .s, cocoaModifiers: .option)
Defaults[.selectionShortcut] = KeyCombo(key: .d, cocoaModifiers: .option)
Defaults[.showMiniWindowShortcut] = KeyCombo(key: .f, cocoaModifiers: .option)
Defaults[.screenshotOCRShortcut] = KeyCombo(key: .s, cocoaModifiers: [.option, .shift])
}

private func setDefaultForAppShortcut() {
setDefaultForGlobalShortcut()

Defaults[.clearInputShortcut] = KeyCombo(key: .k, cocoaModifiers: .command)
Defaults[.clearAllShortcut] = KeyCombo(key: .k, cocoaModifiers: [.command, .shift])
Defaults[.copyShortcut] = KeyCombo(key: .c, cocoaModifiers: [.command, .shift])
Defaults[.copyFirstResultShortcut] = KeyCombo(key: .j, cocoaModifiers: [.command, .shift])
Defaults[.focusShortcut] = KeyCombo(key: .i, cocoaModifiers: .command)
Defaults[.playShortcut] = KeyCombo(key: .s, cocoaModifiers: .command)
Defaults[.retryShortcut] = KeyCombo(key: .r, cocoaModifiers: .command)
Defaults[.toggleShortcut] = KeyCombo(key: .t, cocoaModifiers: .command)
Defaults[.pinShortcut] = KeyCombo(key: .p, cocoaModifiers: .command)
Defaults[.hideShortcut] = KeyCombo(key: .y, cocoaModifiers: .command)
Defaults[.increaseFontSize] = KeyCombo(key: .keypadPlus, cocoaModifiers: .command)
Defaults[.decreaseFontSize] = KeyCombo(key: .keypadMinus, cocoaModifiers: .command)
Defaults[.googleShortcut] = KeyCombo(key: .return, cocoaModifiers: .command)
Defaults[.eudicShortcut] = KeyCombo(key: .return, cocoaModifiers: [.command, .shift])
Defaults[.appleDictionaryShortcut] = KeyCombo(key: .d, cocoaModifiers: [.command, .shift])
}
}
8 changes: 8 additions & 0 deletions Easydict/NewApp/Feature/Shortcut/Shortcut.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ class Shortcut: NSObject {
@objc static func setupShortcut() {
let shortcut = Shortcut.shared
shortcut.restoreShortcut()

if Defaults[.firstLaunch] {
Defaults[.firstLaunch] = false
// set defalut for app shortcut
shortcut.setDefaultForShortcut()
} else {
// do nothing
}
}

// Make sure the class has only one instance
Expand Down

0 comments on commit 319fc48

Please sign in to comment.