Skip to content

Instantly share code, notes, and snippets.

@ospfranco
Created March 24, 2022 15:34
Show Gist options
  • Save ospfranco/b260368c1da4e96f223eb7f2ced0f484 to your computer and use it in GitHub Desktop.
Save ospfranco/b260368c1da4e96f223eb7f2ced0f484 to your computer and use it in GitHub Desktop.
import Cocoa
class _FileIcon: NSView {
let image = NSImageView()
@objc var url: NSString = "" {
didSet {
self.setupView()
}
}
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
private func setupView() {
let icon = NSWorkspace.shared.icon(forFile: self.url as String)
self.image.image = icon
image.autoresizingMask = [.height, .width]
self.addSubview(image)
}
}
@objc (FileIconManager)
class FileIconManager: RCTViewManager {
override static func requiresMainQueueSetup() -> Bool {
return true
}
override func view() -> NSView! {
return _FileIcon()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment