[英]How to Launch a Mac OS App From Safari Extension?
Does anyone know what the replacement for the following legacy extension code block to launch a MacOS app is in the new Safari Extensions? 有谁知道新的Safari扩展程序中用于启动MacOS应用程序的以下旧扩展代码块的替代品?
safari.application.activeBrowserWindow.activeTab.url = "{app_url_scheme}://"
We are currently working on transitioning from a legacy extension to support the newer Safari Extensions framework. 我们目前正在努力从旧版扩展过渡到支持较新的Safari扩展框架。 In the legacy extension we used the following piece code in the global.html file to launch our Mac OS app:
在旧版扩展程序中,我们在global.html文件中使用以下片段代码启动了Mac OS应用程序:
safari.application.activeBrowserWindow.activeTab.url = "{app_url_scheme}://......."
It seems that the comparable code in the new Safari Extension framework would be the following: 新的Safari扩展框架中的可比代码似乎如下:
guard let url = URL(string: "{app_url_scheme}://") else {
return
}
SFSafariApplication.getActiveWindow {(activeWindow: SFSafariWindow?)in
activeWindow?.openTab(with: url, makeActiveIfPossible: false,
completionHandler: { (activeTab: SFSafariTab?) in
print("openTab completed")
})
}
However, while the tab will open just fine if it's something like " https://www.cnn.com ", it won't do anything if it's just "{app_url_scheme}://". 但是,虽然像“ https://www.cnn.com ”这样的标签会很好地打开,但如果只是“ {app_url_scheme}://”,它将不会执行任何操作。 Furthermore, I can type in "{app_url_scheme}://" to the Safari browser and it launches the app just fine, so I know it's not a registration problem.
此外,我可以在Safari浏览器中输入“ {app_url_scheme}://”,这样就可以正常启动该应用程序,因此我知道这不是注册问题。
For anyone stumbling across this in the future, it seems the code to launch a MacOS app would be the following: 对于将来遇到任何麻烦的人来说,启动MacOS应用程序的代码似乎如下:
guard let url = URL(string: "{app_url_scheme}") else {
return
}
NSWorkspace.shared.open(url)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.