0

Right now I open launch firefox like this:

var exe = FileUtils.getFile('XREExeF', []); //this gives path to executable
var process = Cc['@mozilla.org/process/util;1'].createInstance(Ci.nsIProcess);
process.init(exe);

var args = ['-P', profName, '-no-remote']; //-new-instance
if (url) {
    args.push('about:home');
    args.push(url);
}
process.run(false, args, args.length);

This launches it in the foreground.

I would like to launch it into background and then focus it after like 5 seconds. (aside: in my feature right now it launches when user clicks "Create New Profile" but while its creating/launching I want to allow them to name the profile while its working in background, then when user finishes rename by pressing enter or escape/blur then it should focus)

Is this delayed focus possible without js-ctypes?

If I resort to js-ctypes i was thinking get the pid attribute from the run and then move it to background and then focus it later. But a problem happens in that I can't move it to background with winapi, and I don't know about other os'es. (mdn says pid may not be available on all os'es, is it avail on mac and linux?)

nmaier
  • 32,336
  • 5
  • 63
  • 78
Noitidart
  • 35,443
  • 37
  • 154
  • 323

1 Answers1

1

This isn't really possible at all, consistently on all platforms, even if you get the pid and window handle.

E.g. Windows: You cannot simply set other processes' windows to foreground. The other process must allow you to do so first and even then there are still restrictions.

In general, the idea is that the user should be in control, and other applications should not interrupt by stealing focus. Not really what happens in your use case, but the OS/window manager has no real way to know that.

I suggest you do not immediately launch the profile at all, and only start the new profile once the user is done editing any meta data such as the profile name.

nmaier
  • 32,336
  • 5
  • 63
  • 78
  • Thanks man yeah I just created an option for "launch right away" or not. Thanks!! :) Hey I figured out that IPropertyStore thing I sturggled with forever :D it was vtable stuff, still have some quirks to flatten out but i made huge progress in js-ctypes while you were away :D http://stackoverflow.com/questions/24579742/setvalue-and-release-are-not-functions and they all told me it was impossible!!! :D https://github.com/Noitidart/_scratchpad/blob/master/IPropertyStore%20COM%20jsctypes.js – Noitidart Jan 28 '15 at 19:49
  • That gist does exactly what is done here: http://mxr.mozilla.org/mozilla-release/source/widget/windows/WinTaskbar.cpp#108 however the ctypes causes no errors but the AppUserModelID.ID is not changed. Thats the quirk i gotta fix but soooo happy i figured out the ctypes, the not working part is unexplainable right now i gotta get into it. but so happy i want to show off :P – Noitidart Jan 28 '15 at 19:53