<commit_before>path = require 'path-extra'
fs = require 'fs-extra'
glob = require 'glob'
rimraf = require 'rimraf'
{$, $$, _, React, ReactBootstrap, FontAwesome, ROOT} = window
{Grid, Col, Button, ButtonGroup, Input, Alert} = ReactBootstrap
{config, toggleModal} = window
{APPDATA_PATH} = window
{showItenInFolder, openItem} = require 'shell'
Divider = require './divider'
NavigatorBar = require './navigator-bar'
themes = glob.sync(path.join(ROOT, 'assets', 'themes', '*')).map (filePath) ->
  path.basename filePath
PoiConfig = React.createClass
  getInitialState: ->
    layout: config.get 'poi.layout', 'horizonal'
    theme: config.get 'poi.theme', '__default__'
    gameWidth: config.get('poi.scale', window.gameScale) * window.innerWidth
    useFixedResolution: if config.get('poi.scale') then true else false
    enableConfirmQuit: config.get 'poi.confirm.quit', false
  handleSetConfirmQuit: ->
    enabled = @state.enableConfirmQuit
    config.set 'poi.confirm.quit', !enabled
    @setState
      enableConfirmQuit: !enabled
  handleSetLayout: (layout) ->
    return if @state.layout == layout
    config.set 'poi.layout', layout
    event = new CustomEvent 'layout.change',
      bubbles: true
      cancelable: true
      detail:
        layout: layout
    window.dispatchEvent event
    @setState {layout}
  handleSetTheme: (theme) ->
    theme = @refs.theme.getValue()
    return if @state.theme == theme
    config.set 'poi.theme', theme
    event = new CustomEvent 'theme.change',
      bubbles: true
      cancelable: true
      detail:
        theme: theme
    window.dispatchEvent event
    @setState {theme}
  handleSetScale: (e) ->
    @setState
      gameWidth: @refs.scale.getValue()
    width = parseInt @refs.scale.getValue()
    return if isNaN(width) || width < 0 || !@state.useFixedResolution
    scale = width / window.innerWidth
    window.gameScale = scale
    window.dispatchEvent new Event('scale.change')
    config.set 'poi.scale', scale
  handleResize: ->
    {gameWidth} = @state
    width = parseInt gameWidth
    return if isNaN(width) || width < 0
    if @state.useFixedResolution
      scale = width / window.innerWidth
      window.gameScale = scale
      window.dispatchEvent new Event('scale.change')
      config.set 'poi.scale', scale
    else
      @setState
        gameWidth: window.innerWidth * window.gameScale
  handleSetFixedResolution: (e) ->
    current = @state.useFixedResolution
    if current
      config.set 'poi.scale', null
      @setState
        useFixedResolution: false
    else
      @setState
        useFixedResolution: true
      @handleResize()
  handleClearCookie: (e) ->
    rimraf path.join(APPDATA_PATH, 'Cookies'), (err) ->
      if err?
        toggleModal '删除 Cookies', "删除失败，你可以手动删除 #{path.join(APPDATA_PATH, 'Cookies')}"
        try
            fs.ensureFileSync path.join(APPDATA_PATH, '')
            openItem path.join(APPDATA_PATH, '')
        catch e
            toggleModal '打开缓存目录','打开失败，可能没有访问权限'
      else
        toggleModal '删除 Cookies', '删除成功，请立刻重启软件。'
  handleClearCache: (e) ->
    error = null
    rimraf path.join(APPDATA_PATH, 'Cache'), (err) ->
      error = error || err
      rimraf path.join(APPDATA_PATH, 'Pepper Data'), (err) ->
        error = error || err
        if error
          toggleModal '删除浏览器缓存', "删除失败，你可以手动删除 #{path.join(APPDATA_PATH, 'Cache')} 和 #{path.join(APPDATA_PATH, 'Pepper Data')}"
          try
            fs.ensureFileSync path.join(APPDATA_PATH, '')
            openItem path.join(APPDATA_PATH, '')
          catch e
            toggleModal '打开缓存目录','打开失败，可能没有访问权限'
        else
          toggleModal '删除浏览器缓存', '删除成功，请立刻重启软件。'
  handleOpenCustomCss: (e) ->
    try
      d = path.join(EXROOT, 'hack', 'custom.css')
      fs.ensureFileSync d
      openItem d
    catch e
      toggleModal '编辑自定义 CSS', '打开失败，可能没有创建文件的权限'
  componentDidMount: ->
    window.addEventListener 'resize', @handleResize
  componentWillUnmount: ->
    window.removeEventListener 'resize', @handleResize
  render: ->
    <form id="poi-config">
      <div className="form-group" id='navigator-bar'><commit_msg>Improve coding style<commit_after>path = require 'path-extra'
