[PM-1608] Changed safari extension save dialog (#5127)

* PS-1608 - Changed safari extension save dialog

* PM-1608 moved setActivationPolicy to constructor
This commit is contained in:
aj-rosado 2023-04-13 14:30:45 +01:00 committed by GitHub
parent 3300a4cc15
commit e08dafcf5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 14 deletions

View File

@ -8,6 +8,11 @@ let ServiceNameBiometric = ServiceName + "_biometric"
class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling { class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
override init() {
super.init();
NSApplication.shared.setActivationPolicy(.accessory)
}
func beginRequest(with context: NSExtensionContext) { func beginRequest(with context: NSExtensionContext) {
let item = context.inputItems[0] as! NSExtensionItem let item = context.inputItems[0] as! NSExtensionItem
let message = item.userInfo?[SFExtensionMessageKey] as AnyObject? let message = item.userInfo?[SFExtensionMessageKey] as AnyObject?
@ -54,24 +59,24 @@ class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
guard let data = blobData else { guard let data = blobData else {
return return
} }
let panel = NSSavePanel() let panel = NSSavePanel()
panel.isFloatingPanel = true
panel.canCreateDirectories = true panel.canCreateDirectories = true
panel.nameFieldStringValue = dlMsg.fileName panel.nameFieldStringValue = dlMsg.fileName
panel.begin { response in let response = panel.runModal();
if response == NSApplication.ModalResponse.OK {
if let url = panel.url { if response == NSApplication.ModalResponse.OK {
do { if let url = panel.url {
let fileManager = FileManager.default do {
if !fileManager.fileExists(atPath: url.absoluteString) { let fileManager = FileManager.default
fileManager.createFile(atPath: url.absoluteString, contents: Data(), if !fileManager.fileExists(atPath: url.absoluteString) {
attributes: nil) fileManager.createFile(atPath: url.absoluteString, contents: Data(),
} attributes: nil)
try data.write(to: url)
} catch {
print(error)
NSLog("ERROR in downloadFile, \(error)")
} }
try data.write(to: url)
} catch {
print(error)
NSLog("ERROR in downloadFile, \(error)")
} }
} }
} }