How to get the state(enabled/disabled) of safari content blocker app extension from safari toolbar item app extension? - safari-content-blocker

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?

Related

React Hide Component when Mobile Keyboard open

I'm wondering if there is a way to hide React components (Ex. Bottom Navigation Bar Component) while the mobile (Andriod, iOS, etc. ) Keyboard is open on the screen.
Currently I'm doing it with a:
#media (max-height: 400px) {
.navclass {
display: none;
}
}
but am wondering if there is a JS Event or similar.
When am input element is focused on devices of inbuilt keyboards, the keyboards pops up.
ReactJS allows you to write Normal JavaScript in your code.so what you can do is to
this.state = {
isNavVisible: true
}
You can now pass this dynamically as a prop on the components and set it to the style of the wrappers element as an inline style in the components main file.
You can then write a function on your inputs or elements that takes focus:
const disableNav = () => {
if(windows.innerWidth <= 400){
this.setState({isNavVisible: false})
}
}

Extend GCKUICastContainerViewController below the Home Indicator

I'm integrating GoogleCast to my app. Its root view controller is a UITabBarController, with a custom white tab bar.
After I wrapped it with a GCKUICastContainerViewController, the Home Indicator background area became black (and the indicator is white).
How can I make this Container VC extend its child VC (my tab bar controller) below the home indicator?
Note: There is an ugly workaround that I tried, which is to set castContainerVC.view.backgroundColor = .white. This would work if the tab bar was always visible, but some parts of my navigation stack may choose to hide it. When it happens, I'd end with a white Home Indicator area, but whatever color the presented view controller has above the indicator.
extension GCKUICastContainerViewController {
open override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if let window = UIApplication.shared.keyWindow, miniMediaControlsViewController?.view.bounds.height ?? 0 == 0 {
contentViewController?.view.frame = window.frame
} else {
contentViewController?.view.frame = (view.subviews.first! as UIView).frame
}
}
}
Yes, it appears Google wants us to have the GCKUICastContainerViewController as the root view controller. And it looks like it has some layout issue when there is safe area inset at the bottom of the display.
I solved this by changing the view's frame manually in viewDidLayoutSubviews. You can do it with an extension like this
extension GCKUICastContainerViewController {
open override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if let window = UIApplication.shared.keyWindow {
contentViewController?.view.frame = window.frame
}
}
}
This way you will get rid of the space at the bottom of the screen. Works for me.

Firefox: Window similar to Chrome extension window

Sample Chrome extension opens a window after pressing its corresponding button in the upper-right corner of the browser (near the menu list opener). How to open such window for Firefox extension (using jpm preferably).
You can achieve the same functionality in a firefox add-on using toggle buttons. Specifically take a look at attaching panels to buttons.
A simple solution to open a new window when the button of your extension is pressed is the following:
main.js:
var tabs = require("sdk/tabs");
var { ActionButton } = require("sdk/ui/button/action");
var button = ActionButton({
id: "my-button",
label: "my button",
icon: {
"16": "./icon-16.png",
"32": "./icon-32.png",
"64": "./icon-64.png"
},
onClick: handler
});
function handler() {
tabs.open("https://developer.mozilla.org");
}
Make sure that the icons of your extension should be in the data folder.
Look at mozilla developers documentation for more information:
Buttons
Tabs

Chrome page action popup disappears

I need a page action popup icon to appear when a tab has a specific URL in the address bar.
I have this in my background page
chrome.tabs.query({url:"MYURL.COM"} , function(tab)
{
for(i=0;i<tab.length;i++)
{
console.log(tab[i].id);
chrome.pageAction.show(tab[i].id);
}
});
The popup shows whenever I reload the extension but as soon as user refreshes, it goes away and doesn't come back.
The reason is that the background.js page is only loaded once, so you need to add a listener to every time the page tab is updated to check whether the page action should be shown, something like this:
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (tab.url.indexOf("MYURL.COM") > -1) {
chrome.pageAction.show(tabId);
}
});
There is no reason to iterate over each tab as you have done.
As Adam has already said, the tabs.onUpdated event is the way to do it.
Anyway, it [seems like I'm not the only one who experienced that the tabs.onUpdated event doesn't always fire when it should - even when waiting for complete status.
So if you're having the same issue, you might want to try my modified version that has proven reliable for me 100%.
chrome.tabs.onUpdated.addListener(function(tabId, change) {
if (change.status == "complete") {
chrome.tabs.query({active: true}, function(tabs) {
var tab = tabs[0];
// Now do stuff with tab .. Eg:
if (tab.url.indexOf("MYURL.COM") > -1) {
chrome.pageAction.show(tab.id); }
else {
chrome.pageAction.hide(tab.id); }
});
}
});
Use chrome.tabs.onUpdated to listen to new tabs and tab reloads of the domain you are interested in.

Selection type changes context menu using chrome extension

I am trying to build a chrome extension. In it I want the context menu to change according to the selected text on the page.
For example, if its a number I want a menu that says divisibility test for this numbr is ...
and if it is a string, it should have a something else, but not both at the same time.
I cant figure out how to do that.
You will have to set a listener for mouse down. There is no other way to get the selected text before the menu is created.
See this SO question:
chrome extension context menus, how to display a menu item only when there is no selection?
Here is part of the code the rest is at the link.
document.addEventListener("mousedown", function(event){
//right click
if(event.button == 2) {
if(window.getSelection().toString()) {
chrome.extension.sendRequest({cmd: "createSelectionMenu"});
} else {
chrome.extension.sendRequest({cmd: "createRegularMenu"});
}
}
}, true);

Resources