From e09e9b71bf722807eb47f852fbab155592bbb81b Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sun, 27 May 2018 01:18:42 -0400 Subject: [PATCH] =?utf8?q?BarnOwl::Module::RT:=20Launch=20rt=20asynchronou?= =?utf8?q?sly,=20so=20we=20don=E2=80=99t=20block=20the=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Anders Kaseorg --- rt/BarnOwl/lib/BarnOwl/Module/RT.pm | 34 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/rt/BarnOwl/lib/BarnOwl/Module/RT.pm b/rt/BarnOwl/lib/BarnOwl/Module/RT.pm index 4963eff..609200f 100644 --- a/rt/BarnOwl/lib/BarnOwl/Module/RT.pm +++ b/rt/BarnOwl/lib/BarnOwl/Module/RT.pm @@ -12,7 +12,7 @@ Foo =cut package BarnOwl::Module::RT; -use IPC::Open3; +use AnyEvent::Util qw(run_cmd); use Text::ParseWords; our $VERSION = '1.0.1'; @@ -105,23 +105,21 @@ sub cmd_rt{ } sub run_rt_command{ - my @args = ("athrun","tooltime","rt"); - push (@args, @_); - local(*IN, *OUT, *ERR); - my $pid = open3(*IN, *OUT, *ERR, @args) || die("RT threw $!"); - close(*IN); - my $out = do { local $/; }; - close(*OUT); - $out .= do { local $/; }; - close(*ERR); - - waitpid( $pid, 0 ); - - if (($out =~ tr/\n//) eq 1){ - return $out; - } - BarnOwl::popless_text($out); - return; + my $out; + run_cmd( + ["athrun", "tooltime", "rt", @_], + "<", "/dev/null", + ">", \$out, + "2>", \$out, + )->cb(sub { + my $ret = shift->recv; + $ret == 0 or die("RT returned $ret"); + if (($out =~ tr/\n//) == 1) { + BarnOwl::message($out); + } else { + BarnOwl::popless_text($out); + } + }); } BarnOwl::new_command("rt", -- 2.45.0