Embedded WindowController inside XPC module

Is it possible we embed a windowcontroller inside an XPC module and pop/hide the window as demanded? right now the window cannot pop due to not in main thread.

What is the better alternative under the condition that xpc cannot modify the caller for permission.

Displaying UI from an XPC Service is not something I recommend. You can make it work but there’s a bunch of potential pitfalls. The most obvious one is the main run loop. Looking at the xpcservice.plist man page, there are two settings for RunLoopType, dispatch_main and NSRunLoop, neither of which is great for a process displaying UI (you really want to tell XPC to start an NSApplication, but there’s no supported option for that).

What are you trying to do here? Why do you want to display UI from your XPC Service?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I have a somehow related question @eskimo.

Im planning the plugin architecture for my app. I'd like to handle all plugin related operations (more about that below) with the XPC. Right now I'm using the XPC along with the SMLoginItemSetEnabled to launch mini-app that will display image from parent app but the plugin thing is on another level.

For the plugin I have a framework (let's call it the plugin framework) with some classes that the plugin has to inherit from

  • stuff like info about the plugin (identifier, author etc.).
  • plugin has to return a NSWindow subclass (actually a subclass of it).
  • plugin has to return a view that will be used as a preview in my app.

Right now, I'm testing my internal plugins that I load within the app and everything works – I load the bundle, preview are interactive, everything just works. But these are my plugins. So the goal for the new "XPC app" is to act as the middleman between my app and the plugin. The XPC app can load the window provided by the plugin (and I guess I know how to do it, I just have to encode most of the types from my plugin framework) but I don't have any idea what to do about the preview. Because I'd like to load the plugin on the XPC app and then somehow pass the view with the preview to the app.

Any ideas?

then somehow pass the view with the preview to the app.

There is no good way to do this using public API.

The system itself does this a lot using a technology known as remote view. For example, when your app hosts a WKWebView, most of the work is done in a helper process and this remote view technology routes events from your app to that helper process and displays the helper process’s view such that it appears to exist in your app’s view hierarchy. Getting this to work reliably in the general case is staggeringly difficult [1] and probably not possible using public API.

There is, however, progress to be made in specific cases. For example, if your plug-ins only need to draw content that’s displayed in your main app, that’s quite feasible using IOSurface.

So, do you have any constraints that you can apply here? Or do you really need to support everthing that AppKit supports in NSWindow / NSView? ’cause I’d definitely rate the latter as Too Hard™.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] I happen to be friends with the guy who maintains this technology and he has some terrifying war stories (-:

Embedded WindowController inside XPC module
 
 
Q