I am developing the mac app with Safari Content Blocker and Safari Toolbar Item extensions.
I am able to get the state of Content Blocker extension (enabled/disabled) in Safari from the mac app (Containing App), and able to display the warning inside the mac app that Content Blocker is disabled.
But is there any way that I can get the Content Blocker extension's state (enabled/disabled) from the Safari Toolbar Item extension?
Here is the code that executes when the popover is visible when a user clicks on Safari Toolbar Item.
class SafariExtensionViewController: SFSafariExtensionViewController {
// This function is called from the
// SafariExtensionHandler > popoverWillShow(in window: SFSafariWindow)
func onPopoverVisible() {
SFContentBlockerManager.getStateOfContentBlocker(withIdentifier: "com.xyz.macapp.contentblocker") { (state, error) in
guard let state = state else {
// handle the error
return
}
if state.isEnabled {
// display toolbar items and hide warning message
} else {
// display warning message and hide toolbar items
}
}
}
}
When above code executes, state.isEnabled
is always false
.
Is it possible to get the state of one extension from another? If yes, how?. If no, is there any way to handle this scenario?