57 lines
2.0 KiB
Swift
57 lines
2.0 KiB
Swift
/*
|
|
* This file is part of the SDWebImage package.
|
|
* (c) DreamPiggy <lizhuoli1126@126.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
import Cocoa
|
|
import SwiftUI
|
|
import SDWebImage
|
|
import SDWebImageWebPCoder
|
|
import SDWebImageSVGCoder
|
|
import SDWebImagePDFCoder
|
|
|
|
@NSApplicationMain
|
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
|
var window: NSWindow!
|
|
|
|
|
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
|
// Create the SwiftUI view that provides the window contents.
|
|
let contentView = ContentView()
|
|
|
|
// Create the window and set the content view.
|
|
window = NSWindow(
|
|
contentRect: NSRect(x: 0, y: 0, width: 480, height: 300),
|
|
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
|
|
backing: .buffered, defer: false)
|
|
window.center()
|
|
window.setFrameAutosaveName("Main Window")
|
|
window.contentView = NSHostingView(rootView: contentView)
|
|
window.makeKeyAndOrderFront(nil)
|
|
// Add WebP/SVG/PDF support
|
|
SDImageCodersManager.shared.addCoder(SDImageWebPCoder.shared)
|
|
SDImageCodersManager.shared.addCoder(SDImageSVGCoder.shared)
|
|
SDImageCodersManager.shared.addCoder(SDImagePDFCoder.shared)
|
|
// Dynamic check to support vector format for both WebImage/AnimatedImage
|
|
SDWebImageManager.shared.optionsProcessor = SDWebImageOptionsProcessor { url, options, context in
|
|
var options = options
|
|
if let _ = context?[.animatedImageClass] as? SDAnimatedImage.Type {
|
|
// AnimatedImage supports vector rendering, should not force decode
|
|
options.insert(.avoidDecodeImage)
|
|
}
|
|
return SDWebImageOptionsResult(options: options, context: context)
|
|
}
|
|
}
|
|
|
|
func applicationWillTerminate(_ aNotification: Notification) {
|
|
// Insert code here to tear down your application
|
|
}
|
|
|
|
|
|
}
|
|
|