fs = require 'fs-extra'
glob = require 'glob'
rimraf = require 'rimraf'
{$, $$, _, React, ReactBootstrap, FontAwesome, ROOT} = window
{Grid, Col, Button, ButtonGroup, Input, Alert} = ReactBootstrap
{config, toggleModal} = window
{APPDATA_PATH} = window
{showItenInFolder, openItem} = require 'shell'
Divider = require './divider'
NavigatorBar = require './navigator-bar'
themes = glob.sync(path.join(ROOT, 'assets', 'themes', '*')).map (filePath) ->
  path.basename filePath
PoiConfig = React.createClass
  getInitialState: ->
    layout: config.get 'poi.layout', 'horizonal'
    theme: config.get 'poi.theme', '__default__'
    gameWidth: config.get('poi.scale', window.gameScale) * window.innerWidth
    useFixedResolution: if config.get('poi.scale') then true else false
    enableConfirmQuit: config.get 'poi.confirm.quit', false
  handleSetConfirmQuit: ->
    enabled = @state.enableConfirmQuit
    config.set 'poi.confirm.quit', !enabled
    @setState
      enableConfirmQuit: !enabled
  handleSetLayout: (layout) ->
    return if @state.layout == layout
    config.set 'poi.layout', layout
    event = new CustomEvent 'layout.change',
      bubbles: true
      cancelable: true
      detail:
        layout: layout
    window.dispatchEvent event
    @setState {layout}
  handleSetTheme: (theme) ->
    theme = @refs.theme.getValue()
    return if @state.theme == theme
    config.set 'poi.theme', theme
    event = new CustomEvent 'theme.change',
      bubbles: true
      cancelable: true
      detail:
        theme: theme
    window.dispatchEvent event
    @setState {theme}
  handleSetScale: (e) ->
    @setState
      gameWidth: @refs.scale.getValue()
    width = parseInt @refs.scale.getValue()
    return if isNaN(width) || width < 0 || !@state.useFixedResolution
    scale = width / window.innerWidth
    window.gameScale = scale
    window.dispatchEvent new Event('scale.change')
    config.set 'poi.scale', scale
  handleResize: ->
    {gameWidth} = @state
    width = parseInt gameWidth
    return if isNaN(width) || width < 0
    if @state.useFixedResolution
      scale = width / window.innerWidth
      window.gameScale = scale
      window.dispatchEvent new Event('scale.change')
      config.set 'poi.scale', scale
    else
      @setState
        gameWidth: window.innerWidth * window.gameScale
  handleSetFixedResolution: (e) ->
    current = @state.useFixedResolution
    if current
      config.set 'poi.scale', null
      @setState
        useFixedResolution: false
    else
      @setState
        useFixedResolution: true
      @handleResize()
  handleClearCookie: (e) ->
    rimraf path.join(APPDATA_PATH, 'Cookies'), (err) ->
      if err?
        toggleModal '删除 Cookies', "删除失败，你可以手动删除 #{path.join(APPDATA_PATH, 'Cookies')}"
        try
            fs.ensureFileSync APPDATA_PATH
            openItem APPDATA_PATH
        catch e
            toggleModal '打开缓存目录','打开失败，可能没有访问权限'
      else
        toggleModal '删除 Cookies', '删除成功，请立刻重启软件。'
  handleClearCache: (e) ->
    error = null
    rimraf path.join(APPDATA_PATH, 'Cache'), (err) ->
      error = error || err
      rimraf path.join(APPDATA_PATH, 'Pepper Data'), (err) ->
        error = error || err
        if error
          toggleModal '删除浏览器缓存', "删除失败，你可以手动删除 #{path.join(APPDATA_PATH, 'Cache')} 和 #{path.join(APPDATA_PATH, 'Pepper Data')}"
          try
            fs.ensureFileSync APPDATA_PATH
            openItem APPDATA_PATH
          catch e
            toggleModal '打开缓存目录','打开失败，可能没有访问权限'
        else
          toggleModal '删除浏览器缓存', '删除成功，请立刻重启软件。'
  handleOpenCustomCss: (e) ->
    try
      d = path.join(EXROOT, 'hack', 'custom.css')
      fs.ensureFileSync d
      openItem d
    catch e
      toggleModal '编辑自定义 CSS', '打开失败，可能没有创建文件的权限'
  componentDidMount: ->
    window.addEventListener 'resize', @handleResize
  componentWillUnmount: ->
    window.removeEventListener 'resize', @handleResize
  render: ->
    <form id="poi-config">
      <div className="form-group" id='navigator-bar'>
{'fraction_non_alphanumeric': 0.12085626911314985, 'fraction_numerical': 0.0004892966360856269, 'mean_word_length': 2.967006307617661, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, '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': '6432011', 'n_tokens_mistral': 2683, 'n_tokens_neox': 2795, 'n_words': 611}