mirror of
https://github.com/penpot/penpot.git
synced 2025-05-23 02:26:10 +02:00
🐛 Fix problem when loading fonts
This commit is contained in:
parent
e170011e3c
commit
b2c3dc1504
1 changed files with 32 additions and 36 deletions
|
@ -194,10 +194,7 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn ensure-loaded!
|
||||
([id]
|
||||
(p/create (fn [resolve]
|
||||
(ensure-loaded! id resolve))))
|
||||
([id on-loaded]
|
||||
[id]
|
||||
(log/debug :action "try-ensure-loaded!" :font-id id)
|
||||
(if-not (exists? js/window)
|
||||
;; If we are in the worker environment, we just mark it as loaded
|
||||
|
@ -206,25 +203,24 @@
|
|||
(swap! loaded conj id)
|
||||
(p/resolved id))
|
||||
|
||||
(when-let [font (get @fontsdb id)]
|
||||
(let [font (get @fontsdb id)]
|
||||
(cond
|
||||
(nil? font)
|
||||
(p/resolved id)
|
||||
|
||||
;; Font already loaded, we just continue
|
||||
(contains? @loaded id)
|
||||
(p/do
|
||||
(on-loaded id)
|
||||
id)
|
||||
(p/resolved id)
|
||||
|
||||
;; Font is currently downloading. We attach the caller to the promise
|
||||
(contains? @loading id)
|
||||
(-> (get @loading id)
|
||||
(p/then #(do (on-loaded id) id)))
|
||||
(p/resolved (get @loading id))
|
||||
|
||||
;; First caller, we create the promise and then wait
|
||||
:else
|
||||
(let [on-load (fn [resolve]
|
||||
(swap! loaded conj id)
|
||||
(swap! loading dissoc id)
|
||||
(on-loaded id)
|
||||
(resolve id))
|
||||
|
||||
load-p (p/create
|
||||
|
@ -234,7 +230,7 @@
|
|||
(load-font))))]
|
||||
|
||||
(swap! loading assoc id load-p)
|
||||
load-p))))))
|
||||
load-p)))))
|
||||
|
||||
(defn ready
|
||||
[cb]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue