0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 06:58:58 -05:00

Improve globals handling on fronted application.

This commit is contained in:
Andrey Antukh 2021-01-29 13:00:03 +01:00 committed by Alonso Torres
parent b0749b5595
commit 341bb8495a
5 changed files with 49 additions and 48 deletions

View file

@ -13,28 +13,27 @@
[app.common.data :as d]
[cuerdas.core :as str]))
(def version-re #"^(([A-Za-z]+)\-?)?(\d+\.\d+\.\d+)(\-?((alpha|prealpha|beta|rc)(\d+)?))?(\-?(\d+))?(\-?(\w+))$")
(defn parse
[version]
[data]
(cond
(= version "%version%")
(= data "%version%")
{:full "develop"
:base "develop"
:build 0
:commit nil}
:branch "develop"
:modifier nil
:commit nil
:commit-hash nil}
(string? version)
(if (re-seq #"^[A-Za-z]+\-" version)
(let [[branch base build commit] (str/split version #"-" 4)]
{:full version
:base base
:build (d/parse-integer build)
:branch branch
:commit commit})
(let [[base build commit] (str/split version #"-" 3)]
{:full version
:base base
:build (d/parse-integer build)
:branch nil
:commit commit}))
(string? data)
(let [result (re-find version-re data)]
{:full data
:base (get result 3)
:branch (get result 2)
:modifier (get result 5)
:commit (get result 9)
:commit-hash (get result 11)})
:else nil))

View file

@ -10,13 +10,13 @@
<link rel="icon" href="/images/favicon.png" />
<script>
window.appTranslations = JSON.parse({{& translations}});
window.appThemes = {{& themes}};
window.appVersion = "%version%";
window.penpotTranslations = JSON.parse({{& translations}});
window.penpotThemes = {{& themes}};
window.penpotVersion = "%version%";
</script>
{{# manifest}}
<script>window.appWorkerURI="{{& worker}}"</script>
<script>window.penpotWorkerURI="{{& worker}}"</script>
<script src="{{& config}}"></script>
<script src="{{& polyfills}}"></script>
{{/manifest}}

View file

@ -13,7 +13,7 @@
[app.common.data :as d]
[app.common.spec :as us]
[app.common.version :as v]
[app.util.globals :as globals]
[app.util.globals :refer [global location]]
[app.util.object :as obj]
[app.util.dom :as dom]
[app.util.avatars :as avatars]
@ -40,10 +40,10 @@
(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-linux? (fn [] (str/includes? user-agent "linux"))
check-macos? (fn [] (str/includes? user-agent "mac os"))]
check-linux? (fn [] (str/includes? user-agent "linux"))
check-macos? (fn [] (str/includes? user-agent "mac os"))]
(cond
(check-windows?) :windows
(check-linux?) :linux
@ -58,29 +58,30 @@
(defn- parse-version
[global]
(-> (obj/get global "appVersion")
(-> (obj/get global "penpotVersion")
(v/parse)))
;; --- Globar Config Vars
(def default-theme "default")
(def default-language "en")
(this-as global
(def default-language "en")
(def demo-warning (obj/get global "appDemoWarning" false))
(def google-client-id (obj/get global "appGoogleClientID" nil))
(def gitlab-client-id (obj/get global "appGitlabClientID" nil))
(def github-client-id (obj/get global "appGithubClientID" nil))
(def login-with-ldap (obj/get global "appLoginWithLDAP" false))
(def worker-uri (obj/get global "appWorkerURI" "/js/worker.js"))
(def public-uri (or (obj/get global "appPublicURI")
(.-origin ^js globals/location)))
(def media-uri (str public-uri "/assets"))
(def version (delay (parse-version global)))
(def target (delay (parse-target global)))
(def browser (delay (parse-browser)))
(def platform (delay (parse-platform))))
(def demo-warning (obj/get global "penpotDemoWarning" false))
(def allow-demo-users (obj/get global "penpotAllowDemoUsers" true))
(def google-client-id (obj/get global "penpotGoogleClientID" nil))
(def gitlab-client-id (obj/get global "penpotGitlabClientID" nil))
(def github-client-id (obj/get global "penpotGithubClientID" nil))
(def login-with-ldap (obj/get global "penpotLoginWithLDAP" false))
(def worker-uri (obj/get global "penpotWorkerURI" "/js/worker.js"))
(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 target (delay (parse-target global)))
(def browser (delay (parse-browser)))
(def platform (delay (parse-platform)))
(when (= :browser @target)
(js/console.log

View file

@ -9,6 +9,7 @@
(ns app.main
(:require
[app.config :as cfg]
[app.common.uuid :as uuid]
[app.common.spec :as us]
[app.main.repo :as rp]
@ -86,12 +87,10 @@
(defn ^:export init
[]
(let [translations (obj/get js/window "appTranslations")
themes (obj/get js/window "appThemes")]
(i18n/init! translations)
(theme/init! themes)
(st/init)
(init-ui)))
(i18n/init! cfg/translations)
(theme/init! cfg/themes)
(st/init)
(init-ui))
(defn reinit
[]

View file

@ -21,6 +21,8 @@
goog.provide("app.util.globals");
goog.scope(function() {
app.util.globals.global = goog.global;
app.util.globals.window = (function() {
if (typeof goog.global.window !== "undefined") {
return goog.global.window;