From 11a77231bf743a00be205330b15c100125ae5f1c Mon Sep 17 00:00:00 2001 From: Orion1 Date: Sun, 26 Oct 2014 19:31:37 +0100 Subject: [PATCH] added logic for 'notifications across controllers' --- app/libs/runeaudio.php | 22 +++++++++++++--------- command/rune_SY_wrk | 10 ++++++++++ index.php | 5 +++++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/libs/runeaudio.php b/app/libs/runeaudio.php index f2741efe..bdf4a692 100755 --- a/app/libs/runeaudio.php +++ b/app/libs/runeaudio.php @@ -2625,30 +2625,34 @@ function deleteRadio($mpd,$redis,$data) function ui_notify($title = null, $text, $type = null, $permanotice = null) { - if (is_object($permanotice)) { - $output = array('permanotice' => $permanotice->name, 'permaremove' => $permanotice->name); + if ($title === 'raw') { + ui_render('notify', $text); } else { - if (isset($permanotice)) { - $output = array('title' => $title, 'text' => $text, 'type' => $type, 'permanotice' => $permanotice); + if (is_object($permanotice)) { + $output = array('permanotice' => $permanotice->name, 'permaremove' => $permanotice->name); } else { - $output = array('title' => $title, 'text' => $text, 'type' => $type); + if (isset($permanotice)) { + $output = array('title' => $title, 'text' => $text, 'permanotice' => $permanotice); + } else { + $output = array('title' => $title, 'text' => $text); + } } + ui_render('notify', json_encode($output)); } - ui_render('notify', json_encode($output)); } function ui_notify_async($title = null, $text, $type = null, $permanotice = null) { if ($title === 'Kernel switch') { - $output = array('title' => $title, 'text' => $text, 'type' => 'kernelswitch', 'btntext' => 'Reboot now'); + $output = array('title' => $title, 'text' => $text, 'custom' => 'kernelswitch'); } else { if (is_object($permanotice)) { $output = array('permanotice' => $permanotice->name, 'permaremove' => $permanotice->name); } else { if (isset($permanotice)) { - $output = array('title' => $title, 'text' => $text, 'type' => $type, 'permanotice' => $permanotice); + $output = array('title' => $title, 'text' => $text, 'permanotice' => $permanotice); } else { - $output = array('title' => $title, 'text' => $text, 'type' => $type); + $output = array('title' => $title, 'text' => $text); } } } diff --git a/command/rune_SY_wrk b/command/rune_SY_wrk index 514c6733..235e7dcb 100755 --- a/command/rune_SY_wrk +++ b/command/rune_SY_wrk @@ -721,6 +721,16 @@ $redis->pconnect('/tmp/redis.sock'); sysCmd('systemctl restart '.$job->args); $redis->sRem('w_lock', $jobID); break; + case 'ui_notify': + runelog('wrk_SY: ', $job->wrkcmd); + runelog('ui_notify (raw)', $job->args); + usleep(250000); + // send notify to RuneUI + foreach ($job->args as $raw_notification) { + ui_notify('raw', $raw_notification); + } + $redis->sRem('w_lock', $jobID); + break; } // end switch // delete processed job from the w_queue $redis->hDel('w_queue', $jobID); diff --git a/index.php b/index.php index ba305f6d..f876175e 100755 --- a/index.php +++ b/index.php @@ -132,6 +132,11 @@ // close SPOP connection closeSpopSocket($spop); } +// notifications +$notifications = $redis->hGetAll('notifications'); +if ($notifications !== '') { + wrk_control($redis, 'newjob', $data = array('wrkcmd' => 'ui_notify', 'args' => $notifications)); +} // close Redis connection // $redis->close(); // close session