Skip to content

Commit 192cc70

Browse files
committed
various fixes
- remove font-scanner and simplify gh actions - build frame css and remove hardcoded values - enhance input font styles - add versions and env to preload - wip text->path for web - always use web apis to query local fonts
1 parent 325744f commit 192cc70

File tree

27 files changed

+170
-174
lines changed

27 files changed

+170
-174
lines changed

.clj-kondo/funcool/promesa/config.edn

Lines changed: 0 additions & 9 deletions
This file was deleted.

.github/workflows/studio.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ jobs:
4040
with:
4141
cli: 1.12.0.1530
4242

43-
# Required for font-scanner.
44-
- name: Install python setuptools
45-
if: matrix.os == 'macos-latest'
46-
run: brew install python-setuptools
47-
48-
- name: Install fontconfig
49-
if: matrix.os == 'ubuntu-latest'
50-
run: sudo apt -y install libfontconfig1-dev
51-
5243
- name: Electron Builder Action
5344
uses: samuelmeuli/action-electron-builder@v1.6.0
5445
with:

package-lock.json

Lines changed: 5 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
"scripts": {
1010
"upgrade": "npx npm-check-updates -u -x 'codemirror'",
1111
"postinstall": "electron-builder install-app-deps",
12-
"tailwindcss:build": "npx @tailwindcss/cli -i ./src/renderer/main.css -o ./resources/public/css/main.css --minify",
13-
"tailwindcss:watch": "npx @tailwindcss/cli -i ./src/renderer/main.css -o ./resources/public/css/main.css --watch=always",
12+
"tailwindcss-main:build": "npx @tailwindcss/cli -i ./src/renderer/main.css -o ./resources/public/css/main.css --minify",
13+
"tailwindcss-main:watch": "npx @tailwindcss/cli -i ./src/renderer/main.css -o ./resources/public/css/main.css --watch=always",
14+
"tailwindcss-frame:build": "npx @tailwindcss/cli -i ./src/renderer/frame/styles.css -o ./resources/public/css/frame.css --minify",
15+
"tailwindcss-frame:watch": "npx @tailwindcss/cli -i ./src/renderer/frame/styles.css -o ./resources/public/css/frame.css --watch=always",
1416
"shadow:build": "npx shadow-cljs release main preload renderer bootstrap",
1517
"shadow:watch": "npx shadow-cljs watch main preload renderer bootstrap browser-test karma-test portfolio",
16-
"dev": "npx npm-run-all --parallel tailwindcss:watch shadow:watch",
17-
"build": "npx npm-run-all --parallel tailwindcss:build shadow:build",
18+
"dev": "npx npm-run-all --parallel tailwindcss-main:watch tailwindcss-frame:watch shadow:watch",
19+
"build": "npx npm-run-all --parallel tailwindcss-main:build tailwindcss-frame:build shadow:build",
1820
"portfolio": "npx shadow-cljs watch portfolio & npm run tailwindcss:watch",
1921
"electron": "npx electron .",
2022
"dist": "npx electron-builder",
@@ -100,6 +102,7 @@
100102
"karma-junit-reporter": "2.0.1",
101103
"mdn-data": "2.21.0",
102104
"npm-run-all": "4.1.5",
105+
"opentype.js": "1.3.4",
103106
"paper": "0.12.18",
104107
"paperjs-offset": "1.0.8",
105108
"path": "0.12.7",
@@ -126,9 +129,7 @@
126129
"dependencies": {
127130
"electron-log": "5.4.0",
128131
"electron-reloader": "1.2.3",
129-
"electron-window-state": "5.0.3",
130-
"font-scanner": "0.2.1",
131-
"opentype.js": "1.3.4"
132+
"electron-window-state": "5.0.3"
132133
},
133134
"overrides": {
134135
"react": "19.1.0",

src/electron/main.cljs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
["electron-log/main" :as log]
66
["electron-reloader"]
77
["electron-window-state" :as window-state-keeper]
8-
["font-scanner" :as fontManager]
98
["os" :as os]
109
["path" :as path]
1110
["url" :as url]
@@ -68,8 +67,7 @@
6867
["save-document" file/save!]
6968
["save-document-as" file/save-as!]
7069
["export" file/export!]
71-
["print" file/print!]
72-
["load-system-fonts" #(.getAvailableFonts fontManager)]]]
70+
["print" file/print!]]]
7371
(.handle ipcMain e #(f %2))))
7472

7573
(defn register-window-events!

src/electron/preload.cljs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
11
(ns electron.preload
22
"https://www.electronjs.org/docs/latest/tutorial/tutorial-preload"
33
(:require
4-
["electron" :refer [contextBridge ipcRenderer]]
5-
["font-scanner" :as fontManager]
6-
["opentype.js" :as opentype]
7-
["os" :as os]))
8-
9-
(defn text->path
10-
"https://github.com/opentypejs/opentype.js#loading-a-font-synchronously-nodejs"
11-
[text {:keys [font-url x y font-size]}]
12-
(let [font (.loadSync opentype font-url)
13-
path (.getPath font text x y font-size)]
14-
(.toPathData path)))
4+
["electron" :refer [contextBridge ipcRenderer]]))
155

166
(defonce api
17-
{;; Strip event as it includes `sender`
7+
{;; Strip event as it includes `sender`.
188
;; https://www.electronjs.org/docs/latest/api/ipc-renderer#ipcrendereronchannel-listener
19-
:on (fn [channel f] (.on ipcRenderer channel (fn [_e args] (f args))))
9+
:on (fn [channel f] (.on ipcRenderer channel (fn [_event args] (f args))))
2010
:send (fn [channel args] (.send ipcRenderer channel args))
2111
:invoke (fn [channel args] (.invoke ipcRenderer channel args))
22-
:platform (.platform os)
23-
:findFont (fn [descriptor] (.findFontSync fontManager descriptor))
24-
:textToPath (fn [s options] (text->path s (js->clj options :keywordize-keys true)))})
12+
:platform (.-platform js/process)
13+
:versions (.-versions js/process)
14+
:env (.-env js/process)})
2515

