<commit_before>/* Copyright (c) 2012-2015 The TagSpaces Authors. All rights reserved.
 * Use of this source code is governed by a AGPL3 license that
 * can be found in the LICENSE file. */
/*global isNode, isWin, isFirefox, Mousetrap, gui */

/**
 * Description
 * @class TSCORE
 */
define(function(require, exports, module) {
  'use strict';

  console.log('Loading core.api.js ...');

  // Importing modules
  var tsSettings = require('tssetting');
  var tsIOApi = require('tsioapi');
  var tsPersManager = require('tspersmanager');
  var tsTagUtils = require('tstagutils');
  var tsFileOpener = require('tsfileopener');
  var tsTagsUI = require('tstagsui');
  var tsDirectoriesUI = require('tsdirectoriesui');
  var tsCoreUI = require('tscoreui');
  var tsSearch = require('tssearch');
  var tsSearchUI = require('tssearchui');
  var tsPro = require('tspro');
  var tsUtils = require('tsutils');
  var tsIOUtils = require('tsioutils');
  var tsMeta = require('tsmeta');
  var tsExt = require('tsextapi');
  var tsExtManager = require('tsextmanager');
  var TSCORE = require('tscore');
  //var tsAudioRecorderUI = require('tsaudiorecorderui');
  var tsCalendarUI = require('tscalendarui');

  // Defining variables
  var currentPath;
  var currentLocationObject;
  var currentPerspectiveID;
  // Current selected files
  var selectedFiles = [];
  // Current directory list of files
  var fileList = [];
  // List of the sub directories of the current directory
  var subDirsList = [];
  // List of meta files
  var metaFileList = [];
  // Last clicked button for removing a tag
  var selectedTag = '';
  var selectedTagData = '';
  var startTime;
  var subfoldersDirBrowser;
  var directoryBrowser;

  // Loading animation related vars
  var $loadingAnimation = $('.loadingAnimation');
  var $statusBar = $('#statusBar');

  // UI and Layout functionalities
  var isFullWidth = false;
  var shouldOpenCol1 = true;
  var shouldOpenCol2 = true;
  var shouldOpenCol3 = false;
  var oneColumn = false;
  var saveOpenCol1 = false;

  /**
   * Initalizes the application
   * @memberof TSCORE
   * @method initApp
   */
  function initApp() {
    console.log('Init application');
    tsSettings.loadSettingsLocalStorage();
    checkLocalStorageEnabled();
    // In firefox, by empty local storage trying to load the settings from mozilla preferences
    if (tsSettings.Settings === undefined && isFirefox) {
      window.setTimeout(tsIOApi.loadSettings, 1000);
      // executes initUI and updateSettingMozillaPreferences by success
      console.log('Loading setting with from mozilla pref executed with delay...');
    }
    // If still nothing found, loading the default setting from the application's javascript
    // This is usually the case by a new installation
    if (tsSettings.Settings === undefined) {
      tsSettings.Settings = tsSettings.DefaultSettings;
    }
    tsSettings.upgradeSettings();
    // Init UI components
    tsCoreUI.initUI();
    tsTagsUI.initUI();
    tsTagsUI.generateTagGroups();
    tsDirectoriesUI.initUI();
    tsDirectoriesUI.initLocations();
    tsFileOpener.initUI();
    tsSearchUI.initUI();
    //tsAudioRecorderUI.initUI();
    tsExtManager.loadExtensionData().then(function() {
      tsPersManager.initPerspectives().then(function(result) {
        console.log("Perspectives Initialized: " + result);
      }).catch(function(err) {
        console.warn("Perspectives initialization failed: " + err);
      });
    });

    hideLoadingAnimation();

    $(document).ready(function() {
      reLayout();

      var language = tsSettings.getInterfaceLanguage();

      if (tsSettings.isFirstRun()) {
        // Showing license dialog
        tsCoreUI.showLicenseDialog();

        // Setting the language
        var browserLang = navigator.language || navigator.userLanguage;

        var languageMatched;

        tsSettings.getSupportedLanguages().forEach(function(value) {
          if (browserLang === value.iso) {
            language = browserLang;
            languageMatched = true;
          }
        });

        if (!languageMatched) {
          tsSettings.getSupportedLanguages().forEach(function(value) {
            if (value.iso.indexOf(browserLang) === 0) {
              language = value.iso;
            }
          });
        }

        tsSettings.setInterfaceLanguage(language);
        tsSettings.saveSettings();

      }

      var langURLParam = tsUtils.getURLParameter('locale');
      if (langURLParam && langURLParam.length > 1) {
        language = langURLParam;
      }

      switchInterfaceLanguage(language).then(function() {
        if (isNode || isElectron) {
          tsIOApi.initMainMenu();
        }

        if (tsSettings.Settings.tagspacesList.length < 1) {
          // Show getting started guide by no locations
          tsCoreUI.startGettingStartedTour();
        }
      }).catch(function() {
        console.warn("Language switching failed.");
      });

      initKeyBindings();
      tsIOApi.checkAccessFileURLAllowed ? tsIOApi.checkAccessFileURLAllowed() : true;

      if (isNode || isChrome || isElectron || isWeb) {
        // Handle command line argument in node-webkit
        tsIOApi.handleStartParameters(); // Handle minimizing to the tray in node-webkit
      }
      console.log('Document ready finished. Layout initialized');
      checkForNewVersion();
    });

    window.addEventListener('orientationchange', reLayout);

    $(window).on('resize', reLayout);

    applyCustomStyles();
  }

  function applyCustomStyles() {
    var sheet = document.createElement('style');
    sheet.innerHTML = ".tagButton {color: " + TSCORE.Config.getDefaultTagTextColor() + " !important; background: " + TSCORE.Config.getDefaultTagColor() + " !important;}";
    document.body.appendChild(sheet);
  }

  function switchInterfaceLanguage(language) {
    exports.currentLanguage = language;<commit_msg>improving code<commit_after>/* Copyright (c) 2012-2015 The TagSpaces Authors. All rights reserved.
 * Use of this source code is governed by a AGPL3 license that
 * can be found in the LICENSE file. */
/*global isNode, isWin, isFirefox, Mousetrap, gui */

/**
 * Description
 * @class TSCORE
 */
define(function(require, exports, module) {
  'use strict';

  console.log('Loading core.api.js ...');

  // Importing modules
  var tsSettings = require('tssetting');
  var tsIOApi = require('tsioapi');
  var tsPersManager = require('tspersmanager');
  var tsTagUtils = require('tstagutils');
  var tsFileOpener = require('tsfileopener');
  var tsTagsUI = require('tstagsui');
  var tsDirectoriesUI = require('tsdirectoriesui');
  var tsCoreUI = require('tscoreui');
  var tsSearch = require('tssearch');
  var tsSearchUI = require('tssearchui');
  var tsPro = require('tspro');
  var tsUtils = require('tsutils');
  var tsIOUtils = require('tsioutils');
  var tsMeta = require('tsmeta');
  var tsExt = require('tsextapi');
  var tsExtManager = require('tsextmanager');
  var TSCORE = require('tscore');
  //var tsAudioRecorderUI = require('tsaudiorecorderui');
  var tsCalendarUI = require('tscalendarui');

  // Defining variables
  var currentPath;
  var currentLocationObject;
  var currentPerspectiveID;
  // Current selected files
  var selectedFiles = [];
  // Current directory list of files
  var fileList = [];
  // List of the sub directories of the current directory
  var subDirsList = [];
  // List of meta files
  var metaFileList = [];
  // Last clicked button for removing a tag
  var selectedTag = '';
  var selectedTagData = '';
  var startTime;
  var subfoldersDirBrowser;
  var directoryBrowser;

  // Loading animation related vars
  var $loadingAnimation = $('.loadingAnimation');
  var $statusBar = $('#statusBar');

  // UI and Layout functionalities
  var isFullWidth = false;
  var shouldOpenCol1 = true;
  var shouldOpenCol2 = true;
  var shouldOpenCol3 = false;
  var oneColumn = false;
  var saveOpenCol1 = false;

  /**
   * Initalizes the application
   * @memberof TSCORE
   * @method initApp
   */
  function initApp() {
    console.log('Init application');
    tsSettings.loadSettingsLocalStorage();
    checkLocalStorageEnabled();
    // In firefox, by empty local storage trying to load the settings from mozilla preferences
    if (tsSettings.Settings === undefined && isFirefox) {
      window.setTimeout(tsIOApi.loadSettings, 1000);
      // executes initUI and updateSettingMozillaPreferences by success
      console.log('Loading setting with from mozilla pref executed with delay...');
    }
    // If still nothing found, loading the default setting from the application's javascript
    // This is usually the case by a new installation
    if (tsSettings.Settings === undefined) {
      tsSettings.Settings = tsSettings.DefaultSettings;
    }
    tsSettings.upgradeSettings();
    // Init UI components
    tsCoreUI.initUI();
    tsTagsUI.initUI();
    tsTagsUI.generateTagGroups();
    tsDirectoriesUI.initUI();
    tsDirectoriesUI.initLocations();
    tsFileOpener.initUI();
    tsSearchUI.initUI();
    //tsAudioRecorderUI.initUI();
    tsExtManager.loadExtensionData().then(function() {
      tsPersManager.initPerspectives().then(function(result) {
        console.log("Perspectives Initialized: " + result);
      }).catch(function(err) {
        console.warn("Perspectives initialization failed: " + err);
      });
    });

    hideLoadingAnimation();

    $(document).ready(function() {
      reLayout();

      var language = tsSettings.getInterfaceLanguage();

      if (tsSettings.isFirstRun()) {
        // Showing license dialog
        tsCoreUI.showLicenseDialog();

        // Setting the language
        var browserLang = navigator.language || navigator.userLanguage;

        var languageMatched;

        tsSettings.getSupportedLanguages().forEach(function(value) {
          if (browserLang === value.iso) {
            language = browserLang;
            languageMatched = true;
          }
        });

        if (!languageMatched) {
          tsSettings.getSupportedLanguages().forEach(function(value) {
            if (value.iso.indexOf(browserLang) === 0) {
              language = value.iso;
            }
          });
        }

        tsSettings.setInterfaceLanguage(language);
        tsSettings.saveSettings();

      }

      var langURLParam = tsUtils.getURLParameter('locale');
      if (langURLParam && langURLParam.length > 1) {
        language = langURLParam;
      }

      switchInterfaceLanguage(language).then(function() {
        if (isNode || isElectron) {
          tsIOApi.initMainMenu();
        }

        if (tsSettings.Settings.tagspacesList.length < 1) {
          // Show getting started guide by no locations
          tsCoreUI.startGettingStartedTour();
        }
      }).catch(function() {
        console.warn("Language switching failed.");
      });

      initKeyBindings();
      tsIOApi.checkAccessFileURLAllowed ? tsIOApi.checkAccessFileURLAllowed() : true;

      if (isNode || isChrome || isElectron || isWeb) {
        // Handle command line argument in node-webkit
        tsIOApi.handleStartParameters(); // Handle minimizing to the tray in node-webkit
      }
      console.log('Document ready finished. Layout initialized');
      checkForNewVersion();
    });

    window.addEventListener('orientationchange', reLayout);

    $(window).on('resize', reLayout);

    applyCustomStyles();
  }

  function applyCustomStyles() {
    var sheet = document.createElement('style');
    sheet.innerText = ".tagButton {color: " + TSCORE.Config.getDefaultTagTextColor() + " !important; background: " + TSCORE.Config.getDefaultTagColor() + " !important;}";
    document.body.appendChild(sheet);
  }

  function switchInterfaceLanguage(language) {
    exports.currentLanguage = language;
{'fraction_non_alphanumeric': 0.11664827234909585, 'fraction_numerical': 0.003395874013074115, 'mean_word_length': 3.168435951875442, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3905262', 'n_tokens_mistral': 3325, 'n_tokens_neox': 3226, 'n_words': 812}