First try making a new window in code like here: How do I create a Cocoa window programmatically?
And wrap all the code to run in the main thread.
This worked for me:
MyDialog (NSWindowController)
@interface MyDialog : NSWindowController
- (instancetype)initWithFrame:(NSRect)frame;
- (void)runModal;
@end
@implementation MyDialog
- (instancetype)initWithFrame:(NSRect)frame {
NSWindowStyleMask windowMask = NSWindowStyleMaskTitled
| NSWindowStyleMaskClosable | NSWindowStyleMaskResizable;
NSWindow *window = [[NSWindow alloc] initWithContentRect:frame
styleMask:windowMask
backing:NSBackingStoreBuffered
defer:NO];
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(windowWillClose:)
name:NSWindowWillCloseNotification
object:nil];
return [super initWithWindow:window];
}
- (void)dealloc {
[NSNotificationCenter.defaultCenter removeObserver:self];
}
- (void)runModal {
[[NSApplication sharedApplication] runModalForWindow:self.window];
}
- (void)windowWillClose:(NSNotification *)notification {
[[NSApplication sharedApplication] stopModal];
}
@end
Inside presenting function:
[NSOperationQueue.mainQueue addOperationWithBlock:^{
NSRect frame = NSMakeRect(0, 0, 200, 200);
MyDialog *dialog = [[MyDialog alloc] initWithFrame:frame];
[dialog runModal];
NSLog(@"done");
}];
If that works, you can probably achieve the same result with a help of your Window.xib, but you need to make sure that the corresponding Window.nib file (a compiled xib) is present and it is possible to find it in runtime from your plugin. If you place this file somewhere in plugin resources, you could use initWithWindowNibPath:
to specify the full path to it.