I don't really need a named pipe

This commit is contained in:
Jack L. Frost 2016-09-29 11:16:25 +03:00
parent c1ffc8cb6c
commit dd8968571a

View File

@ -4,9 +4,10 @@ $PROGRAM_NAME = "moltenbar"
# Base worker class
class Worker
def initialize(config, name)
def initialize(config, name, pipe)
@config = config
@name = name
@pipe_in = pipe
end
def run()
@ -14,9 +15,6 @@ class Worker
$PROGRAM_NAME = "moltenbar: worker (#{@name})"
Signal.trap("INT") do; end
@pipe_in = File.open(@config['fifo_in'], "w")
@pipe_in.sync = true
mainloop()
end
@ -73,6 +71,8 @@ def cleanup(workers)
for w in workers do
w.kill
end
exit(0)
end
def get_x_dims
@ -98,15 +98,14 @@ puts 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
load("#{mod_dir}/#{m}")
end
pipe_r, pipe_w = IO.pipe
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
m.run
@ -115,8 +114,6 @@ end
Signal.trap("INT") do cleanup(workers); end
Signal.trap("TERM") do cleanup(workers); end
pipe_in = File.open(config['fifo_in'], "r")
if config['geometry'] == nil
config['gap'] ||= 0
config['height'] ||= 14
@ -143,13 +140,17 @@ lemonbar_cmd = [
puts "Launching lemonbar as: " + lemonbar_cmd.join(" ")
IO.popen(lemonbar_cmd, "w") do |pipe_out|
pipe_out.sync = true
IO.popen(lemonbar_cmd, "w+") do |pipe_lb|
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")
panel_data[mod_name] = data
pipe_out.puts config['format'].erb
pipe_lb.puts config['format'].erb
end
end