tmandry / Swindler

macOS window management library for Swift
https://tmandry.github.io/Swindler/docs/main/
MIT License
690 stars 66 forks source link

Fixed crashing when forcefully unwrapping running application #85

Open hahaSK opened 2 years ago

hahaSK commented 2 years ago

Hello again 👋,

I used asynchronous execution DispatchQueue.main.async and was getting crashes of forcefully unwrapping of running application so I have removed the unwrapping.

Also Swindler is missing the Appkit import.

tmandry commented 2 years ago

This means the application object won't be fully initialized. Can you elaborate on how you're using Swindler? Initialization already happens asynchronously, there's no need to do that explicitly, just use the future returned by initialize().

hahaSK commented 2 years ago

When my App starts it initialises Swindler and sets the handlers. Later there is a video playing full screen and while the video is playing windows/apps are positioned if necessary. But some app/s cause swindler to crash at that line of code. When I search for the PID that caused the crash (lazy var runningApplication: NSRunningApplication = NSRunningApplication(processIdentifier: self.processIdentifier)!) it is not in running processes -> cannot find the PID. So I think the problem is not caused by the asynchronous calls but by some application or the fact that the video is playing fullscreen while the windows/apps are being positioned. It is hard to find what is the cause of this problem because it happens only like 25% of time. Also I checked the property and it is internal and only thing that uses it is property below lazy var bundleIdentifier: String? = self.runningApplication.bundleIdentifier which is already optional so no API changes required. Just one addition of ?