I don't really need a named pipe
This commit is contained in:
parent
c1ffc8cb6c
commit
dd8968571a
29
moltenbar
29
moltenbar
|
@ -4,9 +4,10 @@ $PROGRAM_NAME = "moltenbar"
|
||||||
|
|
||||||
# Base worker class
|
# Base worker class
|
||||||
class Worker
|
class Worker
|
||||||
def initialize(config, name)
|
def initialize(config, name, pipe)
|
||||||
@config = config
|
@config = config
|
||||||
@name = name
|
@name = name
|
||||||
|
@pipe_in = pipe
|
||||||
end
|
end
|
||||||
|
|
||||||
def run()
|
def run()
|
||||||
|
@ -14,9 +15,6 @@ class Worker
|
||||||
$PROGRAM_NAME = "moltenbar: worker (#{@name})"
|
$PROGRAM_NAME = "moltenbar: worker (#{@name})"
|
||||||
Signal.trap("INT") do; end
|
Signal.trap("INT") do; end
|
||||||
|
|
||||||
@pipe_in = File.open(@config['fifo_in'], "w")
|
|
||||||
@pipe_in.sync = true
|
|
||||||
|
|
||||||
mainloop()
|
mainloop()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -73,6 +71,8 @@ def cleanup(workers)
|
||||||
for w in workers do
|
for w in workers do
|
||||||
w.kill
|
w.kill
|
||||||
end
|
end
|
||||||
|
|
||||||
|
exit(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_x_dims
|
def get_x_dims
|
||||||
|
@ -98,15 +98,14 @@ puts config_file
|
||||||
|
|
||||||
config = YAML.load_file(config_file)
|
config = YAML.load_file(config_file)
|
||||||
|
|
||||||
# Create a named pipe unless one exists
|
|
||||||
File.mkfifo(config['fifo_in']) unless File.exist?(config['fifo_in'])
|
|
||||||
|
|
||||||
for m in config['modules'] do
|
for m in config['modules'] do
|
||||||
load("#{mod_dir}/#{m}")
|
load("#{mod_dir}/#{m}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
pipe_r, pipe_w = IO.pipe
|
||||||
|
|
||||||
Modules.get.each do |k, v|
|
Modules.get.each do |k, v|
|
||||||
m = Object.const_get(v).new(config, k)
|
m = Object.const_get(v).new(config, k, pipe_w)
|
||||||
workers << m
|
workers << m
|
||||||
|
|
||||||
m.run
|
m.run
|
||||||
|
@ -115,8 +114,6 @@ end
|
||||||
Signal.trap("INT") do cleanup(workers); end
|
Signal.trap("INT") do cleanup(workers); end
|
||||||
Signal.trap("TERM") do cleanup(workers); end
|
Signal.trap("TERM") do cleanup(workers); end
|
||||||
|
|
||||||
pipe_in = File.open(config['fifo_in'], "r")
|
|
||||||
|
|
||||||
if config['geometry'] == nil
|
if config['geometry'] == nil
|
||||||
config['gap'] ||= 0
|
config['gap'] ||= 0
|
||||||
config['height'] ||= 14
|
config['height'] ||= 14
|
||||||
|
@ -143,13 +140,17 @@ lemonbar_cmd = [
|
||||||
|
|
||||||
puts "Launching lemonbar as: " + lemonbar_cmd.join(" ")
|
puts "Launching lemonbar as: " + lemonbar_cmd.join(" ")
|
||||||
|
|
||||||
IO.popen(lemonbar_cmd, "w") do |pipe_out|
|
IO.popen(lemonbar_cmd, "w+") do |pipe_lb|
|
||||||
pipe_out.sync = true
|
pipe_lb.sync = true
|
||||||
|
|
||||||
pipe_in.each do |line|
|
Signal.trap("USR1") do
|
||||||
|
pipe_lb.puts config['format'].erb
|
||||||
|
end
|
||||||
|
|
||||||
|
pipe_r.each do |line|
|
||||||
mod_name, data = line.chomp.split("\0")
|
mod_name, data = line.chomp.split("\0")
|
||||||
panel_data[mod_name] = data
|
panel_data[mod_name] = data
|
||||||
|
|
||||||
pipe_out.puts config['format'].erb
|
pipe_lb.puts config['format'].erb
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user