Created
June 20, 2014 15:50
-
-
Save syphoxy/a986d5f20afbdd53fc7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('RELAY_HOST', '127.0.0.1'); | |
define('RELAY_PORT', 4545); | |
define('APP_TOKEN', 'REMOVED'); | |
header('Content-type: application/json'); | |
if (!isset($_REQUEST['token']) || $_REQUEST['token'] !== APP_TOKEN) { | |
echo json_encode(array( | |
'status' => 'error', | |
'message' => 'Application token is invalid.' | |
)); | |
exit; | |
} | |
if (isset($_REQUEST['title']) && isset($_REQUEST['message'])) { | |
$title = $_REQUEST['title']; | |
$message = $_REQUEST['message']; | |
} else { | |
echo json_encode(array( | |
'status' => 'error', | |
'message' => 'Malformed request.' | |
)); | |
exit; | |
} | |
$client = stream_socket_client('tcp://' . RELAY_HOST . ':' . RELAY_PORT, $errno, $error); | |
if ($client === false) { | |
echo json_encode(array( | |
'status' => 'error', | |
'message' => 'Could not connect to relay server.' | |
)); | |
exit; | |
} | |
fwrite($client, json_encode(array( | |
'title' => $title, | |
'message' => $message | |
)) . PHP_EOL); | |
fclose($client); | |
echo json_encode(array('status' => 'success')); | |
exit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'socket' | |
require 'dbus' | |
require 'yajl' | |
Process.detach(fork do | |
server = TCPServer.new('127.0.0.1', 4545) | |
loop do | |
Thread.start(server.accept) do |client| | |
d = DBus::SessionBus.instance | |
o = d.service('org.freedesktop.Notifications').object('/org/freedesktop/Notifications') | |
o.introspect | |
i = o['org.freedesktop.Notifications'] | |
request = Yajl::Parser.parse(client.gets.strip) | |
i.Notify('extnotifd', 0, 'info', request['title'], request['message'], [], {}, 2000) | |
client.close | |
end | |
end | |
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'socket' | |
require 'yajl' | |
require 'terminal-notifier' | |
Process.detach(fork do | |
server = TCPServer.new('127.0.0.1', 4545) | |
loop do | |
Thread.start(server.accept) do |client| | |
request = Yajl::Parser.parse(client.gets.strip) | |
TerminalNotifier.notify(request['message'], title: request['title']) | |
client.close | |
end | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment