简体   繁体   English

从 JavaFX 应用程序在 macOS 11 Big Sur 上打开应用程序随机失败并出现 kLSNoExecutableErr

[英]Opening app on macOS 11 Big Sur from JavaFX application randomly fails with kLSNoExecutableErr

We have a desktop JavaFX application (well, TornadoFX) that downloads an archive, extracts another app from it and launches this app with macOS open command.我们有一个桌面 JavaFX 应用程序(嗯,TornadoFX),它下载一个存档,从中提取另一个应用程序并使用 macOS open命令启动这个应用程序。 Simplified kotlin code looks like:简化的 kotlin 代码如下所示:

ProcessBuilder(listOf("open", "/path/to/app.app", "arg")).start()

This has worked for years on older versions of macOS (10.15 and earlier) but now with macOS 11 Big Sur launching the app sometimes succeeds and sometimes fails.这已经在旧版本的 macOS(10.15 和更早版本)上运行了多年,但现在随着 macOS 11 Big Sur 启动应用程序有时会成功,有时会失败。

In the mac Console.app following error can be seen:在 mac Console.app 中可以看到以下错误:

OSStatus _LSCopyApplicationNodeFromOpenState(LSOpenState *): Returning kLSNoExecutableErr because node is a directory but we failed to register with error -10814 OSStatus _LSCopyApplicationNodeFromOpenState(LSOpenState *):返回 kLSNoExecutableErr 因为节点是一个目录,但我们未能注册并出现错误 -10814

We extended the logic to check if all the files are really there before launching the app, and the files existed.我们扩展了逻辑以在启动应用程序之前检查所有文件是否确实存在,并且文件存在。

There is an assumption that maybe Launch Services database is not updated fast enough.假设 Launch Services 数据库更新速度不够快。

Following ways of trying to log what might be happening, didn't reveal any errors:以下尝试记录可能发生的事情的方法没有发现任何错误:

lsappinfo listen +all forever lsappinfo 永远听 +all

log stream --debug --predicate 'subsystem == "com.apple.coreservices.launchservices"'记录 stream --debug --predicate 'subsystem == "com.apple.coreservices.launchservices"'

Does anybody have a clue if there is a way to avoid this behavior and to be always able to launch the app?是否有人知道是否有办法避免这种行为并始终能够启动应用程序?

After a lot of research and debugging, what seem to have worked for us, was to force Launch Services to register the app in its database by executing command like:经过大量研究和调试,似乎对我们有用的是,强制启动服务通过执行以下命令在其数据库中注册应用程序:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f /path/to/app.app /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f /path/to/app.app

and afterwards we could launch the app.然后我们可以启动应用程序。

The idea for such solution was found in this answer.这个答案中找到了这种解决方案的想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM