fix: don't crash when the OS doesn't return an icon
This commit is contained in:
1 parent
14713f0063
commit
ce6f6aa223
2 files changed
+4
-4
No files matched your search
@@ -9,7 +9,7 @@ class OpenWindow {
|
||||
var cgId: CGWindowID
|
||||
var cgTitle: String
|
||||
lazy var thumbnail: NSImage = computeThumbnail()
|
||||
lazy var icon: NSImage = computeIcon()
|
||||
lazy var icon: NSImage? = computeIcon()
|
||||
|
||||
init(target: AXUIElement?, ownerPid: pid_t?, cgId: CGWindowID, cgTitle: String) {
|
||||
self.target = target
|
||||
@@ -18,8 +18,8 @@ class OpenWindow {
|
||||
self.cgTitle = cgTitle
|
||||
}
|
||||
|
||||
func computeIcon() -> NSImage {
|
||||
return NSRunningApplication(processIdentifier: ownerPid!)!.icon!
|
||||
func computeIcon() -> NSImage? {
|
||||
NSRunningApplication(processIdentifier: ownerPid!)?.icon
|
||||
}
|
||||
|
||||
func computeThumbnail() -> NSImage {
|
||||
|
||||
@@ -77,7 +77,7 @@ class Cell: NSCollectionViewItem {
|
||||
thumbnail.image!.size = NSSize(width: width, height: height)
|
||||
thumbnail.frame.size = NSSize(width: width, height: height)
|
||||
icon.image = element.icon
|
||||
icon.image!.size = NSSize(width: Preferences.iconSize!, height: Preferences.iconSize!)
|
||||
icon.image?.size = NSSize(width: Preferences.iconSize!, height: Preferences.iconSize!)
|
||||
icon.frame.size = NSSize(width: Preferences.iconSize!, height: Preferences.iconSize!)
|
||||
text.string = element.cgTitle
|
||||
// workaround: setting string on NSTextView change the font (most likely a Cocoa bug)
|
||||
|
||||
Reference in new issue
Block a user