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