{"size": 1792, "ext": "js", "max_stars_repo_path": "dist/app/js/services/core/eventService.js", "max_stars_repo_name": "jtlalka/time-logger", "max_stars_repo_stars_event_min_datetime": "2016-02-21T08:05:55.000Z", "max_stars_repo_stars_event_max_datetime": "2018-06-15T12:16:49.000Z", "max_issues_repo_path": "dist/app/js/services/core/eventService.js", "max_issues_repo_name": "jtlalka/time-logger", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dist/app/js/services/core/eventService.js", "max_forks_repo_name": "jtlalka/time-logger", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.5818181818, "max_line_length": 110, "alphanum_fraction": 0.5546875}
/**
 * Chrome Event Service
 */
angular.module('timeLogger')
    .service('eventService', function($interval, dataService, updateService, propertyService, loggerService) {

        var detectionTime = propertyService.getDetectionTime();
        var intervalTime = propertyService.getIntervalTime();
        var intervalFunc = null;

        this.initChromeEvents = function() {
            onStartApplication();
            onStateChangedEvent();
        };

        var onStartApplication = function() {
            loggerService.info('EventService: onStart event.');
            updateService.checkUpdates().then(function() {
                dataService.checkStatus(dataService.type.ACTIVE);
                startStatusChecker();
            });
        };

        var onStateChangedEvent = function() {
            if (chrome.idle.setDetectionInterval) {
                chrome.idle.setDetectionInterval(detectionTime);
            }
            chrome.idle.onStateChanged.addListener(function(idleState) {
                loggerService.trace('EventService: onStateChanged event.');
                dataService.checkStatus(idleState);
                resetStatusChecker();
            });
        };

        var startStatusChecker = function() {
            if (intervalFunc === null) {
                intervalFunc = $interval(function() {
                    dataService.checkStatus();
                }, intervalTime, 0, false);
            }
        };

        var stopStatusChecker = function() {
            if (intervalFunc !== null) {
                $interval.cancel(intervalFunc);
                intervalFunc = null;
            }
        };

        var resetStatusChecker = function() {
            stopStatusChecker();
            startStatusChecker();
        };
    });