26-
(defn ^:export init! []
27-
;; Expose protected methods that allow the renderer process to use the
28-
;; ipcRenderer without exposing the entire object
29-
;; https://www.electronjs.org/docs/api/context-bridge
16+
(defn ^:export init!
17+
"Expose protected methods that allow the renderer process to use the ipcRenderer.
18+
https://www.electronjs.org/docs/api/context-bridge"
19+
[]
3020
(.exposeInMainWorld contextBridge "api" (clj->js api)))

src/renderer/app/db.cljs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
[:document-tabs {:default [] :persist true} [:vector uuid?]]
5656
[:recent {:max 10 :default [] :persist true} [:vector string?]]
5757
[:drag-threshold {:default 1} number?]
58-
[:system-fonts {:optional true} vector?]
58+
[:system-fonts {:optional true} map?]
5959
[:notifications {:default []} [:* Notification]]
6060
[:debug-info {:default false} boolean?]
6161
[:help-bar {:default true} boolean?]
@@ -64,6 +64,8 @@
6464
[:lang {:optional true :persist true} Lang]
6565
[:system-lang {:optional true} string?]
6666
[:platform {:optional true} Platform]
67+
[:versions {:optional true} [:maybe map?]]
68+
[:env {:optional true} [:maybe map?]]
6769
[:user-agent {:optional true} string?]
6870
[:repl-mode {:default :cljs} keyword?]
6971
[:worker {:default {:tasks {}}} [:map [:tasks map?]]]

src/renderer/app/effects.cljs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@
1616
js/window.api.platform
1717
"web"))))
1818

