Skip to content

Instantly share code, notes, and snippets.

@ralt
Created December 15, 2014 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralt/7c3fa557971803f55a7f to your computer and use it in GitHub Desktop.
Save ralt/7c3fa557971803f55a7f to your computer and use it in GitHub Desktop.
Progress... on a chrome NativeMessaging receiving app
chrome.browserAction.onClicked.addListener(connect);
;;;; pgp-ext-app.lisp
(in-package #:pgp-ext-app)
;;; "pgp-ext-app" goes here. Hacks and glory await!
(defun main (&rest args)
"Application's entry point."
(declare (ignore args))
(read-stdin *standard-input*))
(defun read-stdin ()
(with-open-file (stream "/home/florian/test.log" :direction :output :if-exists :append :if-does-not-exist :create)
(with-open-stream (s *standard-input*)
(let* ((length (parse-length (get-elements s 4)))
(buffer (chars-to-string (get-elements s length))))
`(send-to-ext (jsown:to-json '(:obj ("text" . ,buffer))))))))
(defun get-elements (stream number &optional ret)
"Gets x elements off of a stream"
(if (= number 0)
ret
(get-elements stream (- number 1) (cons ret (read-char stream nil)))))
(defun chars-to-string (chars)
(format nil "~{~c~}" chars))
;;; The missing part
(defun parse-length (bytes))
(defun string-to-chars (str)
(loop for c across str collect c))
(defun send-to-ext (str)
(let ((len (length str)))
(format *standard-output*
"~c~c~c~c~{~c~}"
(code-char (logand len #xFF))
(code-char (logand (ash len 8) #xFF))
(code-char (logand (ash len 16) #xFF))
(code-char (logand (ash len 24) #xFF))
(string-to-chars str))))
function connect() {
var port = chrome.runtime.connectNative('com.margaine.pgp_ext_app');
port.onMessage.addListener(function(msg) {
console.log("Received", msg);
});
port.onDisconnect.addListener(function() {
console.log("Disconnected");
});
console.log('1');
port.postMessage("{ text: \"Hello, my_application\" }\n");
console.log('2');
port.postMessage({ text: "Hello again!" });
console.log('3');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment