Firefox OS keyboard event - firefox-os

Does anyone know if in Firefox OS, when keyboard opens, I have an event for that and if so, which is it?
I need to modify my screen on keyboard opening event. Viewport getting shrinked and I need to control the UI on this event.

Answers from dev-b2g#lists.mozilla.org
#YuanXulei(袁徐磊)
Hi, There is no special event for keyboard opening, but the keyboard
opens after receiving the focus event of current input field. So you
may listen to that event instead.
#Alive
There would be some timing difference (mainly from keyboard overlay
transition) between 'focus' and 'resize' event. So 'resize' is the
correctly event to go.
The process is:
-> User app focuses the input field
-> Keyboard app gets focus event via Keyboard API
-> Keyboard app updates its url with hash
-> Keyboard manager in System app is notified via mozbrowserlocationchange event
-> Keyboard manager performs the opening transition of keyboard overlay
-> In the end of the opening transition, keyboard manager notifies window manager with 'keyboardshow' event
-> Window Manager in System app invokes 'current' app's |appWindow.resize()| method.
-> appWindow calculates the height and adjust the size of the container, the iframe in the container is then resized
-> Use app gets resize event.
** Link to discussion **
https://groups.google.com/forum/#!topic/mozilla.dev.b2g/fXfzRsuhWcI

Since only certified apps have access to mozKeyboard, you probably can't.

I don't think there's currently an event for this, even for certified apps. The browser app uses a media query hack to detect when the keyboard is open which really isn't ideal. Feel free to file a bug to add this feature.

Related

How to inject content_script only if the devtools panel is open?

I am trying to create a Chrome extension that adds a panel to the DevTools console.
The extension will have permission to interact with all urls, so to respect my users, I want to ensure that nothing is running when the devtools panel is closed.
The only thing the DevTool panel needs from the attached page (and all of its iframes) is to listen to a custom event dispatched on the respective window (could also be a postMessage)
window.addEventListener('my-custom-event', e => console.log(e.detail))
I understand that you cannot attach listeners directly from the DevTools panel onto the page/frames and you need a content_script to shuttle the messages forward (as described here).
The issue is, the content_script is always appended to the page regardless of whether the panel is open or not. It sets a listener and basically doesn't run unless the listener transfers a port to communicate on.
I would feel irresponsible knowing that my content script runs on every page, potentially impacting the performance of that page so I'd like them to only be attached to the page when the devtools panel is open and the page reloaded.
Ideally I would like to implement a "recording" button which, only when enabled, the content_script is added to the page. This is to avoid noise when doing performance profiling.
So my question is:
Can you inject content_script only when the DevTools panel is open and
Are you able to programmatically toggle content_script injection?

Chrome Extension Disappears while clicking outside of its resolution

Is there anyway that I can make Chrome Extension's window stick in window even while clicking outside of its resolution?
I'm trying to make it Sticky on the window for one simple google login so that I don't need to go back again to click extension to open it.
By using tabs API you could retrieve windowId of the window you want to focus on. You could do it only if needed e.g. by using query method from that API. You could pass url for example.
If you created a window that you want to be still focused then you have its id already in the hand.
After that, you could use window API update method in order to draw attention or focus. Take a look at updateInfo params - focus and drawAttention.
The same could be done by using tabs API. You could pass tabId and the URL you want to redirect someone.
Now in order to make it work you have a couple of options:
You can use setInterval which would be used to check if the tabId and windowId you want are active and focus the window/tab you want in another case.
Because in the MV3 extensions using setInterval is not recommended you could use alarms. Please take a look at AlarmCreateInfo, when param should help you instead of triggering the alarm periodically.
You could also use event listeners from both windows and tabs API to listen on tab / window focus change. Then you will be able block the change (from user perspective) by methods I described before.
You should play with all approaches and pick on that suits you, because all of them have some drawback. But don't want to make that comment very long.

Is it ok to repeatedly add event listener in the event pages for chrome extension?

