Skip to content

Commit

Permalink
fix: upate menu crash
Browse files Browse the repository at this point in the history
  • Loading branch information
AkaShark committed Feb 8, 2024
1 parent b338c15 commit 452a30a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 50 deletions.
4 changes: 0 additions & 4 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@
9643D94A2B71EABE000FBEA6 /* KeyHolderAlterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D9492B71EABE000FBEA6 /* KeyHolderAlterView.swift */; };
9643D94C2B71F74D000FBEA6 /* MainMenuShortcutCommandItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D94B2B71F74D000FBEA6 /* MainMenuShortcutCommandItem.swift */; };
9643D9562B73B3CD000FBEA6 /* Shortcut+Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D9552B73B3CD000FBEA6 /* Shortcut+Menu.swift */; };
9643D9592B73BAFD000FBEA6 /* String+Localized.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D9582B73BAFD000FBEA6 /* String+Localized.swift */; };
9672D7D22B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m in Sources */ = {isa = PBXBuildFile; fileRef = 9672D7D12B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m */; };
967712EA2B5B913600105E0F /* KeyHolder in Frameworks */ = {isa = PBXBuildFile; productRef = 967712E92B5B913600105E0F /* KeyHolder */; };
967712EE2B5B943400105E0F /* Shortcut.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967712ED2B5B943400105E0F /* Shortcut.swift */; };
Expand Down Expand Up @@ -809,7 +808,6 @@
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>"; };
9643D9552B73B3CD000FBEA6 /* Shortcut+Menu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Shortcut+Menu.swift"; sourceTree = "<group>"; };
9643D9582B73BAFD000FBEA6 /* String+Localized.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Localized.swift"; 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>"; };
967712ED2B5B943400105E0F /* Shortcut.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shortcut.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1266,7 +1264,6 @@
isa = PBXGroup;
children = (
038A723F2B62C0B9004995E3 /* String+Regex.swift */,
9643D9582B73BAFD000FBEA6 /* String+Localized.swift */,
);
path = String;
sourceTree = "<group>";
Expand Down Expand Up @@ -2933,7 +2930,6 @@
0AC8A8412B695480006DA5CC /* DeepLTranslate+ConfigurableService.swift in Sources */,
039CC90D292F664E0037B91E /* NSObject+EZWindowType.m in Sources */,
03B0232229231FA6001C7E63 /* NSImage+MM.m in Sources */,
9643D9592B73BAFD000FBEA6 /* String+Localized.swift in Sources */,
03BB2DEF29F59C8A00447EDD /* EZSymbolImageButton.m in Sources */,
0A2BA9642B4A3CCD002872A4 /* Notification+Name.swift in Sources */,
C415C0AD2B450D4800A9D231 /* GeminiService.swift in Sources */,
Expand Down
6 changes: 4 additions & 2 deletions Easydict/NewApp/Feature/Shortcut/Shortcut+Menu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import SwiftUI

extension Shortcut {
@available(macOS 13, *)
func updateMenu(_ type: ShortcutType) { // update shortcut menu
let shortcutTitle = LocalizedStringKey(type.localizedStringKey()).stringValue()
let shortcutMenu = NSApp.mainMenu?.items.first(where: { $0.title == "Shortcut" })
let shortcutTitle = String(localized: LocalizedStringResource(stringLiteral: type.localizedStringKey()))
let menuTitle = String(localized: LocalizedStringResource(stringLiteral: "shortcut"))
let shortcutMenu = NSApp.mainMenu?.items.first(where: { $0.title == menuTitle })
let clearInput = shortcutMenu?.submenu?.items.first(where: { $0.title == shortcutTitle })
clearInput?.keyEquivalent = ""
}
Expand Down
37 changes: 0 additions & 37 deletions Easydict/NewApp/Utility/Extensions/String/String+Localized.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public struct KeyHolderDataItem: Identifiable {
var type: ShortcutType
}

@available(macOS 13, *)
struct KeyHolderWrapper: NSViewRepresentable {
func makeCoordinator() -> Coordinator {
.init(shortcutType: type, confictAlterMessage: $confictAlterMessage)
Expand Down Expand Up @@ -44,6 +45,7 @@ struct KeyHolderWrapper: NSViewRepresentable {
func updateNSView(_: NSViewType, context _: Context) {}
}

@available(macOS 13, *)
extension KeyHolderWrapper {
class Coordinator: NSObject, RecordViewDelegate {
private var type: ShortcutType
Expand All @@ -70,14 +72,7 @@ extension KeyHolderWrapper {
if let key = keyCombo {
// shortcut validate confict
if Shortcut.validateShortcut(key) {
if #available(macOS 12, *) {
confictAlterMessage = ShortcutConfictAlertMessage(title: String(localized: "shortcut_confict_title \(keyCombo!.keyEquivalentModifierMaskString + keyCombo!.characters)"), message: String(localized: "shortcut_confict_message \(Shortcut.shared.confictMenuItem?.title ?? "")"))
} else {
// Fallback on earlier versions
let title = NSLocalizedString("shortcut_confict_title \(keyCombo!.keyEquivalentModifierMaskString + keyCombo!.characters)", comment: "")
let msg = NSLocalizedString("shortcut_confict_message \(Shortcut.shared.confictMenuItem?.title ?? "")", comment: "")
confictAlterMessage = ShortcutConfictAlertMessage(title: title, message: msg)
}
recordView.clear()
return
}
Expand Down

0 comments on commit 452a30a

Please sign in to comment.