Created
December 15, 2014 08:57
-
-
Save ralt/7c3fa557971803f55a7f to your computer and use it in GitHub Desktop.
Progress... on a chrome NativeMessaging receiving app
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
chrome.browserAction.onClicked.addListener(connect); |
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
;;;; 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)))) |
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
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