mirror of
https://github.com/penpot/penpot.git
synced 2025-06-12 20:11:40 +02:00
✨ Improve globals handling on fronted application.
This commit is contained in:
parent
b0749b5595
commit
341bb8495a
5 changed files with 49 additions and 48 deletions
|
@ -13,28 +13,27 @@
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[cuerdas.core :as str]))
|
[cuerdas.core :as str]))
|
||||||
|
|
||||||
|
(def version-re #"^(([A-Za-z]+)\-?)?(\d+\.\d+\.\d+)(\-?((alpha|prealpha|beta|rc)(\d+)?))?(\-?(\d+))?(\-?(\w+))$")
|
||||||
|
|
||||||
(defn parse
|
(defn parse
|
||||||
[version]
|
[data]
|
||||||
(cond
|
(cond
|
||||||
(= version "%version%")
|
(= data "%version%")
|
||||||
{:full "develop"
|
{:full "develop"
|
||||||
:base "develop"
|
:base "develop"
|
||||||
:build 0
|
:branch "develop"
|
||||||
:commit nil}
|
:modifier nil
|
||||||
|
:commit nil
|
||||||
|
:commit-hash nil}
|
||||||
|
|
||||||
(string? version)
|
(string? data)
|
||||||
(if (re-seq #"^[A-Za-z]+\-" version)
|
(let [result (re-find version-re data)]
|
||||||
(let [[branch base build commit] (str/split version #"-" 4)]
|
{:full data
|
||||||
{:full version
|
:base (get result 3)
|
||||||
:base base
|
:branch (get result 2)
|
||||||
:build (d/parse-integer build)
|
:modifier (get result 5)
|
||||||
:branch branch
|
:commit (get result 9)
|
||||||
:commit commit})
|
:commit-hash (get result 11)})
|
||||||
(let [[base build commit] (str/split version #"-" 3)]
|
|
||||||
{:full version
|
|
||||||
:base base
|
|
||||||
:build (d/parse-integer build)
|
|
||||||
:branch nil
|
|
||||||
:commit commit}))
|
|
||||||
|
|
||||||
:else nil))
|
:else nil))
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,13 @@
|
||||||
<link rel="icon" href="/images/favicon.png" />
|
<link rel="icon" href="/images/favicon.png" />
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
window.appTranslations = JSON.parse({{& translations}});
|
window.penpotTranslations = JSON.parse({{& translations}});
|
||||||
window.appThemes = {{& themes}};
|
window.penpotThemes = {{& themes}};
|
||||||
window.appVersion = "%version%";
|
window.penpotVersion = "%version%";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{{# manifest}}
|
{{# manifest}}
|
||||||
<script>window.appWorkerURI="{{& worker}}"</script>
|
<script>window.penpotWorkerURI="{{& worker}}"</script>
|
||||||
<script src="{{& config}}"></script>
|
<script src="{{& config}}"></script>
|
||||||
<script src="{{& polyfills}}"></script>
|
<script src="{{& polyfills}}"></script>
|
||||||
{{/manifest}}
|
{{/manifest}}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.common.version :as v]
|
[app.common.version :as v]
|
||||||
[app.util.globals :as globals]
|
[app.util.globals :refer [global location]]
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[app.util.avatars :as avatars]
|
[app.util.avatars :as avatars]
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
|
|
||||||
(defn- parse-platform
|
(defn- parse-platform
|
||||||
[]
|
[]
|
||||||
(let [user-agent (-> (dom/get-user-agent) str/lower)
|
(let [user-agent (str/lower (dom/get-user-agent))
|
||||||
check-windows? (fn [] (str/includes? user-agent "windows"))
|
check-windows? (fn [] (str/includes? user-agent "windows"))
|
||||||
check-linux? (fn [] (str/includes? user-agent "linux"))
|
check-linux? (fn [] (str/includes? user-agent "linux"))
|
||||||
check-macos? (fn [] (str/includes? user-agent "mac os"))]
|
check-macos? (fn [] (str/includes? user-agent "mac os"))]
|
||||||
|
@ -58,29 +58,30 @@
|
||||||
|
|
||||||
(defn- parse-version
|
(defn- parse-version
|
||||||
[global]
|
[global]
|
||||||
(-> (obj/get global "appVersion")
|
(-> (obj/get global "penpotVersion")
|
||||||
(v/parse)))
|
(v/parse)))
|
||||||
|
|
||||||
;; --- Globar Config Vars
|
;; --- Globar Config Vars
|
||||||
|
|
||||||
(def default-theme "default")
|
(def default-theme "default")
|
||||||
|
|
||||||
(this-as global
|
|
||||||
(def default-language "en")
|
(def default-language "en")
|
||||||
(def demo-warning (obj/get global "appDemoWarning" false))
|
|
||||||
(def google-client-id (obj/get global "appGoogleClientID" nil))
|
(def demo-warning (obj/get global "penpotDemoWarning" false))
|
||||||
(def gitlab-client-id (obj/get global "appGitlabClientID" nil))
|
(def allow-demo-users (obj/get global "penpotAllowDemoUsers" true))
|
||||||
(def github-client-id (obj/get global "appGithubClientID" nil))
|
(def google-client-id (obj/get global "penpotGoogleClientID" nil))
|
||||||
(def login-with-ldap (obj/get global "appLoginWithLDAP" false))
|
(def gitlab-client-id (obj/get global "penpotGitlabClientID" nil))
|
||||||
(def worker-uri (obj/get global "appWorkerURI" "/js/worker.js"))
|
(def github-client-id (obj/get global "penpotGithubClientID" nil))
|
||||||
(def public-uri (or (obj/get global "appPublicURI")
|
(def login-with-ldap (obj/get global "penpotLoginWithLDAP" false))
|
||||||
(.-origin ^js globals/location)))
|
(def worker-uri (obj/get global "penpotWorkerURI" "/js/worker.js"))
|
||||||
(def media-uri (str public-uri "/assets"))
|
(def translations (obj/get global "penpotTranslations"))
|
||||||
|
(def themes (obj/get global "penpotThemes"))
|
||||||
|
|
||||||
|
(def public-uri (or (obj/get global "penpotPublicURI") (.-origin ^js location)))
|
||||||
|
|
||||||
(def version (delay (parse-version global)))
|
(def version (delay (parse-version global)))
|
||||||
(def target (delay (parse-target global)))
|
(def target (delay (parse-target global)))
|
||||||
(def browser (delay (parse-browser)))
|
(def browser (delay (parse-browser)))
|
||||||
(def platform (delay (parse-platform))))
|
(def platform (delay (parse-platform)))
|
||||||
|
|
||||||
|
|
||||||
(when (= :browser @target)
|
(when (= :browser @target)
|
||||||
(js/console.log
|
(js/console.log
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
(ns app.main
|
(ns app.main
|
||||||
(:require
|
(:require
|
||||||
|
[app.config :as cfg]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.main.repo :as rp]
|
[app.main.repo :as rp]
|
||||||
|
@ -86,12 +87,10 @@
|
||||||
|
|
||||||
(defn ^:export init
|
(defn ^:export init
|
||||||
[]
|
[]
|
||||||
(let [translations (obj/get js/window "appTranslations")
|
(i18n/init! cfg/translations)
|
||||||
themes (obj/get js/window "appThemes")]
|
(theme/init! cfg/themes)
|
||||||
(i18n/init! translations)
|
|
||||||
(theme/init! themes)
|
|
||||||
(st/init)
|
(st/init)
|
||||||
(init-ui)))
|
(init-ui))
|
||||||
|
|
||||||
(defn reinit
|
(defn reinit
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
goog.provide("app.util.globals");
|
goog.provide("app.util.globals");
|
||||||
|
|
||||||
goog.scope(function() {
|
goog.scope(function() {
|
||||||
|
app.util.globals.global = goog.global;
|
||||||
|
|
||||||
app.util.globals.window = (function() {
|
app.util.globals.window = (function() {
|
||||||
if (typeof goog.global.window !== "undefined") {
|
if (typeof goog.global.window !== "undefined") {
|
||||||
return goog.global.window;
|
return goog.global.window;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue