Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ceramic/ceramic
Browse files Browse the repository at this point in the history
Conflicts:
	src/ceramic.lisp
  • Loading branch information
eudoxia0 committed Aug 9, 2015
2 parents 79a55ae + 37814a1 commit fb563ad
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 26 deletions.
4 changes: 4 additions & 0 deletions examples/ipc-example/files/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ document.addEventListener("DOMContentLoaded", function(event) {
node.onclick = function() {
ipc.send('ceramic-channel', { text: 'Clicked button' });
};

ipc.on('ceramic-channel', function(event, msg) {
console.log(msg);
});
});
15 changes: 11 additions & 4 deletions examples/ipc-example/ipc-example.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,23 @@
(defview hello ()
(render-template (+index+)))

(defvar *port* 8000)
(defvar *port* 8001)

(defvar *window*)

(setf ceramic:*event-dispatcher*
(lambda (event)
(format t "Got event! ~A~%" event)))
(let ((event-type (getf event :|event|)))
(format t "Got event of type ~S~%" event-type)
(when (string= event-type "async")
(ceramic:send-message *window*
(list (cons "text" "received!")))))))

(defun run ()
(let ((window (ceramic:make-window :url (format nil "http://localhost:~D/" *port*))))
(ceramic:show-window window)
(let ((*window* (ceramic:make-window :url (format nil "http://localhost:~D/" *port*))))
(start app :port *port*)
(ceramic:show-window *window*)
(ceramic:open-dev-tools *window*)
(ceramic::dispatch-events)))

(ceramic:define-entry-point :ceramic-hello-world ()
Expand Down
9 changes: 8 additions & 1 deletion src/ceramic.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
:hide-window
:close-window
:destroy-window
:send-message
:maximize-window
:unmaximize-window
:minimize-window
Expand Down Expand Up @@ -70,7 +71,7 @@
:operating-system *operating-system*))
t)))

+(defun stop-interactive ()
(defun stop-interactive ()
"Stop the interactive process."
(handler-case
(ceramic.electron:quit *process*)
Expand Down Expand Up @@ -245,6 +246,12 @@
(call-with-defaults ceramic.electron:destroy-window
window))

(defmethod send-message ((window window) message)
"Send an alist message to the window."
(call-with-defaults ceramic.electron:send-message
window
message))

(defmethod maximize-window ((window window))
"Maximize the window."
(call-with-defaults ceramic.electron:maximize-window
Expand Down
4 changes: 4 additions & 0 deletions src/electron/driver.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
(:export :create-window
:close-window
:destroy-window
:send-message
:show-window
:hide-window
:resize-window
Expand Down Expand Up @@ -94,6 +95,9 @@
(define-window-command destroy-window "destroy-window" ()
())

(define-window-command send-message "send-message-to-window" (message)
message)

(define-window-command show-window "show-window" ()
())

Expand Down
27 changes: 19 additions & 8 deletions src/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ function eventIPC(message) {
writeEvent({ "event": "async", "msg": message });
};

/* IPC */

const CHANNEL = 'ceramic-channel';

ipc.on(CHANNEL, function(event, object) {
/* When receiving an asynchronous message, we write it to stdout as an async
event. */
eventIPC(object);
});

/* Commands */

// Windows
Expand All @@ -44,6 +54,12 @@ function windowDestroy(name) {
window_db[name].destroy();
};

//// IPC

function windowSendMessage(name, message) {
window_db[name].webContents.send(CHANNEL, message);
};

//// Display

function windowShow(name) {
Expand Down Expand Up @@ -186,6 +202,9 @@ const dispatcher = {
'destroy-window': function(data) {
windowDestroy(data['name']);
},
'send-message-to-window': function(data) {
windowSendMessage(data['name'], data['message']);
},
//// Display
'show-window': function(data) {
windowShow(data['name']);
Expand Down Expand Up @@ -278,14 +297,6 @@ function dispatchCommand(data) {
dispatcher[command](data);
};

/* IPC */

ipc.on('ceramic-channel', function(event, object) {
/* When receiving an asynchronous message, we write it to stdout as an async
event. */
eventIPC(object);
});

/* Start up */

app.on('ready', function() {
Expand Down
14 changes: 1 addition & 13 deletions t/integration.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,7 @@
(is
(equal (ceramic.resource:resource 'ceramic-test-app::files #p"file.txt")
(asdf:system-relative-pathname :ceramic-test-app
#p"files/file.txt")))
;; Run the app
(let* ((process (external-program:start (namestring binary) (list)
:output :stream))
(stdout (external-program:process-output-stream process)))
(sleep 0.1)
(is
(equal (read-line stdout) "T"))
(is
(equal (read-line stdout)
(namestring
(merge-pathnames #p"resources/files/file.txt"
*extraction-directory*)))))))
#p"files/file.txt")))))

(test cleanup
(uiop:delete-directory-tree *extraction-directory* :validate t))

0 comments on commit fb563ad

Please sign in to comment.