diff --git a/SecretAgent/Notifier.swift b/SecretAgent/Notifier.swift index 1f12f98..ace969d 100644 --- a/SecretAgent/Notifier.swift +++ b/SecretAgent/Notifier.swift @@ -2,6 +2,7 @@ import Foundation import SecretKit import SecretAgentKit import UserNotifications +import AppKit class Notifier { @@ -14,14 +15,34 @@ class Notifier { func notify(accessTo secret: AnySecret, by provenance: SigningRequestProvenance) { let notificationCenter = UNUserNotificationCenter.current() let notificationContent = UNMutableNotificationContent() - notificationContent.title = "Signed Request" - notificationContent.body = "\(secret.name) was used to sign a request from \(provenance.origin.name)." + notificationContent.title = "Signed Request from \(provenance.origin.name)" + notificationContent.subtitle = secret.name + if let iconURL = iconURL(for: provenance), let attachment = try? UNNotificationAttachment(identifier: "icon", url: iconURL, options: nil) { + notificationContent.attachments = [attachment] + } let request = UNNotificationRequest(identifier: UUID().uuidString, content: notificationContent, trigger: nil) notificationCenter.add(request, withCompletionHandler: nil) } } +extension Notifier { + + func iconURL(for provenance: SigningRequestProvenance) -> URL? { + do { + if let app = NSRunningApplication(processIdentifier: provenance.origin.pid), let icon = app.icon?.tiffRepresentation { + let temporaryURL = URL(fileURLWithPath: (NSTemporaryDirectory() as NSString).appendingPathComponent("\(UUID().uuidString).png")) + let bitmap = NSBitmapImageRep(data: icon) + try bitmap?.representation(using: .png, properties: [:])?.write(to: temporaryURL) + return temporaryURL + } + } catch { + } + return nil + } + +} + extension Notifier: SigningWitness { func speakNowOrForeverHoldYourPeace(forAccessTo secret: AnySecret, by provenance: SigningRequestProvenance) throws { diff --git a/SecretAgent/Untitled.png b/SecretAgent/Untitled.png new file mode 100644 index 0000000..c562de7 Binary files /dev/null and b/SecretAgent/Untitled.png differ diff --git a/Secretive.xcodeproj/project.pbxproj b/Secretive.xcodeproj/project.pbxproj index 6878c8b..866bef1 100644 --- a/Secretive.xcodeproj/project.pbxproj +++ b/Secretive.xcodeproj/project.pbxproj @@ -28,6 +28,7 @@ 50617DD223FCEFA90099B055 /* PreviewStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50617DD123FCEFA90099B055 /* PreviewStore.swift */; }; 506772C72424784600034DED /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 506772C62424784600034DED /* Credits.rtf */; }; 506772C92425BB8500034DED /* NoStoresView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 506772C82425BB8500034DED /* NoStoresView.swift */; }; + 506772CB2426CCC200034DED /* Untitled.png in Resources */ = {isa = PBXBuildFile; fileRef = 506772CA2426CCC200034DED /* Untitled.png */; }; 5068389E241471CD00F55094 /* SecretStoreList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5068389D241471CD00F55094 /* SecretStoreList.swift */; }; 506838A12415EA5600F55094 /* AnySecret.swift in Sources */ = {isa = PBXBuildFile; fileRef = 506838A02415EA5600F55094 /* AnySecret.swift */; }; 506838A32415EA5D00F55094 /* AnySecretStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 506838A22415EA5D00F55094 /* AnySecretStore.swift */; }; @@ -203,6 +204,7 @@ 50617DD123FCEFA90099B055 /* PreviewStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewStore.swift; sourceTree = ""; }; 506772C62424784600034DED /* Credits.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = ""; }; 506772C82425BB8500034DED /* NoStoresView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoStoresView.swift; sourceTree = ""; }; + 506772CA2426CCC200034DED /* Untitled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Untitled.png; sourceTree = ""; }; 5068389D241471CD00F55094 /* SecretStoreList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecretStoreList.swift; sourceTree = ""; }; 506838A02415EA5600F55094 /* AnySecret.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnySecret.swift; sourceTree = ""; }; 506838A22415EA5D00F55094 /* AnySecretStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnySecretStore.swift; sourceTree = ""; }; @@ -507,6 +509,7 @@ children = ( 50020BAF24064869003D4025 /* AppDelegate.swift */, 5018F54E24064786002EB505 /* Notifier.swift */, + 506772CA2426CCC200034DED /* Untitled.png */, 50A3B79024026B7600D209EA /* Assets.xcassets */, 50A3B79524026B7600D209EA /* Main.storyboard */, 50A3B79824026B7600D209EA /* Info.plist */, @@ -790,6 +793,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 506772CB2426CCC200034DED /* Untitled.png in Resources */, 50A3B79724026B7600D209EA /* Main.storyboard in Resources */, 50A3B79424026B7600D209EA /* Preview Assets.xcassets in Resources */, 50A3B79124026B7600D209EA /* Assets.xcassets in Resources */, diff --git a/Secretive/AppDelegate.swift b/Secretive/AppDelegate.swift index 2e6096c..18dc39e 100644 --- a/Secretive/AppDelegate.swift +++ b/Secretive/AppDelegate.swift @@ -66,7 +66,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { @IBAction func runSetup(sender: AnyObject?) { let setupWindow = NSWindow( - contentRect: NSRect(x: 0, y: 0, width: 480, height: 300), + contentRect: NSRect(x: 0, y: 0, width: 00, height: 00), styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView], backing: .buffered, defer: false) let setupView = SetupView() { success in @@ -74,6 +74,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { self.agentStatusChecker.check() } setupWindow.contentView = NSHostingView(rootView: setupView) + setupWindow.setContentSize(setupWindow.contentView!.fittingSize) window.beginSheet(setupWindow, completionHandler: nil) }