Last active
February 18, 2025 04:46
-
-
Save yogthos/81d560da28da7dd5b86dcda3003b35e7 to your computer and use it in GitHub Desktop.
Gjs ClojureScript example
This file contains hidden or 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
(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) |
This file contains hidden or 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
(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}}]}) |
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!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like
js/console.log
(as used in line 20) does not work with gjs, butjs/log
does; as gjs has it's own logging functions:https://gitlab.gnome.org/GNOME/gjs/blob/master/doc/Logging.md