From b6ecdcd0ead210d9c28a69643d33f6313501d441 Mon Sep 17 00:00:00 2001 From: True Zhuanjia Date: Wed, 24 Jul 2024 19:29:52 +0800 Subject: [PATCH] make key mapping static --- Limelight/Input/CommandManager.swift | 10 ++++++---- .../ViewControllers/CommandManagerViewController.swift | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Limelight/Input/CommandManager.swift b/Limelight/Input/CommandManager.swift index b8f15107..53e459b2 100644 --- a/Limelight/Input/CommandManager.swift +++ b/Limelight/Input/CommandManager.swift @@ -40,8 +40,7 @@ import UIKit @objc public class CommandManager: NSObject { @objc public static let shared = CommandManager() - private var commands: [RemoteCommand] = [] - private let keyMappings: [String: UInt16] = [ + static let keyMappings: [String: UInt16] = [ "CTRL": 0x11, "ALT": 0x12, "DEL": 0x2E, @@ -49,6 +48,8 @@ import UIKit "F2": 0x71 ] + private var commands: [RemoteCommand] = [] + public weak var viewController: CommandManagerViewController? private override init() { @@ -57,12 +58,12 @@ import UIKit } @objc public func createTestKeyMappings() -> [String: UInt16] { - return keyMappings + return CommandManager.keyMappings } // extractKeyStrings from keyboardCMDString @objc public func extractKeyStrings(from input: String) -> [String]? { - let keys = keyMappings.keys.joined(separator: "|") + let keys = CommandManager.keyMappings.keys.joined(separator: "|") let pattern = "^(?:(\(keys))(?:\\+(\(keys))*)*)$" guard let regex = try? NSRegularExpression(pattern: pattern, options: []) else { @@ -78,6 +79,7 @@ import UIKit let matchedString = (input as NSString).substring(with: match.range(at: 0)) let keyStrings = matchedString.split(separator: "+").map { String($0) } + guard !keyStrings.isEmpty else { print("No key strings found in the matched string") return nil diff --git a/Limelight/ViewControllers/CommandManagerViewController.swift b/Limelight/ViewControllers/CommandManagerViewController.swift index 8e79ca18..3e54eb04 100644 --- a/Limelight/ViewControllers/CommandManagerViewController.swift +++ b/Limelight/ViewControllers/CommandManagerViewController.swift @@ -199,7 +199,6 @@ import UIKit if let indexPath = previouslySelectedIndexPath { // Make sure the indexPath is still valid and scroll to the selected indexPath if indexPath.row < tableView.numberOfRows(inSection: indexPath.section) { - print("scrollToRow") tableView.selectRow(at: indexPath, animated: true, scrollPosition: .middle) // keep the entry of previous index selected. } }