<commit_before>/*
This uses the beakerBrowser API, which is exposed by webview-preload to all sites loaded over the beaker: protocol
*/

import * as yo from 'yo-yo'
import co from 'co'
import emitStream from 'emit-stream'

// globals
// =

var settings
var browserInfo
var browserEvents
var defaultProtocolSettings

// exported API
// =

export function setup () {
  // wire up events
  browserEvents = emitStream(beakerBrowser.eventsStream())
  browserEvents.on('updater-state-changed', onUpdaterStateChanged)
  browserEvents.on('updater-error', onUpdaterError)
}

export function show () {
  document.title = 'Settings'
  defaultProtocolSettings = beakerBrowser.getDefaultProtocolSettings()
  co(function* () {
    browserInfo = yield beakerBrowser.getInfo()
    settings = yield beakerBrowser.getSettings()

    render()
  })
}

export function hide () {
  browserInfo = null
  settings = null
  defaultProtocolSettings = null
}

// rendering
// =

function render () {
  // only render if this page is active
  if (!browserInfo)
    return

  yo.update(document.querySelector('#el-content'), yo`<div class="pane" id="el-content">
    <div class="settings">
      <div class="ll-heading">Auto-updater</div>
      ${renderAutoUpdater()}
      <div class="ll-heading">Application Info</div>
      <div class="s-section">
        <div><strong>Version:</strong> ${browserInfo.version}</div>
        <div><strong>User data:</strong> ${browserInfo.paths.userData}</div>
      </div>
      <div class="ll-heading">Protocols</div>
      ${renderProtocolSettings()}
    </div>
  </div>`)
}

function renderProtocolSettings () {
  function register (protocol) {
    return function () {
      beakerBrowser.setAsDefaultProtocolClient(protocol)
    }
  }
  function remove (protocol) {
    return function () {
      beakerBrowser.removeAsDefaultProtocolClient(protocol)
    }
  }
  return yo`<div class="s-section">
    <div>${
      Object.keys(defaultProtocolSettings).map(p => {
        return yo`<div>${p.toUpperCase()} <a onclick=${register(p)}>Register</a> | <a onclick=${remove(p)}>Unregister</a></div>`
      })
    }</div>
  </div>`
}

function renderAutoUpdater () {
  if (!browserInfo.updater.isBrowserUpdatesSupported) {
    return yo`<div class="s-section">
      <div>Sorry! Beaker auto-updates are only supported on the production build for MacOS and Windows.
      You will need to build new versions of Beaker from source.</div>
    </div>`
  }

  switch (browserInfo.updater.state) {
    default:
    case 'idle':
      return yo`<div class="s-section">
        <button class="btn btn-default" onclick=${onClickCheckUpdates}>Check for updates</button>
        <span class="version-info">
          ${ browserInfo.updater.error
            ? yo`<span><span class="icon icon-cancel"></span> ${browserInfo.updater.error}</span>`
            : yo`<span>
                <span class="icon icon-check"></span>
                <strong>Beaker v${browserInfo.version}</strong> is up-to-date
              </span>` }
          ${renderAutoUpdateCheckbox()}
        </span>
      </div>`<commit_msg>bold style for protocol name<commit_after>/*
This uses the beakerBrowser API, which is exposed by webview-preload to all sites loaded over the beaker: protocol
*/

import * as yo from 'yo-yo'
import co from 'co'
import emitStream from 'emit-stream'

// globals
// =

var settings
var browserInfo
var browserEvents
var defaultProtocolSettings

// exported API
// =

export function setup () {
  // wire up events
  browserEvents = emitStream(beakerBrowser.eventsStream())
  browserEvents.on('updater-state-changed', onUpdaterStateChanged)
  browserEvents.on('updater-error', onUpdaterError)
}

export function show () {
  document.title = 'Settings'
  defaultProtocolSettings = beakerBrowser.getDefaultProtocolSettings()
  co(function* () {
    browserInfo = yield beakerBrowser.getInfo()
    settings = yield beakerBrowser.getSettings()

    render()
  })
}

export function hide () {
  browserInfo = null
  settings = null
  defaultProtocolSettings = null
}

// rendering
// =

function render () {
  // only render if this page is active
  if (!browserInfo)
    return

  yo.update(document.querySelector('#el-content'), yo`<div class="pane" id="el-content">
    <div class="settings">
      <div class="ll-heading">Auto-updater</div>
      ${renderAutoUpdater()}
      <div class="ll-heading">Application Info</div>
      <div class="s-section">
        <div><strong>Version:</strong> ${browserInfo.version}</div>
        <div><strong>User data:</strong> ${browserInfo.paths.userData}</div>
      </div>
      <div class="ll-heading">Protocols</div>
      ${renderProtocolSettings()}
    </div>
  </div>`)
}

function renderProtocolSettings () {
  function register (protocol) {
    return function () {
      beakerBrowser.setAsDefaultProtocolClient(protocol)
    }
  }
  function remove (protocol) {
    return function () {
      beakerBrowser.removeAsDefaultProtocolClient(protocol)
    }
  }
  return yo`<div class="s-section">
    <div>${
      Object.keys(defaultProtocolSettings).map(p => {
        return yo`<div><b>${p.toUpperCase()}</b> <a onclick=${register(p)}>Register</a> | <a onclick=${remove(p)}>Unregister</a></div>`
      })
    }</div>
  </div>`
}

function renderAutoUpdater () {
  if (!browserInfo.updater.isBrowserUpdatesSupported) {
    return yo`<div class="s-section">
      <div>Sorry! Beaker auto-updates are only supported on the production build for MacOS and Windows.
      You will need to build new versions of Beaker from source.</div>
    </div>`
  }

  switch (browserInfo.updater.state) {
    default:
    case 'idle':
      return yo`<div class="s-section">
        <button class="btn btn-default" onclick=${onClickCheckUpdates}>Check for updates</button>
        <span class="version-info">
          ${ browserInfo.updater.error
            ? yo`<span><span class="icon icon-cancel"></span> ${browserInfo.updater.error}</span>`
            : yo`<span>
                <span class="icon icon-check"></span>
                <strong>Beaker v${browserInfo.version}</strong> is up-to-date
              </span>` }
          ${renderAutoUpdateCheckbox()}
        </span>
      </div>`
{'fraction_non_alphanumeric': 0.1422829581993569, 'fraction_numerical': 0.0, 'mean_word_length': 3.3081717451523547, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 107, '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': '346883', 'n_tokens_mistral': 1850, 'n_tokens_neox': 1858, 'n_words': 423}