19+
(rf/reg-cofx
20+
::versions
21+
(fn [coeffects _]
22+
(cond-> coeffects
23+
js/window.api
24+
(assoc :versions js/window.api.versions))))
25+
26+
(rf/reg-cofx
27+
::env
28+
(fn [coeffects _]
29+
(cond-> coeffects
30+
js/window.api
31+
(assoc :env js/window.api.env))))
32+
1933
(rf/reg-cofx
2034
::user-agent
2135
(fn [coeffects _]

src/renderer/app/events.cljs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@
2727
::initialize-db
2828
[(rf/inject-cofx ::app.effects/user-agent)
2929
(rf/inject-cofx ::app.effects/platform)
30+
(rf/inject-cofx ::app.effects/versions)
31+
(rf/inject-cofx ::app.effects/env)
3032
(rf/inject-cofx ::app.effects/system-language)]
31-
(fn [{:keys [user-agent platform system-language]} _]
33+
(fn [{:keys [user-agent platform versions env system-language]} _]
3234
{:db (assoc app.db/default
3335
:platform platform
36+
:versions (js->clj versions)
37+
:env (js->clj env)
3438
:user-agent user-agent
3539
:system-lang system-language)}))
3640

@@ -111,26 +115,19 @@
111115
(fn [db [_ k]]
112116
(update-in db [:panels k :visible] not)))
113117

114-
(defn ->font-map
115-
[^js/FontData font-data]
116-
(into {} [[:postscriptName (.-postscriptName font-data)]
117-
[:fullName (.-fullName font-data)]
118-
[:family (.-family font-data)]
119-
[:style (.-style font-data)]]))
120-
121118
(rf/reg-event-fx
122119
::load-system-fonts
123-
(fn [{:keys [db]} _]
124-
(if (= (:platform db) "web")
125-
{::app.effects/query-local-fonts
126-
{:on-success [::set-system-fonts]
127-
:on-error [::notification.events/show-exception]
128-
:formatter #(mapv ->font-map %)}}
129-
{::effects/ipc-invoke
130-
{:channel "load-system-fonts"
131-
:on-success [::set-system-fonts]
132-
:on-error [::notification.events/show-exception]
133-
:formatter #(js->clj % :keywordize-keys true)}})))
120+
(fn [_ _]
121+
{::app.effects/query-local-fonts
122+
{:on-success [::set-system-fonts]
123+
:on-error [::notification.events/show-exception]
124+
:formatter #(reduce (fn [fonts ^js/FontData font-data]
125+
(let [family (.-family font-data)
126+
style (.-style font-data)]
127+
(assoc-in fonts [family style]
128+
{:postscript-name (.-postscriptName font-data)
129+
:full-name (.-fullName font-data)})))
130+
{} %)}}))
134131

135132
(def schema-validator
136133
(rf/->interceptor

src/renderer/app/subs.cljs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,3 @@
9292
::panel-visible?
9393
(fn [db [_ k]]
9494
(-> db :panels k :visible)))
95-
96-
(rf/reg-sub
97-
::font-options
98-
:<- [::system-fonts]
99-
(fn [system-fonts _]
100-
(when system-fonts
101-
(->> system-fonts
102-
(map :family)
103-
(distinct)))))

src/renderer/app/views.cljs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@
6666

6767
(defn debug-info
6868
[]
69-
(into [:div.absolute.top-1.left-2.pointer-events-none
70-
{:style {:color "#555"}}]
69+
(into [:div.absolute.top-1.left-2.pointer-events-none]
7170
(for [[s v] (debug-rows)]
7271
[:div.flex [:strong.mr-1 s] [:div v]])))
7372

@@ -99,6 +98,7 @@
9998
[:div.bg-primary
10099
[ruler.views/ruler :vertical]])
101100
[:div.relative.grow.flex
101+
{:data-theme "light"}
102102
[frame.views/root]
103103
(when read-only?
104104
[:div.absolute.inset-0.border-4.border-accent
@@ -111,7 +111,6 @@
111111
{:on-click #(rf/dispatch [::app.events/set-backdrop false])}])
112112
(when (and help-bar (seq help-message))
113113
[:div.flex.absolute.justify-center.w-full.p-4.pointer-events-none
114-
{:data-theme "light"}
115114
[:div.bg-primary.rounded-full.overflow-hidden.shadow-lg
116115
[:div.overlay.text-color.text-xs.gap-1.flex.flex-wrap.truncate.py-2.px-4.justify-center
117116
{:aria-live "polite"}

src/renderer/attribute/impl/font_family.cljs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@
3131
(if-not suggestions
3232
[:div.w-full [views/loading-indicator]]
3333
"No local fonts found.")]
34-
(for [item suggestions]
35-
^{:key item}
34+
(for [[family _item] suggestions]
35+
^{:key family}
3636
[:> Command/CommandItem
37-
{:on-select #(rf/dispatch [::element.events/set-attr :font-family item])}
37+
{:on-select #(rf/dispatch [::element.events/set-attr :font-family family])}
3838
[:div.flex.justify-between.items-center.w-full.gap-2
39-
[:div item]
39+
[:div family]
4040
[:div.leading-none.text-muted
41-
{:style {:font-family item}}
42-
"Lorem ipsum"]]])]]]])
41+
{:style {:font-family family}}
42+
"AaBbCc 0123"]]])]]]])
4343

4444
(defmethod attribute.hierarchy/form-element [:default :font-family]
4545
[_ k v attrs]
46-
(let [suggestions @(rf/subscribe [::app.subs/font-options])]
46+
(let [suggestions @(rf/subscribe [::app.subs/system-fonts])]
4747
[:div.flex.gap-px.w-full
4848
[attribute.views/form-input k v attrs]
4949
[:> Popover/Root

src/renderer/attribute/impl/length.cljs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
[_ k v {:keys [disabled placeholder]}]
3333
[:div.flex.w-full.gap-px
3434
[attribute.views/form-input k v
35-
{:disabled disabled
35+
{:class "font-mono"
36+
:disabled disabled
3637
:placeholder (if v placeholder "multiple")}]
3738
[:div.flex.gap-px
3839
[:button.form-control-button

src/renderer/attribute/views.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
[:div.flex.w-full.gap-px
111111
[form-input k v {:disabled disabled
112112
:placeholder placeholder
113-
:class "w-20"}]
113+
:class "font-mono w-20"}]
114114
[:div.px-1.w-full.bg-primary
115115
[views/slider
116116
(merge

src/renderer/core.cljs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
[renderer.ruler.subs]
3333
[renderer.snap.events]
3434
[renderer.snap.subs]
35-
[renderer.theme.db :as theme.db]
3635
[renderer.theme.effects]
3736
[renderer.theme.events :as theme.events]
3837
[renderer.theme.subs]
@@ -85,7 +84,7 @@
8584
(print "Type (help) to see a list of commands."))
8685

8786
(defn ^:export init! []
88-
(js/console.log (str "%c" easter-egg) (str "color: " theme.db/accent))
87+
(js/console.log (str "%c" easter-egg) (str "color: " "pink"))
8988

9089
;; https://code.thheller.com/blog/shadow-cljs/2017/10/14/bootstrap-support.html
9190
(bootstrap/init replumb.repl/st {:path "js/bootstrap"

src/renderer/element/impl/container/svg.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
{:on-pointer-up pointer-handler
3636
:on-pointer-down pointer-handler
3737
:on-pointer-move pointer-handler
38-
:fill "#888"
38+
:fill "var(--font-color-muted)"
3939
:font-family "monospace"
4040
:font-size (/ 12 zoom)}) (or (:label el) (name (:tag el)))]
4141

0 commit comments

Comments
 (0)