Skip to content

Instantly share code, notes, and snippets.

@leafo
Created October 24, 2017 06:34
Show Gist options
  • Save leafo/d701477c97bfae385fbfcf4597d8ae86 to your computer and use it in GitHub Desktop.
Save leafo/d701477c97bfae385fbfcf4597d8ae86 to your computer and use it in GitHub Desktop.
textbox = require "wibox.widget.textbox"
awful = require "awful"
naughty = require "naughty"
local selfwatch_text
make_selfwatch_textbox = (timeout=60) ->
return selfwatch_text if selfwatch_text
w = textbox!
check_running = (fn) ->
awful.spawn.easy_async "pidof selfwatch", (stdout, stderr, reason, code) ->
fn code == 0
get_status = (fn) ->
awful.spawn.easy_async "selfwatch -config /home/leafo/.selfwatch/selfwatch.json status", (stdout, stderr, reason, code) ->
fn stdout
t = with timer(:timeout)
\connect_signal "timeout", ->
check_running (running) ->
if running
get_status (status) ->
w\set_markup '<span color="#B7CE42">✓ ' .. status .. '</span> '
else
w\set_markup '<span color="#F00060">✕ SW</span> '
\start!
\emit_signal "timeout"
w\connect_signal "button::press", ->
t\emit_signal "timeout"
selfwatch_text = w
w
{ :make_selfwatch_textbox, }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment