Browse Source

Merge pull request #1239 from logseq/fix/electron-alpha-issues

Fix/electron alpha issues
Tienson Qin 4 years ago
parent
commit
9cba5e4493

+ 3 - 2
.github/workflows/build-stage.yml

@@ -37,11 +37,12 @@ jobs:
         run: yarn cache clean && yarn install --frozen-lockfile
 
       - name: Build Released-Web
-        run: yarn gulp:build && rm -Rf .shadow-cljs && ENV=staging clojure -M:cljs release app  --config-merge '{:asset-path "${{env.asset-path}}"}'
+        run: yarn gulp:build && clojure -M:cljs release app  --config-merge '{:asset-path "${{env.asset-path}}"}'
 
       - uses: jakejarvis/s3-sync-action@master
         with:
-            args: --acl public-read --follow-symlinks --delete
+            #args: --acl public-read --follow-symlinks --delete
+            args: --acl public-read --follow-symlinks
         env:
           AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
           AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}

+ 1 - 1
README.md

@@ -86,7 +86,7 @@ Open <http://localhost:3001>.
 ### 4. Build a release
 
 ``` bash
-yarn release 
+yarn release
 ```
 
 ### 5. Run tests

+ 3 - 7
deps.edn

@@ -1,4 +1,4 @@
-{:paths ["src/main" "resources"]
+{:paths ["src/main"]
  :deps
  {org.clojure/clojure         {:mvn/version "1.10.0"}
   cheshire/cheshire {:mvn/version "5.10.0"}
@@ -37,16 +37,12 @@
  :aliases {:cljs {:extra-paths ["src/dev-cljs/" "src/test/" "src/electron/"]
                   :extra-deps  {org.clojure/clojurescript   {:mvn/version "1.10.764"}
                                 org.clojure/tools.namespace {:mvn/version "0.2.11"}
-                                cider/cider-nrepl           {:mvn/version "0.25.5"}
-                                aero/aero                   {:mvn/version "1.1.6"}
-                                mhuebert/shadow-env         {:mvn/version "0.1.6"}}
+                                cider/cider-nrepl           {:mvn/version "0.25.5"}}
                   :main-opts ["-m" "shadow.cljs.devtools.cli"]}
            :test
            {:extra-paths ["src/test/"]
             :extra-deps  {org.clojure/clojurescript {:mvn/version "1.10.764"}
-                          org.clojure/test.check {:mvn/version "RELEASE"}
-                          aero/aero                   {:mvn/version "1.1.6"}
-                          mhuebert/shadow-env         {:mvn/version "0.1.6"}}
+                          org.clojure/test.check {:mvn/version "RELEASE"}}
             :main-opts   ["-m" "shadow.cljs.devtools.cli"]}
 
            :test-clj

+ 5 - 6
package.json

@@ -27,14 +27,13 @@
     "scripts": {
         "watch": "run-p gulp:build gulp:watch cljs:watch",
         "electron-watch": "run-p gulp:build gulp:watch cljs:electron-watch",
-        "release": "ENV=prod run-s gulp:build cljs:release",
-        "release-staging": "ENV=staging run-s gulp:build cljs:release",
+        "release": "run-s gulp:build cljs:release",
         "watch-app": "run-p gulp:watch cljs:watch-app",
-        "release-app": "ENV=prod run-s gulp:build cljs:release-app",
-        "release-publishing": "ENV=prod run-s gulp:build cljs:release-publishing",
-        "dev-release-app": "ENV=prod run-s gulp:build cljs:dev-release-app",
+        "release-app": "run-s gulp:build cljs:release-app",
+        "release-publishing": "run-s gulp:build cljs:release-publishing",
+        "dev-release-app": "run-s gulp:build cljs:dev-release-app",
         "dev-electron-app": "gulp electron",
-        "release-electron": "gulp build && ENV=prod gulp electronMaker",
+        "release-electron": "gulp build && gulp electronMaker",
         "debug-electron": "cd static/ && yarn electron:debug",
         "clean": "gulp clean",
         "test": "run-s cljs:test cljs:run-test",

+ 0 - 17
resources/config.edn

@@ -1,17 +0,0 @@
-{:runtime #profile {:dev :dev
-                    :staging :staging
-                    :test :test
-                    :prod :prod}
- :website #profile {:dev "http://localhost:3000"
-                    :staging "https://staging.logseq.com"
-                    :prod "https://logseq.com"}
- :api #profile {:dev "http://localhost:3000/api/v1/"
-                :staging "https://staging.logseq.com/api/v1/"
-                :prod "https://logseq.com/api/v1/"}
- :asset-domain #profile {:dev ""
-                         :staging "https://d2mcfbcftfbnmt.cloudfront.net"
-                         :prod "https://assets.logseq.com"}
- :github-app-name #profile {:dev "logseq-test"
-                            :staging "logseq-staging"
-                            :prod "logseq"}}
-

+ 1 - 1
resources/forge.config.js

@@ -2,7 +2,7 @@ const path = require('path')
 
 module.exports = {
   packagerConfig: {
-    icon: './icons/logseq_big_sur.icns',
+    icon: './icons/logseq.png',
     osxSign: {
       identity: 'Developer ID Application: Tiansheng Qin',
       'hardened-runtime': true,

+ 3 - 6
shadow-cljs.edn

@@ -31,8 +31,7 @@
     :http-root    "public"
     :http-port    3001
     :watch-path   "static"
-    :preloads     [devtools.preload]}
-   :build-hooks [(shadow-env.core/hook)]}
+    :preloads     [devtools.preload]}}
 
   :electron {:target :node-script
              :output-to "static/electron.js"
@@ -45,8 +44,7 @@
   {:target :node-test
    :output-to "static/tests.js"
    :closure-defines {frontend.util/NODETEST true}
-   :devtools {:enabled false}
-   :build-hooks [(shadow-env.core/hook)]}
+   :devtools {:enabled false}}
 
   :publishing
   {:target :browser
@@ -72,5 +70,4 @@
    {:before-load frontend.core/stop
     ;; after live-reloading finishes call this function
     :after-load frontend.core/start
-    :preloads     [devtools.preload]}
-   :build-hooks [(shadow-env.core/hook)]}}}
+    :preloads     [devtools.preload]}}}}

+ 4 - 3
src/electron/electron/core.cljs

@@ -14,7 +14,7 @@
 (defonce *teardown-fn (volatile! nil))
 
 ;; Handle creating/removing shortcuts on Windows when installing/uninstalling.
-(when (js/require "electron-squirrel-startup") (.quit app))
+;(when (js/require "electron-squirrel-startup") (.quit app))
 
 (defn create-main-window
   "create main app window"
@@ -31,7 +31,7 @@
                    :preload                 (path/join js/__dirname "js/preload.js")}}
         url MAIN_WINDOW_ENTRY
         win (BrowserWindow. (clj->js win-opts))]
-    (when win32? (.removeMenu win))
+    ;(when win32? (.removeMenu win))
     (.loadURL win url)
     (when dev? (.. win -webContents (openDevTools)))
     win))
@@ -47,7 +47,8 @@
    protocol "assets"
    (fn [^js request callback]
      (let [url (.-url request)
-           path (string/replace url "assets://" "")]
+           path (string/replace url "assets://" "")
+           path (js/decodeURIComponent path)]
        (callback #js {:path path}))))
   #(.unregisterProtocol protocol "assets"))
 

+ 1 - 1
src/main/frontend/commands.cljs

@@ -127,7 +127,7 @@
      (cond
        (and (util/electron?) (config/local-db? (state/get-current-repo)))
 
-       ["Upload an asset" [[:editor/click-hidden-file-input :id]]]
+       ["Upload an asset (image, pdf, docx, etc.)" [[:editor/click-hidden-file-input :id]]]
 
        (state/logged?)
        ["Upload an image" [[:editor/click-hidden-file-input :id]]])

+ 8 - 2
src/main/frontend/components/header.cljs

@@ -15,6 +15,7 @@
             [frontend.components.repo :as repo]
             [frontend.components.search :as search]
             [frontend.handler.project :as project-handler]
+            [frontend.handler.page :as page-handler]
             [frontend.handler.web.nfs :as nfs]
             [goog.dom :as gdom]
             [goog.object :as gobj]))
@@ -153,7 +154,12 @@
                    (remove #(= (:url %) config/local-repo)))]
     (rum/with-context [[t] i18n/*tongue-context*]
       [:div.cp__header#head
-       {:on-double-click #(when (util/electron?) (js/window.apis.toggleMaxOrMinActiveWindow))}
+       {:on-double-click (fn [^js e]
+                           (when-let [target (.-target e)]
+                             (when (and (util/electron?)
+                                        (or (.. target -classList (contains "cp__header"))
+                                            (. target (closest "#search"))))
+                               (js/window.apis.toggleMaxOrMinActiveWindow))))}
        (left-menu-button {:on-click (fn []
                                       (open-fn)
                                       (state/set-left-sidebar-open! true))})
@@ -188,7 +194,7 @@
                   (not config/publishing?))
          [:a.text-sm.font-medium.opacity-70.hover:opacity-100.ml-3.block
           {:on-click (fn []
-                       (nfs/ls-dir-files))}
+                       (page-handler/ls-dir-files!))}
           [:div.flex.flex-row.text-center
            [:span.inline-block svg/folder-add]
            (when-not config/mobile?

+ 7 - 2
src/main/frontend/components/page.cljs

@@ -1,6 +1,7 @@
 (ns frontend.components.page
   (:require [rum.core :as rum]
             [frontend.util :as util :refer-macros [profile]]
+            [frontend.tools.html-export :as html-export]
             [frontend.handler.file :as file]
             [frontend.handler.page :as page-handler]
             [frontend.handler.ui :as ui-handler]
@@ -306,11 +307,15 @@
                                                                              (page-handler/unpublish-page! page-name))}}
                                                       {:title   (t :page/publish)
                                                        :options {:on-click (fn []
-                                                                             (page-handler/publish-page! page-name project/add-project))}})
+                                                                             (page-handler/publish-page!
+                                                                               page-name project/add-project
+                                                                               html-export/export-page))}})
                                                     (when-not published?
                                                       {:title   (t :page/publish-as-slide)
                                                        :options {:on-click (fn []
-                                                                             (page-handler/publish-page-as-slide! page-name project/add-project))}})
+                                                                             (page-handler/publish-page-as-slide!
+                                                                               page-name project/add-project
+                                                                               html-export/export-page))}})
                                                     {:title   (t (if public? :page/make-private :page/make-public))
                                                      :options {:background (if public? "gray" "indigo")
                                                                :on-click (fn []

+ 2 - 1
src/main/frontend/components/repo.cljs

@@ -9,6 +9,7 @@
             [frontend.handler.route :as route-handler]
             [frontend.handler.export :as export-handler]
             [frontend.handler.web.nfs :as nfs-handler]
+            [frontend.handler.page :as page-handler]
             [frontend.util :as util]
             [frontend.config :as config]
             [reitit.frontend.easy :as rfe]
@@ -44,7 +45,7 @@
              [:div.mr-8
               (ui/button
                (t :open-a-directory)
-               :on-click nfs-handler/ls-dir-files)])
+               :on-click page-handler/ls-dir-files!)])
            (when (and (state/logged?) (not (util/electron?)))
              (ui/button
               "Add another git repo"

+ 3 - 3
src/main/frontend/components/search.cljs

@@ -200,7 +200,7 @@
         show-result? (boolean (seq search-result))]
     (rum/with-context [[t] i18n/*tongue-context*]
       [:div#search.flex-1.flex
-       [:div.flex.md:ml-0
+       [:div.inner
         [:label.sr-only {:for "search_field"} (t :search)]
         [:div#search-wrapper.relative.w-full.text-gray-400.focus-within:text-gray-600
          [:div.absolute.inset-y-0.flex.items-center.pointer-events-none.left-0
@@ -208,8 +208,8 @@
            {:view-box "0 0 20 20", :fill "currentColor"}
            [:path
             {:d
-             "M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z",
-             :clip-rule "evenodd",
+             "M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z"
+             :clip-rule "evenodd"
              :fill-rule "evenodd"}]]]
          [:input#search_field.block.w-full.h-full.pr-3.py-2.rounded-md.focus:outline-none.placeholder-gray-500.focus:placeholder-gray-400.sm:text-sm.sm:bg-transparent
 

+ 5 - 2
src/main/frontend/components/search.css

@@ -1,5 +1,8 @@
-#search p {
-  margin: 0;
+#search {
+  > .inner {
+    width: 100%;
+    max-width: 280px;
+  }
 }
 
 #search-wrapper svg {

+ 2 - 1
src/main/frontend/components/widgets.cljs

@@ -5,6 +5,7 @@
             [frontend.handler.repo :as repo-handler]
             [frontend.handler.notification :as notification]
             [frontend.handler.web.nfs :as nfs]
+            [frontend.handler.page :as page-handler]
             [frontend.state :as state]
             [clojure.string :as string]
             [frontend.ui :as ui]
@@ -87,7 +88,7 @@
        [:div.cp__widgets-open-local-directory
         [:div.select-file-wrap.cursor
          (when nfs-supported?
-           {:on-click nfs/ls-dir-files})
+           {:on-click page-handler/ls-dir-files!})
          [:div
           [:h1.title "Open a local directory"]
           [:p.text-sm

+ 16 - 21
src/main/frontend/config.cljs

@@ -2,8 +2,7 @@
   (:require [clojure.set :as set]
             [clojure.string :as string]
             [frontend.state :as state]
-            [frontend.util :as util]
-            [frontend.env :as env]))
+            [frontend.util :as util]))
 
 (goog-define DEV-RELEASE false)
 (defonce dev-release? DEV-RELEASE)
@@ -14,33 +13,28 @@
 
 ;; :TODO: How to do this?
 ;; (defonce desktop? ^boolean goog.DESKTOP)
-(def test? (= :test (env/get-static :runtime)))
-(def staging? (= :staging (env/get-static :runtime)))
-(def prod? (= :prod (env/get-static :runtime)))
 
 (def app-name "logseq")
+(def website
+  (if dev?
+    "http://localhost:3000"
+    (util/format "https://%s.com" app-name)))
 
-
-(def website (env/get-static :website))
-(def api (env/get-static :api))
-(def asset-domain (env/get-static :asset-domain))
-(def github-app-name (env/get-static :github-app-name))
+(def api
+  (if dev?
+    "http://localhost:3000/api/v1/"
+    (str website "/api/v1/")))
 
 (defn asset-uri
   [path]
-  (cond
-    (util/file-protocol?)
+  (if (util/file-protocol?)
     (string/replace path "/static/" "./")
+    (if dev? path
+        (str asset-domain path))))
 
-    dev? path
-
-    staging?
-    (if-let [branch (-> (state/get-me) :git-branch)]
-      (str asset-domain "/" branch path)
-      (str asset-domain path))
+(goog-define GITHUB_APP_NAME "logseq-test")
 
-    :else
-    (str asset-domain path)))
+(def github-app-name (if dev? GITHUB_APP_NAME "logseq"))
 
 (defn git-pull-secs
   []
@@ -293,7 +287,8 @@
 
 (defn local-db?
   [s]
-  (string/starts-with? s local-db-prefix))
+  (and (string? s)
+       (string/starts-with? s local-db-prefix)))
 
 (defn local-asset?
   [s]

+ 0 - 23
src/main/frontend/env.cljc

@@ -1,23 +0,0 @@
-(ns frontend.env
-  #?(:clj (:require [aero.core :as aero]
-                    [clojure.java.io :as io]
-                    [clojure.string :as str]))
-  (:refer-clojure :exclude [get])
-  (:require [shadow-env.core :as env]))
-
-#?(:clj
-   (defn read-env [build-state]
-     (let [aero-config {:profile (or (some->
-                                       (System/getenv "ENV")
-                                       (str/lower-case)
-                                       (keyword))
-                                     :dev)}
-           client-config (some-> (io/resource "config.edn")
-                           (aero/read-config aero-config))]
-       {:cljs client-config})))
-
-(env/link get `read-env)
-
-(defmacro get-static [& ks]
-  (let [ks (into [:shadow-env.core/cljs] ks)]
-    (clojure.core/get-in get ks)))

+ 0 - 1
src/main/frontend/handler.cljs

@@ -17,7 +17,6 @@
             [frontend.handler.file :as file-handler]
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.ui :as ui-handler]
-            [frontend.handler.export :as export-handler]
             [frontend.handler.web.nfs :as nfs]
             [frontend.fs.watcher-handler :as fs-watcher-handler]
             [frontend.ui :as ui]

+ 8 - 0
src/main/frontend/handler/common.cljs

@@ -13,6 +13,7 @@
             [cljs-time.core :as t]
             [cljs-time.format :as tf]
             [frontend.config :as config]
+            ["ignore" :as Ignore]
             ["/frontend/utils" :as utils]))
 
 (defn get-ref
@@ -61,6 +62,13 @@
   (assoc config
          :document/mode? (state/sub [:document/mode?])))
 
+(defn ignore-files
+  [pattern paths]
+  (-> (Ignore)
+      (.add pattern)
+      (.filter (bean/->js paths))
+      (bean/->clj)))
+
 (comment
   (let [repo (state/get-current-repo)]
     (p/let [remote-oid (get-remote-ref repo)

+ 1 - 0
src/main/frontend/handler/editor.cljs

@@ -1772,6 +1772,7 @@
          (and last-command
               (commands/get-matched-commands last-command)))))
     (catch js/Error e
+      (js/console.error e)
       nil)))
 
 (defn get-matched-block-commands

+ 0 - 8
src/main/frontend/handler/file.cljs

@@ -25,7 +25,6 @@
             [cljs-time.core :as t]
             [cljs-time.coerce :as tc]
             [frontend.utf8 :as utf8]
-            ["ignore" :as Ignore]
             ["/frontend/utils" :as utils]))
 
 ;; TODO: extract all git ops using a channel
@@ -303,13 +302,6 @@
           content (db/get-file path)]
       (alter-file repo path content {:re-render-root? true}))))
 
-(defn ignore-files
-  [pattern paths]
-  (-> (Ignore)
-      (.add pattern)
-      (.filter (bean/->js paths))
-      (bean/->clj)))
-
 ;; TODO: batch writes, how to deal with file history?
 (defn run-writes-chan!
   []

+ 14 - 7
src/main/frontend/handler/page.cljs

@@ -4,7 +4,6 @@
             [datascript.core :as d]
             [frontend.state :as state]
             [frontend.util :as util :refer-macros [profile]]
-            [frontend.tools.html-export :as html-export]
             [frontend.config :as config]
             [frontend.handler.common :as common-handler]
             [frontend.handler.route :as route-handler]
@@ -13,6 +12,7 @@
             [frontend.handler.git :as git-handler]
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.project :as project-handler]
+            [frontend.handler.web.nfs :as web-nfs]
             [frontend.handler.notification :as notification]
             [frontend.handler.config :as config-handler]
             [frontend.handler.ui :as ui-handler]
@@ -173,9 +173,9 @@
     @plugins))
 
 (defn publish-page-as-slide!
-  ([page-name project-add-modal]
-   (publish-page-as-slide! page-name (db/get-page-blocks page-name) project-add-modal))
-  ([page-name blocks project-add-modal]
+  ([page-name project-add-modal export-page-html]
+   (publish-page-as-slide! page-name (db/get-page-blocks page-name) project-add-modal export-page-html))
+  ([page-name blocks project-add-modal export-page-html]
    (project-handler/exists-or-create!
     (fn [project]
       (config-handler/set-config! [:project :name] project)
@@ -186,7 +186,7 @@
             data {:project project
                   :title page-name
                   :permalink (:permalink properties)
-                  :html (html-export/export-page page-name blocks notification/show!)
+                  :html (export-page-html page-name blocks notification/show!)
                   :tags (:tags properties)
                   :settings (merge
                              (assoc properties
@@ -201,7 +201,7 @@
     project-add-modal)))
 
 (defn publish-page!
-  [page-name project-add-modal]
+  [page-name project-add-modal export-page-html]
   (project-handler/exists-or-create!
    (fn [project]
      (let [properties (db/get-page-properties page-name)
@@ -218,7 +218,7 @@
              (let [data {:project project
                          :title page-name
                          :permalink (:permalink properties)
-                         :html (html-export/export-page page-name blocks notification/show!)
+                         :html (export-page-html page-name blocks notification/show!)
                          :tags (:tags properties)
                          :settings (merge properties plugins)
                          :repo (state/get-current-repo)}]
@@ -496,6 +496,13 @@
         (let [templates (map string/lower-case templates)]
           (contains? (set templates) (string/lower-case title)))))))
 
+(defn ls-dir-files!
+  []
+  (web-nfs/ls-dir-files-with-handler!
+    (fn []
+      (init-commands!))))
+
+
 ;; TODO: add use :file/last-modified-at
 (defn get-pages-with-modified-at
   [repo]

+ 4 - 5
src/main/frontend/handler/web/nfs.cljs

@@ -4,12 +4,10 @@
             [promesa.core :as p]
             [medley.core :as medley]
             [goog.object :as gobj]
-            [goog.dom :as gdom]
             [frontend.util :as util]
             [frontend.handler.common :as common-handler]
             ["/frontend/utils" :as utils]
             [frontend.handler.repo :as repo-handler]
-            [frontend.handler.file :as file-handler]
             [frontend.idb :as idb]
             [frontend.state :as state]
             [clojure.string :as string]
@@ -33,7 +31,7 @@
       (if-let [file (:file/file ignore-file)]
         (p/let [content (.text file)]
           (when content
-            (let [paths (set (file-handler/ignore-files content (map :file/path files)))]
+            (let [paths (set (common-handler/ignore-files content (map :file/path files)))]
               (when (seq paths)
                 (filter (fn [f] (contains? paths (:file/path f))) files)))))
         (p/resolved files))
@@ -99,8 +97,8 @@
     (set-files-aux! handles)))
 
 ;; TODO: extract code for `ls-dir-files` and `reload-dir!`
-(defn ls-dir-files
-  []
+(defn ls-dir-files-with-handler!
+  [ok-handler]
   (let [path-handles (atom {})
         electron? (util/electron?)
         nfs? (not electron?)]
@@ -154,6 +152,7 @@
                                                        :nfs-files    files})
 
                        (state/add-repo! {:url repo :nfs? true})
+                       (and ok-handler (ok-handler))
                        (when (util/electron?)
                          (fs/watch-dir! dir-name)))))
            (p/catch (fn [error]

+ 1 - 1
src/main/frontend/state.cljs

@@ -144,7 +144,7 @@
 
 (defn get-current-repo
   []
-  (:git/current-repo @state))
+  (or (:git/current-repo @state) "local"))
 
 (defn get-config
   ([]

+ 3 - 2
src/main/frontend/util.cljc

@@ -53,8 +53,9 @@
 #?(:cljs
    (defn electron?
      []
-     (let [ua (string/lower-case js/navigator.userAgent)]
-       (string/includes? ua " electron"))))
+     (when (and js/window (gobj/get js/window "navigator"))
+       (let [ua (string/lower-case js/navigator.userAgent)]
+         (string/includes? ua " electron")))))
 
 #?(:cljs
    (defn file-protocol?