From 58d30a60bcf4c24baea53f847f342b4c1e225c68 Mon Sep 17 00:00:00 2001 From: David Botton Date: Wed, 30 Dec 2020 20:05:48 -0500 Subject: [PATCH] singleton demo --- clog-system.lisp | 11 +++++++++-- clog.lisp | 5 +++-- demos/01-hello.lisp | 2 +- demos/02-singleton.lisp | 22 ++++++++++++++++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 demos/02-singleton.lisp diff --git a/clog-system.lisp b/clog-system.lisp index 968c0ee..5522e21 100644 --- a/clog-system.lisp +++ b/clog-system.lisp @@ -25,7 +25,7 @@ (let ((body (make-clog-body connection-id))) (funcall *on-new-window* body))) -(defun initialize (on-new-window +(defun initialize (on-new-window-handler &key (host "0.0.0.0") (port 8080) @@ -34,7 +34,7 @@ "Inititalze CLOG on a socket using HOST and PORT to serve BOOT-FILE as the default route to establish web-socket connections and static files located at STATIC-ROOT." - (setf *on-new-window* on-new-window) + (setf *on-new-window* on-new-window-handler) (cc:initialize #'on-connect :host host @@ -42,6 +42,13 @@ located at STATIC-ROOT." :boot-file boot-file :static-root static-root)) +;;;;;;;;;;;;;;;;;;;;;;; +;; set-on-new-window ;; +;;;;;;;;;;;;;;;;;;;;;;; + +(defun set-on-new-window (on-new-window-handler) + (setf *on-new-window* on-new-window-handler)) + ;;;;;;;;;;;;;; ;; shutdown ;; ;;;;;;;;;;;;;; diff --git a/clog.lisp b/clog.lisp index ba05363..a1908ac 100644 --- a/clog.lisp +++ b/clog.lisp @@ -38,8 +38,9 @@ application." (defsection @clog-system (:title "CLOG System") "CLOG Startup and Shutdown" - (initialize function) - (shutdown function)) + (initialize function) + (set-on-new-window function) + (shutdown function)) (defsection @clog-utilities (:title "CLOG Utilities") "CLOG utilities" diff --git a/demos/01-hello.lisp b/demos/01-hello.lisp index 3b09e14..c240937 100644 --- a/demos/01-hello.lisp +++ b/demos/01-hello.lisp @@ -1,6 +1,6 @@ (defpackage #:clog-user (:use #:cl #:clog) - (:export hello)) + (:export start-demo)) (in-package :clog-user) diff --git a/demos/02-singleton.lisp b/demos/02-singleton.lisp new file mode 100644 index 0000000..232177e --- /dev/null +++ b/demos/02-singleton.lisp @@ -0,0 +1,22 @@ +(defpackage #:clog-user + (:use #:cl #:clog) + (:export start-demo)) + +(in-package :clog-user) + +(defun start-demo () + "How to allow only one CLOG app to be executed. Normally many browsers can +can be started with the same app." + + (clog:initialize + (lambda (win) + (let ((click-target (clog:create-child win "

Hello World!

"))) + (clog:set-on-click click-target + (lambda () + (clog:create-child win "

You Clicked me!

"))) + (clog:set-on-new-window + (lambda (win) + (clog:put-br (clog:html-document win) + "Only single connection premitted.")))))) + + (clog:open-browser))