open mac app when read now button is tapped from share extension
This commit is contained in:
@ -26,12 +26,17 @@ public class ShareExtensionViewModel: ObservableObject {
|
||||
let saveService = ExtensionSaveService()
|
||||
|
||||
func handleReadNowAction(requestId: String, extensionContext: NSExtensionContext?) {
|
||||
// TODO: write macos version
|
||||
#if os(iOS)
|
||||
let deepLinkUrl = NSURL(string: "omnivore://shareExtensionRequestID/\(requestId)")
|
||||
if let application = UIApplication.value(forKeyPath: #keyPath(UIApplication.shared)) as? UIApplication {
|
||||
let deepLinkUrl = NSURL(string: "omnivore://shareExtensionRequestID/\(requestId)")
|
||||
application.perform(NSSelectorFromString("openURL:"), with: deepLinkUrl)
|
||||
}
|
||||
#else
|
||||
let deepLinkUrl = URL(string: "omnivore://shareExtensionRequestID/\(requestId)")
|
||||
let workspace = NSWorkspace.value(forKeyPath: #keyPath(NSWorkspace.shared)) as? NSWorkspace
|
||||
if let workspace = workspace, let deepLinkUrl = deepLinkUrl {
|
||||
workspace.open(deepLinkUrl)
|
||||
}
|
||||
#endif
|
||||
extensionContext?.completeRequest(returningItems: [], completionHandler: nil)
|
||||
}
|
||||
|
||||
@ -131,6 +131,15 @@ import Views
|
||||
loadItems(isRefresh: true)
|
||||
}
|
||||
}
|
||||
.handlesExternalEvents(preferring: Set(["shareExtensionRequestID"]), allowing: Set(["*"]))
|
||||
.onOpenURL { url in
|
||||
viewModel.linkRequest = nil
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) {
|
||||
if let linkRequestID = DeepLink.make(from: url)?.linkRequestID {
|
||||
viewModel.linkRequest = LinkRequest(id: UUID(), serverID: linkRequestID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user