Skip to content

Instantly share code, notes, and snippets.

@falkolab
Last active March 14, 2017 22:51
Show Gist options
  • Select an option

  • Save falkolab/807da29ec954fe742e25 to your computer and use it in GitHub Desktop.

Select an option

Save falkolab/807da29ec954fe742e25 to your computer and use it in GitHub Desktop.

Revisions

  1. falkolab revised this gist Mar 18, 2016. 1 changed file with 38 additions and 37 deletions.
    75 changes: 38 additions & 37 deletions runner.js
    Original file line number Diff line number Diff line change
    @@ -2,55 +2,56 @@ 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);
    if (isFirstLaunch) Ti.App.Properties.setBool(exports.FIRST_LAUNCH_KEY, false);

    // Свежий запуск приложения (не повторный интент)
    var initialLaunchPerformed = false;

    _.extend(exports, Backbone.Events);

    exports.isFirstLaunch = function() {
    // да, именно из переменной, не из Properties
    return isFirstLaunch;
    // да, именно из переменной, не из Properties
    return isFirstLaunch;
    };

    exports.runApplication = function() {
    Ti.API.debug('runner.runApplication');
    if(isFirstLaunch) Ti.API.debug("Первый запуск после установки!");
    this.trigger('run', {source: this});
    if(require('runner').isFirstLaunch()) {
    this.trigger('firstlaunch');
    }
    Ti.API.debug('runner.runApplication');
    if (isFirstLaunch) Ti.API.debug("Первый запуск после установки!");
    this.trigger('run', {
    source: this
    });
    };

    exports.isInitialLaunchPerformed = function() {
    return initialLaunchPerformed;
    return initialLaunchPerformed;
    };

    (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 (!runner.isInitialLaunchPerformed()) {
    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;
    }
    })();
    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;
    }
    })();
    }
  2. falkolab revised this gist Mar 12, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions alloy.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    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();
    });
  3. falkolab created this gist Mar 12, 2016.
    5 changes: 5 additions & 0 deletions alloy.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    require('runner').on('run', function(evt) {
    // evt.source - runner module reference
    var hc = Alloy.CFG.homeController;
    Alloy.createController(hc.name, hc.args).getView().open();
    });
    1 change: 1 addition & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    require('runner').runApplication();
    1 change: 1 addition & 0 deletions index.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    <Alloy><View/></Alloy>
    56 changes: 56 additions & 0 deletions runner.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    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});
    if(require('runner').isFirstLaunch()) {
    this.trigger('firstlaunch');
    }
    };

    exports.isInitialLaunchPerformed = function() {
    return initialLaunchPerformed;
    };

    (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 (!runner.isInitialLaunchPerformed()) {
    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;
    }
    })();