Firefox - Using ITaskbarList::ActivateTab - firefox

I use a toolbar button to toggle between normal and private windows.
Here is the code:
OpenBrowserWindow({private: !PrivateBrowsingUtils.isWindowPrivate(window)});
setTimeout(BrowserTryToCloseWindow, 80);
I use 'setTimeout' in order to prevent some flickering.
When the new window opens, it gets the focus.
When the command 'BrowserTryToCloseWindow' is executed, the focus returns to the old window.
When the old window is closed, the new one does have the focus, but it isn't 'checked / active' in Windows Task Bar.
I suppose I need to use ITaskbarList::ActivateTab in order to activate the new window in the task bar.
I have the (very) basic direction:
Components.utils.import("resource://gre/modules/ctypes.jsm");
var lib = ctypes.open("shell32.dll");
var taskBar = lib.declare(---
taskBar---
lib.close();
I'd appreciate your help.
Win 7, 32-bit, Classic Theme.
Posted here too.

Solution:
function togglePB(click)
{
var newWin = OpenBrowserWindow({ private: ! PrivateBrowsingUtils.isWindowPrivate(window) });
if(click.button == 0)
newWin.addEventListener("focus", function switchWindows() { window.focus(); BrowserTryToCloseWindow(); newWin.removeEventListener("focus", switchWindows); });
}
http://forums.mozillazine.org/viewtopic.php?f=19&t=2895755

Related

How to test if window is currently focused

Is there a way to test if a window is currently focused? I know I can do this with addEventListener of activated on the window, and use a global var to track it, but the thing is I need to test this on startup of my addon, so this is before a chance to add any event listeners.
Doing window == Services.wm.getMostRecentWindow(null) will not work because other application windows may be over it. So I guess I need to know if firefox is the currently top most window.
tldr: I need to test if the current window is focused, meaning not just of any other firefox windows, but of all windows on the OS.
With the add-on sdk:
require("sdk/window/utils").isFocused(window)
Without the add-on sdk:
function isFocused(window) {
const FM = Cc["#mozilla.org/focus-manager;1"].
getService(Ci.nsIFocusManager);
let childTargetWindow = {};
FM.getFocusedElementForWindow(window, true, childTargetWindow);
childTargetWindow = childTargetWindow.value;
let focusedChildWindow = {};
if (FM.activeWindow) {
FM.getFocusedElementForWindow(FM.activeWindow, true, focusedChildWindow);
focusedChildWindow = focusedChildWindow.value;
}
return (focusedChildWindow === childTargetWindow);
}
isFocused(window);

How to get handle of popup window (WebdriverIO)

I am very very new to automated testing and I am currently completely stuck with the following issue:
I have a webpage open(first window)
In the same test I call a .newWindow(second window) and do some stuff in that window. The last action opens new popup window(popup window).
What I need, is to set the focus on a popup window.
According to WebdriverIO API I can use .switchTab http://webdriver.io/api/window/switchTab.html
But to be able to switch to a popup window I have to indicate handle, but I don't understand how to get the handle of a popup window :(
That s my piece of code:
//this is the part where I have already second window open
it('should open email letter', function(done) {
client
.pause(2000)
.clickAndWait('[title="Password restore"]', 4000)
.clickAndWait('[title="Restore password"]', 7000) //this is the part where popup window opens
.pause(2000)
.windowHandles(function(err,res){
console.log(res, handles)
}) // I have got three handles but i dont know how to use them now
.........
There is a lot of examples in java, but i didnt find anything that would fit mine language.
Please, excuse me my dumbness, I am really a very beginner and I will appreciate if somebody could explain that to me.
Thanks a lot in advance!
we not use getCurrentTabId to remember the handle of the currently open window?
For example:
var main, popup; //your window handles
client
.getCurrentTabId(function (err, handle) {
main = handle;
})
.newWindow('http://localhost:9001/') //you are on popup window
.getCurrentTabId(function (err, handle) {
popup = handle;
})
.switchTab(main) //you are back to main window
.switchTab(popup) //you are on popup again
.close(popup) //extra bonus!
I notice you stated "The last action opens new popup window(popup window). What I need, is to set the focus on a popup window."
I had this issue. But the new window was opened when clicking on login with facebook. This caused an issue on finding the handle for the new window because I could not use .newWindow('http://localhost:9001/'). The API keys and all sorts are added as parameters when using a social login. So one has little control
To handle this I registered each window ID as its opened.
The first background step in my feature is Given I open the url "/a.html"
In the step you can set an empty array as the variable windowID with let let windowID = []
So my step file would look like this
const url = 'http://localhost:8080'
let windowID = []
this.Given(/^I open the url "([^"]*)"$/, (path) => {
browser
.url(url + path)
console.log(`# Navigating to ${url + path}`)
expect(browser.getUrl()).toEqual(url + path)
windowID.main = browser.getTabIds()
});
During the step after clicking the Facebook button you can then check all the open window ID's and drop the one that matches windowID.main
this.When(/^I authenticate with facebook$/, function (arg1) {
// log the ID of the main window
console.log('Main Window ID' + windowID.main)
browser
.pause(2000)
.getTabIds().forEach(function (value) {
if (value === windowID.main) {
// we do not need to do anything with windowID.main as it's already set
return
}
// if the value does not match windowID.main then we know its the new facebook login window
windowID.facebook = value
})
// log both of these
console.log('Main Window ID: ' + windowID.main)
console.log('Facebook Window ID: ' + windowID.facebook)
// Do the login
browser
.switchTab(windowID.facebook)
.setValue('input[name="email"]', process.env.FACEBOOK_EMAIL)
.setValue('input[name="pass"]', process.env.FACEBOOK_PASSWORD)
.submitForm('form')
});
note that I add credentials as an environment variable. This is a good idea, you don't want to commit your personal credentials to the code base. One may think well obviously, but you may not, who knows.
You had your question answered years ago, but I found this post first when trying to find a solution so it seems a sensible place to put this addition.

Titanium Appcelerator parent window close the new window as well

I am trying to open a new window and close its parent window, so that I can't return to previous window and keep the application more efficient.
However calling close on parent window causes the new window to be closed as well, regardless if I call it before opening the new window or after.
What happens is new window is being opened and then closed right away.
I tried to open a new window on the event listener close for parent window... but that doesn't help.
Code example:
`app.js:`
var loginWin = Ti.UI.createWindow({
url:login.js
});
loginWin.open();
`login.js:`
var win = Ti.UI.currentWindow;
var btn = Ti.UI.createButton({.....});
btn.addEventListener('click',function(e){
//putting win.close() also causes the problem
var appCoreWindow = Ti.UI.createWindow({
url:"core.js"
});
win.close();
appCoreWidnow.open();
});
win.add(btn);
You are creating Window object inside eventhandler and when function finishes garbage collector removes all local variables from it, including appCoreWindow.
Try this instead:
var win = Ti.UI.currentWindow;
var appCoreWindow = Ti.UI.createWindow({ url:"core.js" });
var btn = Ti.UI.createButton({.....});
btn.addEventListener('click',function(e){
appCoreWidnow.open();
win.close();
});
win.add(btn);

Firefox addon bar close event

Is there something in firefox addon through which we can register a callback which gets invoked when the addon is closed by clicking the x button on the left?
What I need is, when a user closes the addon bar using the x button, my extension loaded on that bar should be notified. Now what happens is, even though the user closes the addon bar, it is not getting closed; instead it just hides.
If we can be informed through a callback that the user has clicked on x button, then i could listen to that in the extension.
Yes sir there absolutely is: MutationObserver.
Copy paste this to a scratchpad file in Browser envirnoment and then as addon bar is closed and opened you will see a message.
// select the target node
var win = Services.wm.getMostRecentWindow('navigator:browser');
var target = win.document.querySelector('#addon-bar');
// create an observer instance
var observer = new win.MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName == 'collapsed') {
Services.prompt.alert(null,'title','addon bar toggled it WAS = ' + mutation.oldValue);
}
});
});
// configuration of the observer:
var config = { attributes:true, attributeOldValue:true };
// pass in the target node, as well as the observer options
observer.observe(target, config);
// later, you can stop observing
//observer.disconnect();
The easiest way to do this is to attach a command handler to the button in question. If your code runs inside the browser window, this will do:
var closeButton = document.getElementById("addonbar-closebutton");
closeButton.addEventListener("command", function(event) {
// Add-on bar is being closed, do something
}, false);
Note that this code is bound to stop working very soon as the add-on bar is being removed from Firefox.

Appcelerator. Using swipe to open window

I am developing an iOS app in Appcelerator and I want to switch between windows with the use of a swipe event listener. How can I do this? The below code does not work. The current window that I "start" from contains a table.
var window = Ti.UI.currentWindow;
window.addEventListener('swipe', function() {
// Create the new window
var win = Titanium.UI.createWindow({
title: 'Contacts',
url:'contacts_simple.js'
});
// Animate the page turn
Titanium.UI.currentTab.open(win, {animated:false});
});
I think the problem is with the Ti.UI.currentWindow. Depending on the context you're working in it may not be valid.
Google 'appcelerator currentWindow', but here's a related link:
http://developer.appcelerator.com/question/5391/currentwindow
This will not be optimal and dynamic, but to start with, try referencing the window implicitly. Meaning if you did something like
var window_x = Ti.UI.createWindow({});
try
window_x.addEventListener('swipe', function() {...});

Resources