这些个密码簿 App 真的越来越猖狂了,滥用 SecureEventInput ,完全不把中文用户的打字需求当回事。
理想情况:当且仅当密码输入框处于正在接收文字输入的这种激活状态时,才启用 EnableSecureEventInput()。只要密码输入框是非当前 App 、只要密码输入框失去输入状态,那就应该立刻执行 DisableSecureEventInput(),免得害得整个系统都用不了第三方输入法。
实际情况:欧美厂商设计的这类 App 很难会去主动考虑中文副厂输入法使用者的死活。
我写了一段工具,可以供副厂输入法开发者们集成在输入法内、每隔 15 秒跑一次以自动侦测是否有这个情况。有的话,可以推系统通知告诉使用者「此时输入法因为这个原因在输入法选单当中是灰色的、无法使用」。如果你输入法没有 Sandbox 的话,你还可以直接强制结束对应的密码簿应用。
// (c) 2023 and onwards The vChewing Project (MIT-NTL License).
// ====================
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
import AppKit
extension NSRunningApplication {
private var isPotentalAbuserOfSecureEventInput: Bool {
let condition1 = NSRunningApplication.current != self
var condition2 = false
Self.problemAppKeywords.forEach { theKeyWord in
guard let bID = bundleIdentifier else { return }
if bID.contains(theKeyWord) { condition2 = true }
}
let condition3 = isActive
return condition1 && condition2 && condition3
}
private var isSecurityAgentInTheBackground: Bool {
let condition1 = NSRunningApplication.current != self
let condition2 = bundleIdentifier == "com.apple.SecurityAgent"
return condition1 && condition2
}
private static let problemAppKeywords: [String] = [
"com.agilebits.onepassword",
"com.bitwarden.",
]
public static func findSecureEventInputAbusers() -> NSRunningApplication? {
var isSecurityAgentInTheBackground = false
var matchedApp: NSRunningApplication? = nil
NSWorkspace.shared.runningApplications.forEach { theApp in
if theApp.isPotentalAbuserOfSecureEventInput {
matchedApp = theApp
}
if theApp.isSecurityAgentInTheBackground {
isSecurityAgentInTheBackground = true
}
}
return isSecurityAgentInTheBackground ? matchedApp : nil
}
}
1
ShikiSuen OP License: MIT. Copyright 2023 Shiki Suen 或 Copyright 2023 vChewing Project.
|
2
ShikiSuen OP 此文也在掘金那边刊出了: https://juejin.cn/post/7291937079877304359
|
3
ShikiSuen OP 这个脚本有了更新。因为 V2EX 贴文编辑次数有限制,所以请到稀土掘金那边看新版本。
也可以看 gist: https://gist.github.com/ShikiSuen/493babbcc032c6b9bb6332537051f2cb |
4
ShikiSuen OP 这个脚本被我用 IOKit 重写了,让检测过程更加精确。
|