From e08dafcf5f3b032aedc929f7bab784f9105e8f6e Mon Sep 17 00:00:00 2001 From: aj-rosado <109146700+aj-rosado@users.noreply.github.com> Date: Thu, 13 Apr 2023 14:30:45 +0100 Subject: [PATCH] [PM-1608] Changed safari extension save dialog (#5127) * PS-1608 - Changed safari extension save dialog * PM-1608 moved setActivationPolicy to constructor --- .../safari/SafariWebExtensionHandler.swift | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/apps/browser/src/safari/safari/SafariWebExtensionHandler.swift b/apps/browser/src/safari/safari/SafariWebExtensionHandler.swift index 5a12da3a02..80ea214b4b 100644 --- a/apps/browser/src/safari/safari/SafariWebExtensionHandler.swift +++ b/apps/browser/src/safari/safari/SafariWebExtensionHandler.swift @@ -8,6 +8,11 @@ let ServiceNameBiometric = ServiceName + "_biometric" class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling { + override init() { + super.init(); + NSApplication.shared.setActivationPolicy(.accessory) + } + func beginRequest(with context: NSExtensionContext) { let item = context.inputItems[0] as! NSExtensionItem let message = item.userInfo?[SFExtensionMessageKey] as AnyObject? @@ -54,24 +59,24 @@ class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling { guard let data = blobData else { return } + let panel = NSSavePanel() - panel.isFloatingPanel = true panel.canCreateDirectories = true panel.nameFieldStringValue = dlMsg.fileName - panel.begin { response in - if response == NSApplication.ModalResponse.OK { - if let url = panel.url { - do { - let fileManager = FileManager.default - if !fileManager.fileExists(atPath: url.absoluteString) { - fileManager.createFile(atPath: url.absoluteString, contents: Data(), - attributes: nil) - } - try data.write(to: url) - } catch { - print(error) - NSLog("ERROR in downloadFile, \(error)") + let response = panel.runModal(); + + if response == NSApplication.ModalResponse.OK { + if let url = panel.url { + do { + let fileManager = FileManager.default + if !fileManager.fileExists(atPath: url.absoluteString) { + fileManager.createFile(atPath: url.absoluteString, contents: Data(), + attributes: nil) } + try data.write(to: url) + } catch { + print(error) + NSLog("ERROR in downloadFile, \(error)") } } }