1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
require 'osx/cocoa'
include OSX
class AppDelegate < NSObject
def applicationDidFinishLaunching(aNotification)
url = ARGV[0].dup
url.gsub!(/http:\/\//, "http://slactoid:easy4kastner@")
begin
Thread.start { OSX::NSRunLoop.currentRunLoop.run }
cmd = "cd ~ && axel -a #{url}"
last_number = 0
IO.popen(cmd) do |pipe|
pipe.each("\r") do |line|
number = line[/[^\d]([\d]+)%/].to_i
speed = line[/[^\d][\d\.]+KB\/s/].to_f
if last_number != number
last_number = number
advance_slider(number)
write_speed(speed)
end
end
end
rescue
end
end
def moveForward(sender)
puts sender.setTitle("bob")
end
def advance_slider(value)
$pro.setDoubleValue(value.to_f)
$pro.stopAnimation($pro)
end
def write_speed(speed)
$txt.setStringValue(speed)
end
end
if $0 == __FILE__ then
OSX.ruby_thread_switcher_start(0.001, 0.1)
$stderr.print "just wait..." ; $stderr.flush
app = NSApplication.sharedApplication()
app.setDelegate(AppDelegate.alloc.init)
frame = [400.0, 300.0, 452.0, 107.0]
win = NSWindow.alloc.initWithContentRect_styleMask_backing_defer(frame, 15, 2, 0)
win.setTitle 'Axel Progress'
win.setLevel(3)
$pro = NSProgressIndicator.alloc.initWithFrame [18.0, 48.0, 416.0, 20.0]
$pro.setIndeterminate(0)
$pro.setDoubleValue(0)
win.contentView.addSubview($pro)
$txt = NSTextField.alloc.initWithFrame [316.0, 10.0, 114.0, 22.0]
$txt.setEditable(0)
$txt.setSelectable(0)
$txt.setBezeled(0)
$txt.setDrawsBackground(0)
$txt.setAlignment(NSRightTextAlignment)
win.contentView.addSubview($txt)
win.display()
win.orderFrontRegardless()
app.run()
exit 0
end
|