V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
ShikiSuen
V2EX  ›  Apple

写了个脚本侦测 1password 等密码簿是否在全局禁用第三方输入法。

  •  
  •   ShikiSuen · 194 天前 · 709 次点击
    这是一个创建于 194 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这些个密码簿 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
      }
    }
    
    ShikiSuen
        1
    ShikiSuen  
    OP
       194 天前
    License: MIT. Copyright 2023 Shiki Suen 或 Copyright 2023 vChewing Project.
    ShikiSuen
        2
    ShikiSuen  
    OP
       194 天前
    此文也在掘金那边刊出了: https://juejin.cn/post/7291937079877304359
    ShikiSuen
        3
    ShikiSuen  
    OP
       194 天前
    这个脚本有了更新。因为 V2EX 贴文编辑次数有限制,所以请到稀土掘金那边看新版本。
    也可以看 gist: https://gist.github.com/ShikiSuen/493babbcc032c6b9bb6332537051f2cb
    ShikiSuen
        4
    ShikiSuen  
    OP
       193 天前
    这个脚本被我用 IOKit 重写了,让检测过程更加精确。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2388 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:53 · PVG 20:53 · LAX 05:53 · JFK 08:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.