Search code examples
windowsdesktop-applicationtidesdk

TideSDK bring window to top level on click of system notification


I am using tideSDK to create desktop app.

I wanted to show the system notifications on certain events. The below code works well.

    //Create a callback function for the notification
var doSomething = function() {
    //Do something!
}

//Creating a notification and displaying it.
var notification = Ti.Notification.createNotification({
    'title' : 'Notification from App',
    'message' : 'Click here for updates!',
    'timeout' : 10,
    'callback' : doSomething,
    'icon' : 'app://images/notificationIcon.png'        
});

notification.show();

this from http://tidesdk.multipart.net/docs/user-dev/generated/#!/api/Ti.Notification

Here in doSomething method I want to bring the tideSDK app window to top level.

I tried Ti.UI.currentWindow.focus();


Solution

  • setTopMost together with show can be used to achieve this

    var window = Ti.UI.currentWindow;
    window.setTopMost(true);
    window.show()
    window.setTopMost(false);
    

    It is important to do setTopMost(false), otherwise the window will always show on top of other windows even if you want to open other windows