mirror of
https://github.com/insidegui/VirtualBuddy.git
synced 2026-12-02 15:29:22 +08:00
29 lines
843 B
Swift
29 lines
843 B
Swift
import Cocoa
|
|
|
|
public extension VBVirtualMachine {
|
|
|
|
var screenshot: NSImage? {
|
|
guard let imageData = metadataContents(VBVirtualMachine.screenshotFileName) ?? metadataContents(VBVirtualMachine._legacyScreenshotFileName) else { return nil }
|
|
return NSImage(data: imageData)
|
|
}
|
|
|
|
func thumbnailImage() -> NSImage? {
|
|
guard let thumbnailURL = try? metadataFileURL(Self.thumbnailFileName) else { return nil }
|
|
|
|
if let existingImage = NSImage(contentsOf: thumbnailURL) {
|
|
return existingImage
|
|
}
|
|
|
|
return try? screenshot?.vb_createThumbnail(at: thumbnailURL)
|
|
}
|
|
|
|
func invalidateThumbnail() throws {
|
|
try deleteMetadataFile(named: Self.thumbnailFileName)
|
|
|
|
DispatchQueue.main.async {
|
|
self.didInvalidateThumbnail.send()
|
|
}
|
|
}
|
|
|
|
}
|