2016-06-14 17:39:44 +03:00
|
|
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
;;
|
2020-03-11 09:20:12 +01:00
|
|
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
|
|
|
;; defined by the Mozilla Public License, v. 2.0.
|
|
|
|
;;
|
2020-05-05 12:03:34 +02:00
|
|
|
;; Copyright (c) 2020 UXBOX Labs SL
|
2016-06-14 17:39:44 +03:00
|
|
|
|
2020-08-18 19:26:37 +02:00
|
|
|
(ns app.config
|
2020-10-05 18:20:39 +02:00
|
|
|
(:require
|
2020-11-30 17:59:39 +01:00
|
|
|
[clojure.spec.alpha :as s]
|
2020-12-04 16:01:33 +01:00
|
|
|
[app.common.data :as d]
|
2020-11-30 17:59:39 +01:00
|
|
|
[app.common.spec :as us]
|
2020-12-04 16:01:33 +01:00
|
|
|
[app.common.version :as v]
|
2020-10-05 18:20:39 +02:00
|
|
|
[app.util.object :as obj]
|
2020-11-30 17:59:39 +01:00
|
|
|
[app.util.dom :as dom]
|
2020-10-05 18:20:39 +02:00
|
|
|
[cuerdas.core :as str]))
|
2016-07-29 13:45:00 +03:00
|
|
|
|
2020-12-04 16:01:33 +01:00
|
|
|
;; --- Auxiliar Functions
|
|
|
|
|
2020-11-30 17:59:39 +01:00
|
|
|
(s/def ::platform #{:windows :linux :macos :other})
|
|
|
|
(s/def ::browser #{:chrome :mozilla :safari :edge :other})
|
|
|
|
|
2020-12-04 16:01:33 +01:00
|
|
|
(defn- parse-browser
|
2020-11-30 17:59:39 +01:00
|
|
|
[]
|
|
|
|
(let [user-agent (-> (dom/get-user-agent) str/lower)
|
|
|
|
check-chrome? (fn [] (str/includes? user-agent "chrom"))
|
|
|
|
check-firefox? (fn [] (str/includes? user-agent "firefox"))
|
|
|
|
check-edge? (fn [] (str/includes? user-agent "edg"))
|
|
|
|
check-safari? (fn [] (str/includes? user-agent "safari"))]
|
|
|
|
(cond
|
|
|
|
(check-edge?) :edge
|
|
|
|
(check-chrome?) :chrome
|
|
|
|
(check-firefox?) :firefox
|
|
|
|
(check-safari?) :safari
|
|
|
|
:else :other)))
|
|
|
|
|
2020-12-04 16:01:33 +01:00
|
|
|
(defn- parse-platform
|
2020-11-30 17:59:39 +01:00
|
|
|
[]
|
|
|
|
(let [user-agent (-> (dom/get-user-agent) str/lower)
|
|
|
|
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"))]
|
|
|
|
(cond
|
|
|
|
(check-windows?) :windows
|
|
|
|
(check-linux?) :linux
|
|
|
|
(check-macos?) :macos
|
|
|
|
:else :other)))
|
|
|
|
|
2020-12-11 11:37:01 +01:00
|
|
|
(defn- parse-target
|
|
|
|
[global]
|
|
|
|
(if (some? (obj/get global "document"))
|
|
|
|
:browser
|
|
|
|
:webworker))
|
|
|
|
|
|
|
|
(defn- parse-version
|
|
|
|
[global]
|
|
|
|
(-> (obj/get global "appVersion")
|
|
|
|
(v/parse)))
|
|
|
|
|
2020-12-04 16:01:33 +01:00
|
|
|
;; --- Globar Config Vars
|
|
|
|
|
|
|
|
(def default-theme "default")
|
|
|
|
|
2020-05-05 12:03:34 +02:00
|
|
|
(this-as global
|
2020-08-18 17:16:23 +02:00
|
|
|
(def default-language "en")
|
|
|
|
(def demo-warning (obj/get global "appDemoWarning" false))
|
|
|
|
(def google-client-id (obj/get global "appGoogleClientID" nil))
|
2020-08-24 13:24:36 +03:00
|
|
|
(def gitlab-client-id (obj/get global "appGitlabClientID" nil))
|
2020-08-18 17:16:23 +02:00
|
|
|
(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 js/location)))
|
2020-12-11 11:37:01 +01:00
|
|
|
(def media-uri (str public-uri "/media"))
|
|
|
|
(def version (delay (parse-version global)))
|
|
|
|
(def target (delay (parse-target global)))
|
|
|
|
(def browser (delay (parse-browser)))
|
|
|
|
(def platform (delay (parse-platform))))
|
2020-12-04 16:01:33 +01:00
|
|
|
|
|
|
|
|
2020-12-11 11:37:01 +01:00
|
|
|
(when (= :browser @target)
|
|
|
|
(js/console.log
|
|
|
|
(str/format "Welcome to penpot! Version: '%s'." (:full @version))))
|
2020-12-04 16:01:33 +01:00
|
|
|
|
|
|
|
;; --- Helper Functions
|
|
|
|
|
2020-11-30 17:59:39 +01:00
|
|
|
|
|
|
|
(defn ^boolean check-browser? [candidate]
|
|
|
|
(us/verify ::browser candidate)
|
2020-12-11 11:37:01 +01:00
|
|
|
(= candidate @browser))
|
2020-11-30 17:59:39 +01:00
|
|
|
|
|
|
|
(defn ^boolean check-platform? [candidate]
|
|
|
|
(us/verify ::platform candidate)
|
2020-12-11 11:37:01 +01:00
|
|
|
(= candidate @platform))
|
2020-08-17 13:39:36 +02:00
|
|
|
|
|
|
|
(defn resolve-media-path
|
|
|
|
[path]
|
2020-10-05 18:20:39 +02:00
|
|
|
(when path
|
|
|
|
(if (str/starts-with? path "data:")
|
|
|
|
path
|
|
|
|
(str media-uri "/" path))))
|