<commit_before>require 'coffee-react/register'
path = require 'path-extra'
notifier = require 'node-notifier'
fs = require 'fs-extra'

# Environments
window.remote = require 'remote'
window.ROOT = path.join(__dirname, '..')
window.EXROOT = remote.getGlobal 'EXROOT'
window.APPDATA_PATH = remote.getGlobal 'APPDATA_PATH'
window.PLUGIN_PATH = path.join window.APPDATA_PATH, 'plugins'
window.POI_VERSION = remote.getGlobal 'POI_VERSION'
window.SERVER_HOSTNAME = remote.getGlobal 'SERVER_HOSTNAME'
window.MODULE_PATH = remote.getGlobal 'MODULE_PATH'
fs.ensureDirSync window.PLUGIN_PATH
fs.ensureDirSync path.join window.PLUGIN_PATH, 'node_modules'

# Shortcuts and Components
window._ = require 'underscore'
window.$ = (param) -> document.querySelector(param)
window.$$ = (param) -> document.querySelectorAll(param)
window.jQuery = require path.join(ROOT, 'components/jquery/dist/jquery')
window.React = require 'react'
window.ReactBootstrap = require 'react-bootstrap'
window.FontAwesome = require 'react-fontawesome'

{remoteStringify} = remote.require './lib/utils'

# Utils
Object.clone = (obj) ->
  JSON.parse JSON.stringify obj
Object.remoteClone = (obj) ->
  JSON.parse remoteStringify obj
window.resolveTime = (seconds) ->
  return '' if seconds < 0
  hours = Math.floor(seconds / 3600)
  seconds -= hours * 3600
  minutes = Math.floor(seconds / 60)
  seconds -= minutes * 60
  seconds = Math.floor(seconds)
  hours = "0#{hours}" if hours < 10
  minutes = "0#{minutes}" if minutes < 10
  seconds = "0#{seconds}" if seconds < 10
  "#{hours}:#{minutes}:#{seconds}"
window.log = (msg) ->
  event = new CustomEvent 'poi.alert',
    bubbles: true
    cancelable: true
    detail:
      message: msg
      type: 'default'
  window.dispatchEvent event
window.success = (msg) ->
  event = new CustomEvent 'poi.alert',
    bubbles: true
    cancelable: true
    detail:
      message: msg
      type: 'success'
  window.dispatchEvent event
window.warn = (msg) ->
  event = new CustomEvent 'poi.alert',
    bubbles: true
    cancelable: true
    detail:
      message: msg
      type: 'warning'
  window.dispatchEvent event
window.error = (msg) ->
  event = new CustomEvent 'poi.alert',
    bubbles: true
    cancelable: true
    detail:
      message: msg
      type: 'danger'
  window.dispatchEvent event

window.notify = (msg, options) ->
  # Notification config
  enabled = config.get('poi.notify.enabled', true)
  audio = config.get('poi.notify.audio', "file://#{ROOT}/assets/audio/poi.mp3")
  volume = config.get('poi.notify.volume', 1.0)
  title = 'poi'
  icon = path.join(ROOT, 'assets', 'icons', 'icon.png')
  switch options?.type
    when 'construction'
      enabled = config.get('poi.notify.construction.enabled', enabled) if enabled
      audio = config.get('poi.notify.construction.audio', audio)
    when 'expedition'
      enabled = config.get('poi.notify.expedition.enabled', enabled) if enabled
      audio = config.get('poi.notify.expedition.audio', audio)
    when 'repair'
      enabled = config.get('poi.notify.repair.enabled', enabled) if enabled
      audio = config.get('poi.notify.repair.audio', audio)
    when 'morale'
      enabled = config.get('poi.notify.morale.enabled', enabled) if enabled
      audio = config.get('poi.notify.morale.audio', audio)
    else
      enabled = config.get('poi.notify.others.enabled', enabled) if enabled
  # Overwrite by options
  if options?
    title = options.title if options.title
    icon = options.icon if options.icon
  # Send desktop notification
  return unless enabled
  if process.platform == 'win32'
    notifier.notify
      title: title
      icon: icon
      message: msg<commit_msg>Avoid requiring path-extra on each notify call<commit_after>require 'coffee-react/register'
path = require 'path-extra'
notifier = require 'node-notifier'
fs = require 'fs-extra'

