Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get NSView or NSWindow? #31

Open
humbleCoder1990 opened this issue Nov 1, 2021 · 3 comments
Open

How to get NSView or NSWindow? #31

humbleCoder1990 opened this issue Nov 1, 2021 · 3 comments

Comments

@humbleCoder1990
Copy link

I want to get current NSView or NSWindow.
Is it possible?

@lukaskollmer
Copy link
Owner

Not sure what you mean, tbh. It seems to me like that's something that would fall into the scope of AppKit, rather than this library.

@Lijian1122
Copy link

I want to get current NSView or NSWindow.
Is it possible?

Have you reslove this problem? Do you know the method , thanks

@shirakaba
Copy link

This is essentially how you'd do it:

// Import AppKit to get access to its symbols (like NSApplication)
const objc = require('objc');
objc.import('AppKit');

// Once the application has started, and a window is available, you
// can get a reference to it like this:
const mainWindow = objc.NSApplication.sharedApplication().mainWindow();

For an example of starting up an application from scratch, see #43 (where I actually initialise the NSWindow myself, so getting a reference to it is easy).

If you want to control an already-running app using this (which it seems many Electron users do), I have no idea whether that's even possible (if nothing else due to macOS sandboxing apps from each other). It would be easiest to start up and manage the entire app using this framework rather than attach to an existing one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants