historical/xcloud-keyboard-mouse-inftrial.git/safari/Keyboard & Mouse for Xbox xCloud/Shared (Extension)/SafariWebExtensionHandler.swift
2024-01-16 11:20:27 -06:00

26 lines
762 B
Swift

//
// SafariWebExtensionHandler.swift
// Shared (Extension)
//
// Created by David Idol on 12/4/21.
//
import SafariServices
import os.log
let SFExtensionMessageKey = "message"
class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
func beginRequest(with context: NSExtensionContext) {
let item = context.inputItems[0] as! NSExtensionItem
let message = item.userInfo?[SFExtensionMessageKey]
os_log(.default, "Received message from browser.runtime.sendNativeMessage: %@", message as! CVarArg)
let response = NSExtensionItem()
response.userInfo = [ SFExtensionMessageKey: [ "Response to": message ] ]
context.completeRequest(returningItems: [response], completionHandler: nil)
}
}