<commit_before>/*
 * Copyright 2016 Resin.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @module Etcher
 */

'use strict';

var angular = require('angular');
const _ = require('lodash');

const app = angular.module('Etcher', [
  require('angular-ui-router'),
  require('angular-ui-bootstrap'),
  require('angular-moment'),
  require('angular-middle-ellipses'),
  require('angular-if-state'),

  // Etcher modules
  require('./modules/drive-scanner'),
  require('./modules/image-writer'),
  require('./modules/analytics'),

  // Models
  require('./models/selection-state'),
  require('./models/settings'),
  require('./models/supported-formats'),
  require('./models/drives'),

  // Components
  require('./components/progress-button/progress-button'),
  require('./components/drive-selector/drive-selector'),
  require('./components/svg-icon/svg-icon'),
  require('./components/update-notifier/update-notifier'),
  require('./components/tooltip-modal/tooltip-modal'),

  // Pages
  require('./pages/finish/finish'),
  require('./pages/settings/settings'),

  // OS
  require('./os/notification/notification'),
  require('./os/window-progress/window-progress'),
  require('./os/open-external/open-external'),
  require('./os/dropzone/dropzone'),
  require('./os/dialog/dialog'),

  // Utils
  require('./utils/notifier/notifier'),
  require('./utils/path/path'),
  require('./utils/manifest-bind/manifest-bind'),
  require('./utils/byte-size/byte-size')
]);

app.run(function(AnalyticsService) {
  AnalyticsService.logEvent('Application start');
});

app.config(function($stateProvider, $urlRouterProvider) {
  $urlRouterProvider.otherwise('/main');

  $stateProvider
    .state('main', {
      url: '/main',
      controller: 'AppController as app',
      templateUrl: './partials/main.html'
    });
});

app.controller('AppController', function(
  $state,
  $scope,
  NotifierService,
  DriveScannerService,
  SelectionStateModel,
  SettingsModel,
  SupportedFormatsModel,
  DrivesModel,
  ImageWriterService,
  AnalyticsService,
  DriveSelectorService,
  UpdateNotifierService,
  TooltipModalService,
  OSWindowProgressService,
  OSNotificationService,
  OSDialogService
) {
  let self = this;
  this.formats = SupportedFormatsModel;
  this.selection = SelectionStateModel;
  this.drives = DrivesModel;
  this.writer = ImageWriterService;
  this.settings = SettingsModel.data;
  this.tooltipModal = TooltipModalService;
  this.success = true;

  this.handleError = function(error) {
    OSDialogService.showError(error);

    // Also throw it so it gets displayed in DevTools
    // and its reported by TrackJS.
    throw error;
  };

  if (UpdateNotifierService.shouldCheckForUpdates()) {
    AnalyticsService.logEvent('Checking for updates');

    UpdateNotifierService.isLatestVersion().then(function(isLatestVersion) {

      // In case the internet connection is not good and checking the
      // latest published version takes too long, only show notify
      // the user about the new version if he didn't start the flash
      // process (e.g: selected an image), otherwise such interruption
      // might be annoying.
      if (!isLatestVersion && !SelectionStateModel.hasImage()) {

        AnalyticsService.logEvent('Notifying update');
        UpdateNotifierService.notify();
      }
    });
  }

  // This catches the case where the user enters
  // the settings screen when a flash finished
  // and goes back to the main screen with the back button.
  if (!this.writer.isFlashing()) {

    this.selection.clear({

      // Preserve image, in case there is one, otherwise<commit_msg>fix: check for updates only once at startup (#517)<commit_after>/*
 * Copyright 2016 Resin.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @module Etcher
 */

'use strict';

var angular = require('angular');
const _ = require('lodash');

const app = angular.module('Etcher', [
  require('angular-ui-router'),
  require('angular-ui-bootstrap'),
  require('angular-moment'),
  require('angular-middle-ellipses'),
  require('angular-if-state'),

  // Etcher modules
  require('./modules/drive-scanner'),
  require('./modules/image-writer'),
  require('./modules/analytics'),

  // Models
  require('./models/selection-state'),
  require('./models/settings'),
  require('./models/supported-formats'),
  require('./models/drives'),

  // Components
  require('./components/progress-button/progress-button'),
  require('./components/drive-selector/drive-selector'),
  require('./components/svg-icon/svg-icon'),
  require('./components/update-notifier/update-notifier'),
  require('./components/tooltip-modal/tooltip-modal'),

  // Pages
  require('./pages/finish/finish'),
  require('./pages/settings/settings'),

  // OS
  require('./os/notification/notification'),
  require('./os/window-progress/window-progress'),
  require('./os/open-external/open-external'),
  require('./os/dropzone/dropzone'),
  require('./os/dialog/dialog'),

  // Utils
  require('./utils/notifier/notifier'),
  require('./utils/path/path'),
  require('./utils/manifest-bind/manifest-bind'),
  require('./utils/byte-size/byte-size')
]);

app.run(function(AnalyticsService, UpdateNotifierService, SelectionStateModel) {
  AnalyticsService.logEvent('Application start');

  if (UpdateNotifierService.shouldCheckForUpdates()) {
    AnalyticsService.logEvent('Checking for updates');

    UpdateNotifierService.isLatestVersion().then(function(isLatestVersion) {

      // In case the internet connection is not good and checking the
      // latest published version takes too long, only show notify
      // the user about the new version if he didn't start the flash
      // process (e.g: selected an image), otherwise such interruption
      // might be annoying.
      if (!isLatestVersion && !SelectionStateModel.hasImage()) {

        AnalyticsService.logEvent('Notifying update');
        UpdateNotifierService.notify();
      }
    });
  }

});

app.config(function($stateProvider, $urlRouterProvider) {
  $urlRouterProvider.otherwise('/main');

  $stateProvider
    .state('main', {
      url: '/main',
      controller: 'AppController as app',
      templateUrl: './partials/main.html'
    });
});

app.controller('AppController', function(
  $state,
  $scope,
  NotifierService,
  DriveScannerService,
  SelectionStateModel,
  SettingsModel,
  SupportedFormatsModel,
  DrivesModel,
  ImageWriterService,
  AnalyticsService,
  DriveSelectorService,
  UpdateNotifierService,
  TooltipModalService,
  OSWindowProgressService,
  OSNotificationService,
  OSDialogService
) {
  let self = this;
  this.formats = SupportedFormatsModel;
  this.selection = SelectionStateModel;
  this.drives = DrivesModel;
  this.writer = ImageWriterService;
  this.settings = SettingsModel.data;
  this.tooltipModal = TooltipModalService;
  this.success = true;

  this.handleError = function(error) {
    OSDialogService.showError(error);

    // Also throw it so it gets displayed in DevTools
    // and its reported by TrackJS.
    throw error;
  };

  // This catches the case where the user enters
  // the settings screen when a flash finished
  // and goes back to the main screen with the back button.
  if (!this.writer.isFlashing()) {

    this.selection.clear({

      // Preserve image, in case there is one, otherwise
{'fraction_non_alphanumeric': 0.1338771593090211, 'fraction_numerical': 0.002279270633397313, 'mean_word_length': 3.7913793103448277, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1402811', 'n_tokens_mistral': 2373, 'n_tokens_neox': 2292, 'n_words': 591}