0

I am trying to prevent the user from closing the window when they click on the close button. I would like to have the application dock to the system tray.

My first step is to recognize when the user attempts to close the window and prevent the default behavior on that event. I would expect this code to work, but it does not.

var appWindow = Titanium.UI.getCurrentWindow();
appWindow.addEventListener('app.exit', function(event){
  event.preventDefault();
})

I tried using the exit event and the event constants themselves to no avail.

citizen conn
  • 15,300
  • 3
  • 58
  • 80

2 Answers2

0

This wont work because all your doing when you call preventDefault is stopping the default behavior in the WebKit browser page, not the native application wrapper itself.

The close command is a native function call to the underlying wrapper, it just passes an event to the listener, it does not pass control.

Also, this sounds somewhat dangerous, not allowing a user to close an application seems problematic. Maybe instead you should register a background service to run instead?

Josiah Hester
  • 6,065
  • 1
  • 24
  • 37
  • Thanks, doesn't seem like this is possible then? Consider the behavior where closing the app only "docks" the app to the taskbar. This is the use case I am thinking of. – citizen conn Oct 29 '12 at 18:16
0

one trick might be to open an 'invisible' window for the app, so even if the user closes the 'application' window, the app should still be running.

meeech
  • 1,396
  • 13
  • 21