I am learning the Event Pages for Chrome extension and according to the documentation, the scripts will only be loaded when needed. Then I find that the Google Mail Checker's event page script will add the event listener:
// Some declarations
chrome.browserAction.onClicked.addListener(goToInbox);
// ...
And I write an event script:
chrome.tabs.create({url: 'https://www.google.com'});
function onClickListener() {
chrome.tabs.create({url: 'https://www.bing.com'});
}
chrome.browserAction.onClicked.addListener(onClickListener);
After I reloaded my extension, a new tab of google.com is opened as expected. Seconds later the process of my extension is gone in Chrome's task manager, and I clicked the extension icon. Then, both google.com and bing.com are opened! So I learn that this entire script will be loaded again.
Now look back to the script of Google Mail Checker. The listener will be added repeatedly once the script is loaded, so my question is: is it ok to add listener repeatedly? If the listener's behavior will change from A to B when the script is loaded, which one will be fired on the second load, A or B?
In fact your question is logically impossible, since the documentation has stated that the event listener will only exist in the context of the event page, that means it will be automatically removed once the event page is unloaded. So to some degree, it's ok to add listener repeatedly, although in fact you are adding it only once.
Because the listeners themselves only exist in the context of the event page, you must use addListener each time the event page loads
And Chrome also states that in the first line of best practices when using event pages
Register to receive any events your extension is interested in each time the event page is loaded. The event page will be loaded once for each new version of your extension. After that it will only be loaded to deliver events you have registered for. This generally means that your event listeners should be added at the top level scope of the event page, otherwise they may not be available when the event page reloads.

Howto send a message from content-script to inactive popup, chrome extension

I want to log text on any webpage (using content-script to handle selection) into a database that is popup's resource in order to collect text in one place.
what i am trying
I create a database in popup page and try to manage it from content-script though popup is not active (not opened) by using chrome messaging but cannot make the popup receives any message from content-script.
I'm not sure about using messaging to solve this problem.
Is there any better solution?
A content script cannot send a message to an invisible popup, because the popup's context is inactive (closed) when it's hidden.
There are several solutions to your problem.
Option 1: No message passing, use storage events
If your "database" is in fact a simple key-value store, switch to the chrome.storage API. This API is available to the Content script and the popup, and comes with an event to notify you of value changes.
Example:
// Get notified of changes (in the popup?)
chrome.storage.onChanged.addListener(function(changes, areaName) {
// Do whatever you want with the changes.
});
// Initialization of the popup (print initial information?)
chrome.storage.local.get({keyName: 'defaultValue'}, function(items) {
// Do something with items.keyName
});
// Content script, storage (remember document title?)
chrome.storage.local.set({keyName: document.title});
Option 2: Pass messages to the background/event page
The popup and the background / event page share the same process. Any database tied to the popup is also available to the background page, and vice versa. A high-level overview of this method:
Content script sends a message to the background page.
The background page stores the value in the database
If the popup is open, update the popup's view.
If the popup is opened (so it was closed before), it should read the database (either directly, or by reading data from the background page using chrome.runtime.getBackgroundPage) and handle the results.
I've provided the code corresponding to this flow in this answer.

Iphone 4 sdk - How can I find out if applicationWillEnterForeground was triggered due to a notification?

I am using the notification system as an alerting mechanism. If the app is off or in the background, the iphone alerts the user when a notification comes in. If the app is running and in the foreground I want to show the same alert view as if it was off. I cannot get this to work for the case where the app transitions from the background to the foreground. I end up seeing the alert twice if the the transition was due to a notification, or once if the user clicked the launch icon.
Is there any way to know whether the transition was due to a notification of due to the user clicking the launch icon?
Thanks.
This question provides the answer.
Specifically, in the didReceiveRemoteNotification method you can check the state of the app. UIApplicationStateActive means it is in the foreground so you need to show the alert. Otherwise the Iphone will handle the alert:
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
// Show the alert
}

Resources