<commit_before>/**
 * @fileOverview This file opens a tab with the first run html doc under
 * appropriate conditions when the extension is loaded on browser launch or
 * on extension install.
 * 
 * Appropriate conditions fall under two circumstances:
 * 1. LocalStorage does not have a stored value for the version of privly
 *    installed. (Privly was just installed or localStorage was cleared)
 * 2. The version stored in the manifest differs from the version stored in
 *    localStorage. (Privly was updated)
 *
 **/

/**
 * Get version stored in the manifest
 */
function get_privly_version(){ 
  var details = chrome.app.getDetails();
  return details.version;
}

/**
 * Get version stored in localStorage
 */
function get_stored_version(){
  var stored_version = localStorage["version"];
  return stored_version;
}

/**
 * Update localStorage version
 */
function update_version(version){
  localStorage["version"] = version;
}

/** 
 * open a window with the local first_run.html and ensures the localStorage
 * variables are assigned.
 */
function firstrun(){
  
  var postingDomain = localStorage["posting_content_server_url"];
  if (postingDomain === undefined || postingDomain === null) {
    localStorage["posting_content_server_url"] = "https://privlyalpha.org";
  }
  
  var page = chrome.extension.getURL("pages/first_run.html");
  chrome.windows.create({url: page, focused: true,
                         width: 1100,
                         top: 0, left: 0, type: "popup"}, 
                         function(newWindow){});
  return "Done";
}

/**
 * Check whether the first run html page should be opened.
 */
function run_firstrun(){
  
  var running_version = get_privly_version();
  var last_run_version = get_stored_version();

  if (last_run_version === null || running_version !== last_run_version ) {
    
    // minor update, don't show popup if they already had 0.3.2
    if(last_run_version !== "0.3.2" && running_version !== "0.3.3") firstrun();
    update_version(running_version);
  }
}

// Initialize the spoofing glyph
// The generated string is not cryptographically secure and should not be used
// for anything other than the glyph.
if (localStorage["privly_glyph"] === undefined) {
  localStorage["privly_glyph"] = Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16);
}
<commit_msg>always opens first run page on update<commit_after>/**
 * @fileOverview This file opens a tab with the first run html doc under
 * appropriate conditions when the extension is loaded on browser launch or
 * on extension install.
 * 
 * Appropriate conditions fall under two circumstances:
 * 1. LocalStorage does not have a stored value for the version of privly
 *    installed. (Privly was just installed or localStorage was cleared)
 * 2. The version stored in the manifest differs from the version stored in
 *    localStorage. (Privly was updated)
 *
 **/

/**
 * Get version stored in the manifest
 */
function get_privly_version(){ 
  var details = chrome.app.getDetails();
  return details.version;
}

/**
 * Get version stored in localStorage
 */
function get_stored_version(){
  var stored_version = localStorage["version"];
  return stored_version;
}

/**
 * Update localStorage version
 */
function update_version(version){
  localStorage["version"] = version;
}

/** 
 * open a window with the local first_run.html and ensures the localStorage
 * variables are assigned.
 */
function firstrun(){
  
  var postingDomain = localStorage["posting_content_server_url"];
  if (postingDomain === undefined || postingDomain === null) {
    localStorage["posting_content_server_url"] = "https://privlyalpha.org";
  }
  
  var page = chrome.extension.getURL("pages/first_run.html");
  chrome.windows.create({url: page, focused: true,
                         width: 1100,
                         top: 0, left: 0, type: "popup"}, 
                         function(newWindow){});
  return "Done";
}

/**
 * Check whether the first run html page should be opened.
 */
function run_firstrun(){
  
  var running_version = get_privly_version();
  var last_run_version = get_stored_version();

  if (last_run_version === null || running_version !== last_run_version ) {
    firstrun();
    update_version(running_version);
  }
}

// Initialize the spoofing glyph
// The generated string is not cryptographically secure and should not be used
// for anything other than the glyph.
if (localStorage["privly_glyph"] === undefined) {
  localStorage["privly_glyph"] = Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16) + "," +
    Math.floor(Math.random()*16777215).toString(16);
}

{'fraction_non_alphanumeric': 0.13539996436843044, 'fraction_numerical': 0.04008551576696953, 'mean_word_length': 3.7738095238095237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7648951', 'n_tokens_mistral': 1814, 'n_tokens_neox': 1658, 'n_words': 440}