SessionCtl // Temporarily remember the recent 20 clients' Bundle IDs.

This commit is contained in:
ShikiSuen 2023-02-18 22:33:46 +08:00
parent 9fbfe22fa6
commit bb991d0c86
1 changed files with 17 additions and 1 deletions

View File

@ -45,7 +45,23 @@ public class SessionCtl: IMKInputController {
/// bundleIdentifier
///
public var clientBundleIdentifier: String = ""
public var clientBundleIdentifier: String = "" {
willSet {
if newValue.isEmpty { return }
Self.recentClientBundleIdentifiers[newValue] = Int(Date().timeIntervalSince1970)
}
}
///
public static var recentClientBundleIdentifiers = [String: Int]() {
didSet {
if recentClientBundleIdentifiers.count < 20 { return }
if recentClientBundleIdentifiers.isEmpty { return }
let x = recentClientBundleIdentifiers.sorted(by: { $0.value < $1.value }).first?.key
guard let x = x else { return }
recentClientBundleIdentifiers[x] = nil
}
}
// MARK: -