# Environments
window.remote = require 'remote'
window.ROOT = path.join(__dirname, '..')
window.EXROOT = remote.getGlobal 'EXROOT'
window.APPDATA_PATH = remote.getGlobal 'APPDATA_PATH'
window.PLUGIN_PATH = path.join window.APPDATA_PATH, 'plugins'
window.POI_VERSION = remote.getGlobal 'POI_VERSION'
window.SERVER_HOSTNAME = remote.getGlobal 'SERVER_HOSTNAME'
window.MODULE_PATH = remote.getGlobal 'MODULE_PATH'
fs.ensureDirSync window.PLUGIN_PATH
fs.ensureDirSync path.join window.PLUGIN_PATH, 'node_modules'

# Shortcuts and Components
window._ = require 'underscore'
window.$ = (param) -> document.querySelector(param)
window.$$ = (param) -> document.querySelectorAll(param)
window.jQuery = require path.join(ROOT, 'components/jquery/dist/jquery')
window.React = require 'react'
window.ReactBootstrap = require 'react-bootstrap'
window.FontAwesome = require 'react-fontawesome'

{remoteStringify} = remote.require './lib/utils'

# Utils
Object.clone = (obj) ->
  JSON.parse JSON.stringify obj
Object.remoteClone = (obj) ->
  JSON.parse remoteStringify obj
window.resolveTime = (seconds) ->
  return '' if seconds < 0
  hours = Math.floor(seconds / 3600)
  seconds -= hours * 3600
  minutes = Math.floor(seconds / 60)
  seconds -= minutes * 60
  seconds = Math.floor(seconds)
  hours = "0#{hours}" if hours < 10
  minutes = "0#{minutes}" if minutes < 10
  seconds = "0#{seconds}" if seconds < 10
  "#{hours}:#{minutes}:#{seconds}"
window.log = (msg) ->
  event = new CustomEvent 'poi.alert',
    bubbles: true
    cancelable: true
    detail:
      message: msg
      type: 'default'
  window.dispatchEvent event
window.success = (msg) ->
  event = new CustomEvent 'poi.alert',
    bubbles: true
    cancelable: true
    detail:
      message: msg
      type: 'success'
  window.dispatchEvent event
window.warn = (msg) ->
  event = new CustomEvent 'poi.alert',
    bubbles: true
    cancelable: true
    detail:
      message: msg
      type: 'warning'
  window.dispatchEvent event
window.error = (msg) ->
  event = new CustomEvent 'poi.alert',
    bubbles: true
    cancelable: true
    detail:
      message: msg
      type: 'danger'
  window.dispatchEvent event

NOTIFY_DEFAULT_ICON = path.join(ROOT, 'assets', 'icons', 'icon.png')
window.notify = (msg, options) ->
  # Notification config
  enabled = config.get('poi.notify.enabled', true)
  audio = config.get('poi.notify.audio', "file://#{ROOT}/assets/audio/poi.mp3")
  volume = config.get('poi.notify.volume', 1.0)
  title = 'poi'
  icon = NOTIFY_DEFAULT_ICON
  switch options?.type
    when 'construction'
      enabled = config.get('poi.notify.construction.enabled', enabled) if enabled
      audio = config.get('poi.notify.construction.audio', audio)
    when 'expedition'
      enabled = config.get('poi.notify.expedition.enabled', enabled) if enabled
      audio = config.get('poi.notify.expedition.audio', audio)
    when 'repair'
      enabled = config.get('poi.notify.repair.enabled', enabled) if enabled
      audio = config.get('poi.notify.repair.audio', audio)
    when 'morale'
      enabled = config.get('poi.notify.morale.enabled', enabled) if enabled
      audio = config.get('poi.notify.morale.audio', audio)
    else
      enabled = config.get('poi.notify.others.enabled', enabled) if enabled
  # Overwrite by options
  if options?
    title = options.title if options.title
    icon = options.icon if options.icon
  # Send desktop notification
  return unless enabled
  if process.platform == 'win32'
    notifier.notify
      title: title
      icon: icon
      message: msg
{'fraction_non_alphanumeric': 0.12806281304995262, 'fraction_numerical': 0.007310139434141058, 'mean_word_length': 3.7207667731629392, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4378945', 'n_tokens_mistral': 2368, 'n_tokens_neox': 2343, 'n_words': 573}