<commit_before>log = require './log'

{react_utils, theme, mixins, components, sounds, format_time} = require './common_ui.coffee'
# MyoUI includes some React utils.
{Component, React, ReactDOM} = react_utils
{div} = React.DOM
# "Component" returns a radium component which will allow us
# to use arrays and objects combined in the same style property.

is_linux = process.platform == 'linux'

electron = require 'electron'
ewin = electron.remote.getCurrentWindow()
window.$window = ewin
ewin.setAlwaysOnTop true
ewin.setVisibleOnAllWorkspaces true

addEventListener 'keydown', (event)->
    if event.keyCode == 123
        ewin.webContents.openDevTools({mode:'detach'})

settings = ewin.settings
window.$settings = settings

AutoLaunch = require 'auto-launch'
auto_launcher = window.auto_launcher = new AutoLaunch
    name: 'myou-log'

if settings.open_on_startup
    auto_launcher.enable().then ()->
        console.log 'Open on system startup ENABLED'
else
    console.log 'Open on system startup DISABLED'
    auto_launcher.disable()

{Tray, Menu, app, globalShortcut} = electron.remote
path = require 'path'
trayMenuTemplate = [

    {
       label: 'Show app',
       click: ->
          show_window()
    }
    {
       label: 'Report viewer',
       click: ->
          ewin.create_report_window()
    }
    {
       label: 'Quit',
       click: ->
           localStorage.myoulog_win_position = JSON.stringify ewin.getPosition()
           tray.destroy()
           ewin.close()
    }
]

trayMenu = Menu.buildFromTemplate trayMenuTemplate

tray = new Tray __dirname + '/../static_files/images/icon.png'

tray.setContextMenu trayMenu
tray.on 'click', ->
    show_window()
ewin.on 'minimize', ->
    hide_window()

addEventListener 'beforeunload', ->
    tray.destroy()
    globalShortcut.unregisterAll()

win_position = localStorage.myoulog_win_position
if win_position
    win_position = JSON.parse win_position
    ewin.setPosition win_position[0], win_position[1]

show_window_timeout = null
hide_window = (break_time=0)->
    break_time = break_time or settings.auto_show_window_timeout
    ewin.hide()
    console.log "Set timeout to show window in #{format_time break_time}."
    show = ->
        show_window(true)
    show_window_timeout = setTimeout show, break_time

show_window_time = 0
show_window = (alarm)->
    show_window_time = Date.now()
    ewin.setAlwaysOnTop true
    clearTimeout show_window_timeout
    # play again (not pause)
    if log.is_paused
        log.new_entry {pause:false, date:show_window_time}
    ewin.show()
    ewin.blur()
    if alarm
        ui_alarm?()
    else
        render_all?()
    set_inactivity_check?()


last_check_inactivity_interval = null
set_inactivity_check = ->
    clearInterval last_check_inactivity_interval
    check_inactivity = ->
        time = (Date.now() - log.last_activity_change.date)
        if ewin.isVisible() and current_dialog == 0
            log.new_entry {active:false, date:show_window_time}
            render_all()
        ui_alarm()

    last_check_inactivity_interval = setInterval check_inactivity,
        settings.inactivity_check_interval

addEventListener 'click', set_inactivity_check
addEventListener 'keydown', -> if current_dialog == 1 then set_inactivity_check()

auto_hide_time = Infinity
last_auto_hide_interval = null
set_auto_hide_time = (time=10, callback=->)->
    clearInterval last_auto_hide_interval
    auto_hide_time = time
    if auto_hide_time == Infinity
        render_all()
        return

    auto_hide_interval = ->
        auto_hide_time -= 1
        if auto_hide_time == 0
            set_auto_hide_time Infinity
            set_dialog(0)
            callback?()<commit_msg>Back to dialog 0 when `check_inactivity` detects inactivity.<commit_after>log = require './log'

{react_utils, theme, mixins, components, sounds, format_time} = require './common_ui.coffee'
# MyoUI includes some React utils.
{Component, React, ReactDOM} = react_utils
{div} = React.DOM
# "Component" returns a radium component which will allow us
# to use arrays and objects combined in the same style property.

is_linux = process.platform == 'linux'

electron = require 'electron'
ewin = electron.remote.getCurrentWindow()
window.$window = ewin
ewin.setAlwaysOnTop true
ewin.setVisibleOnAllWorkspaces true

addEventListener 'keydown', (event)->
    if event.keyCode == 123
        ewin.webContents.openDevTools({mode:'detach'})

settings = ewin.settings
window.$settings = settings

AutoLaunch = require 'auto-launch'
auto_launcher = window.auto_launcher = new AutoLaunch
    name: 'myou-log'

if settings.open_on_startup
    auto_launcher.enable().then ()->
        console.log 'Open on system startup ENABLED'
else
    console.log 'Open on system startup DISABLED'
    auto_launcher.disable()

{Tray, Menu, app, globalShortcut} = electron.remote
path = require 'path'
trayMenuTemplate = [

    {
       label: 'Show app',
       click: ->
          show_window()
    }
    {
       label: 'Report viewer',
       click: ->
          ewin.create_report_window()
    }
    {
       label: 'Quit',
       click: ->
           localStorage.myoulog_win_position = JSON.stringify ewin.getPosition()
           tray.destroy()
           ewin.close()
    }
]

trayMenu = Menu.buildFromTemplate trayMenuTemplate

tray = new Tray __dirname + '/../static_files/images/icon.png'

tray.setContextMenu trayMenu
tray.on 'click', ->
    show_window()
ewin.on 'minimize', ->
    hide_window()

addEventListener 'beforeunload', ->
    tray.destroy()
    globalShortcut.unregisterAll()

win_position = localStorage.myoulog_win_position
if win_position
    win_position = JSON.parse win_position
    ewin.setPosition win_position[0], win_position[1]

show_window_timeout = null
hide_window = (break_time=0)->
    break_time = break_time or settings.auto_show_window_timeout
    ewin.hide()
    console.log "Set timeout to show window in #{format_time break_time}."
    show = ->
        show_window(true)
    show_window_timeout = setTimeout show, break_time

show_window_time = 0
show_window = (alarm)->
    show_window_time = Date.now()
    ewin.setAlwaysOnTop true
    clearTimeout show_window_timeout
    # play again (not pause)
    if log.is_paused
        log.new_entry {pause:false, date:show_window_time}
    ewin.show()
    ewin.blur()
    if alarm
        ui_alarm?()
    else
        render_all?()
    set_inactivity_check?()


last_check_inactivity_interval = null
set_inactivity_check = ->
    clearInterval last_check_inactivity_interval
    check_inactivity = ->
        time = (Date.now() - log.last_activity_change.date)
        set_dialog 0
        log.new_entry {active:false, date:show_window_time}
        ui_alarm()

    last_check_inactivity_interval = setInterval check_inactivity,
        settings.inactivity_check_interval

addEventListener 'click', set_inactivity_check
addEventListener 'keydown', -> if current_dialog == 1 then set_inactivity_check()

auto_hide_time = Infinity
last_auto_hide_interval = null
set_auto_hide_time = (time=10, callback=->)->
    clearInterval last_auto_hide_interval
    auto_hide_time = time
    if auto_hide_time == Infinity
        render_all()
        return

    auto_hide_interval = ->
        auto_hide_time -= 1
        if auto_hide_time == 0
            set_auto_hide_time Infinity
            set_dialog(0)
            callback?()
{'fraction_non_alphanumeric': 0.09540588155576636, 'fraction_numerical': 0.003930071825450603, 'mean_word_length': 3.3132670952659264, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, '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': '1597345', 'n_tokens_mistral': 2331, 'n_tokens_neox': 2286, 'n_words': 522}