Skip to content

Instantly share code, notes, and snippets.

@falkolab
Last active March 14, 2017 22:51
Show Gist options
  • Save falkolab/807da29ec954fe742e25 to your computer and use it in GitHub Desktop.
Save falkolab/807da29ec954fe742e25 to your computer and use it in GitHub Desktop.
Application launch manager for Titanium SDK
require('runner').on('run', function(evt) {
// evt.source - runner module reference
var hc = Alloy.CFG.homeController;
// home window launch
Alloy.createController(hc.name, hc.args).getView().open();
});
require('runner').runApplication();
<Alloy><View/></Alloy>
exports.FIRST_LAUNCH_KEY = "app.firstlaunch";
//первый запуск приложения после установки
var isFirstLaunch = Ti.App.Properties.getBool(exports.FIRST_LAUNCH_KEY, true);
if (isFirstLaunch) Ti.App.Properties.setBool(exports.FIRST_LAUNCH_KEY, false);
// Свежий запуск приложения (не повторный интент)
var initialLaunchPerformed = false;
_.extend(exports, Backbone.Events);
exports.isFirstLaunch = function() {
// да, именно из переменной, не из Properties
return isFirstLaunch;
};
exports.runApplication = function() {
Ti.API.debug('runner.runApplication');
if (isFirstLaunch) Ti.API.debug("Первый запуск после установки!");
this.trigger('run', {
source: this
});
};
exports.isInitialLaunchPerformed = function() {
return initialLaunchPerformed;
};
if (OS_ANDROID) {
(function attachResumeHandler() {
/*
Every Android application has a root activity that starts the application.
For Titanium applications, the root activity displays the splash screen.
When a backgrounded application is left inactive (for about 30 minutes or so), upon reopening the app Android kills off activities above the root activity.
This reveals the splash screen activity, making it appear as if the application is hung.
http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Android.Activity
*/
var rootActivity = Ti.Android.currentActivity;
var onResume = function onResume() {
var runner = require('runner');
if (!initialLaunchPerformed) {
initialLaunchPerformed = true;
return;
}
runner.runApplication();
};
if (_.isFunction(rootActivity.onResume)) {
Ti.API.warn("onResume handler already defined. It composed with handler from `runner`");
rootActivity.onResume = _.compose(rootActivity.onResume, onResume);
} else {
rootActivity.onResume = onResume;
}
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment