-
-
Save yogthos/81d560da28da7dd5b86dcda3003b35e7 to your computer and use it in GitHub Desktop.
(ns gjs-example.core) | |
(defn main [] | |
(set! (-> js/imports .-gi .-versions .-Gtk) "3.0") | |
(let [Gtk (doto (-> js/imports .-gi .-Gtk) (.init nil)) | |
window (Gtk.Window. | |
(clj->js | |
{:type (-> Gtk .-WindowType .-TOPLEVEL) | |
:title "A default title" | |
:default_width 300 | |
:default_height 250 | |
:window_position (-> Gtk .-WindowPosition .-CENTER)})) | |
button (Gtk.Button. | |
(clj->js | |
{:label "close" | |
:visible true | |
:valign (-> Gtk .-Align .-CENTER) | |
:halign (-> Gtk .-Align .-CENTER)}))] | |
(set! (.-title window) "Hello World") | |
(.connect window "delete-event" #(boolean (js/log "delete event"))) | |
(.connect window "destroy" #(.main_quit Gtk)) | |
(.connect button "clicked" #(.destroy window)) | |
(.add window button) | |
(.show window) | |
(.main Gtk))) | |
(main) |
(defproject gjs-test "0.1.0" | |
:dependencies [[org.clojure/clojure "1.10.1"] | |
[org.clojure/clojurescript "1.10.520"]] | |
:plugins [[lein-cljsbuild "1.1.7"]] | |
:cljsbuild {:builds [{:source-paths ["src"] | |
:compiler {:output-to "target/app.js" | |
:optimizations :simple | |
:target :nodejs | |
:pretty-print true}}]}) |
🔥 👍
I have been looking for a way to use Clojurescript to write gnome applications for a long time now. Was it always possible? Or maybe something changed in the new version of Clojurescript compiler?
Thanks for sharing!
I'm not sure how long this was possible actually. I randomly ran across an app using GJS, and got curious to see if I could drive the API from Clojurescript. Was pleasantly surprised how quickly I got it working.
Looks like js/console.log
(as used in line 20) does not work with gjs, but js/log
does; as gjs has it's own logging functions:
https://gitlab.gnome.org/GNOME/gjs/blob/master/doc/Logging.md
Ah thanks for the heads up
That sounds great. I'll give it a try at some point.
I have implemented a new target for shadow-cljs to compile Clojurescript for Gjs environment, with some additional import syntax sugar. If anyone is interested, please take a look at https://github.com/titonbarua/shadow-cljs-gjs-target . Contributions and feed-backs are welcome.
Nice!
the script can be run with
gjs-console target/app.js