我需要在主/最前面的窗口上显示一个模态对话框,即使该窗口不是我的(即客户端可能正在Chrome上全屏观看视频)。 我怎样才能做到这一点?目前我正在通过设置延迟并在另一个不起作用的应用程序中进行测试(即仅当我切换到应用程序时警报才可见)。 我正在寻求开发一种系统范围的插件,因此它需要是全球性的。
其他详细信息: 我不想将焦点从最前面的应用程序移开。我需要像UserNotification这样的东西,但可以更好地控制UI。用户实际上将使用键盘快捷键激活“菜单”。
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(10), execute: {
// Insert code here to initialize your application
let alert = NSAlert.init()
alert.messageText = "Hello world"
alert.informativeText = "Information text"
alert.addButton(withTitle: "OK")
alert.addButton(withTitle: "Cancel")
alert.runModal()
// Put your code which should be executed with a delay here
})