Last active
August 29, 2015 14:07
-
-
Save fasterthanlime/776e597cc03360c0a917 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'net/http' | |
require 'cgi' | |
require 'uri' | |
def wifi_info | |
uri = URI("http://192.168.1.1/Info.live.htm") | |
body = Net::HTTP.get(uri) | |
wireless = body.split("\n").select { |x| x =~ /active_wireless/ }[0] | |
wireless = wireless[1..-2].split(',')[1..-1].map { |x| x[1..-2] } | |
keys = [ | |
:iface, | |
:uptime, | |
:tx, | |
:rx, | |
:signal, | |
:noise, | |
:snr, | |
:unk | |
] | |
map = {} | |
for i in 0...keys.size | |
map[keys[i]] = wireless[i] | |
end | |
map | |
end | |
require "osx/cocoa" | |
include OSX | |
#app = NSApplication.sharedApplication | |
class WifiLoop | |
def start | |
@statusitem = NSStatusBar.systemStatusBar().statusItemWithLength(NSVariableStatusItemLength) | |
@timer = NSTimer.scheduledTimerWithTimeInterval 1, | |
target: self, | |
selector: 'refresh:', | |
userInfo: nil, | |
repeats: true | |
end | |
def refresh(timer) | |
info = wifi_info | |
@statusitem.setTitle("↑ #{info[:tx]} ↓ #{info[:rx]} ☁ #{info[:snr]}") | |
end | |
end | |
puts "Starting loop." | |
WifiLoop.new.start | |
NSRunLoop.currentRunLoop.runUntilDate(NSDate.distantFuture) | |
puts "Starting app.." | |
app.run | |
puts "App started!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment