From a8adf60165628167044fce11bdeb9638fa26404c Mon Sep 17 00:00:00 2001 From: Daniel Jalkut Date: Wed, 31 May 2017 15:19:05 -0400 Subject: [PATCH] Generate a placeholder app icon by rendering the Emoji Evergreen glyph. --- Evergreen/AppDelegate.swift | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Evergreen/AppDelegate.swift b/Evergreen/AppDelegate.swift index 8816edd44..4a62eb04b 100644 --- a/Evergreen/AppDelegate.swift +++ b/Evergreen/AppDelegate.swift @@ -40,10 +40,40 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations { super.init() } + private func evergreenImage() -> NSImage? { + var image: NSImage? = nil + let imageWidth = 1024 + let imageHeight = 1024 + let imageSize = NSMakeSize(CGFloat(imageWidth), CGFloat(imageHeight)) + + if let drawingContext = CGContext(data: nil, width: imageWidth, height: imageHeight, bitsPerComponent: 8, bytesPerRow: 0, space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGImageAlphaInfo.premultipliedFirst.rawValue) { + + let graphicsContext = NSGraphicsContext(cgContext: drawingContext, flipped: false) + NSGraphicsContext.saveGraphicsState() + NSGraphicsContext.setCurrent(graphicsContext) + + let targetRect = NSRect(origin: NSZeroPoint, size: imageSize) + NSString(string: "🌲").draw(in: targetRect, withAttributes: [NSFontAttributeName: NSFont.systemFont(ofSize: 1000)]) + + NSGraphicsContext.restoreGraphicsState() + + if let coreImage = drawingContext.makeImage() { + image = NSImage(cgImage: coreImage, size: imageSize) + } + } + + return image + } + // MARK: NSApplicationDelegate func applicationDidFinishLaunching(_ note: Notification) { + if let appIconImage = evergreenImage() { + appIconImage.setName("NSApplicationIcon") + NSApplication.shared().applicationIconImage = appIconImage + } + registerDefaults() currentTheme = themeLoader.defaultTheme