Skip to content

Instantly share code, notes, and snippets.

@MisterPoppet
Created January 26, 2013 01:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MisterPoppet/4639473 to your computer and use it in GitHub Desktop.
Save MisterPoppet/4639473 to your computer and use it in GitHub Desktop.
This is the bare minimum javascript you need to ensure that a TideSDK-based app will not exit when you close the window on a Mac. It simply reopens the closed the window.
var preventCloseEvent = function() {
var appWindow = Ti.UI.getCurrentWindow();
appWindow.addEventListener(Ti.CLOSE, function(event) {
appWindow.hide();
event.preventDefault();
return false;
});
return appWindow;
}
var os = Ti.Platform.name.toLowerCase()
if (os == 'darwin') {
var appWindow = preventCloseEvent();
} else {
var appWindow = Titanium.UI.getCurrentWindow();
}
if (os == 'darwin') {
Ti.API.addEventListener("reopen", function (e) {
if (!e.hasVisibleWindows) {
appWindow.show();
e.preventDefault();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment