浏览代码

creating new branch for PR

hkgnp 2 年之前
父节点
当前提交
b80a0abc1a
共有 1 个文件被更改,包括 43 次插入35 次删除
  1. 43 35
      src/main/electron/listener.cljs

+ 43 - 35
src/main/electron/listener.cljs

@@ -1,45 +1,49 @@
 (ns electron.listener
   "System-component-like ns that defines listeners by event name to receive ipc
   messages from electron's main process"
-  (:require [frontend.state :as state]
-            [frontend.context.i18n :refer [t]]
-            [frontend.date :as date]
-            [frontend.handler.route :as route-handler]
-            [frontend.handler.editor :as editor-handler]
-            [frontend.handler.ui :as ui-handler]
-            [frontend.handler.file-sync :as file-sync-handler]
-            [frontend.config :as config]
-            [clojure.string :as string]
-            [cljs-bean.core :as bean]
-            [frontend.fs.watcher-handler :as watcher-handler]
-            [frontend.fs.sync :as sync]
-            [frontend.db :as db]
-            [frontend.db.model :as db-model]
-            [datascript.core :as d]
-            [electron.ipc :as ipc]
-            [frontend.ui :as ui]
-            [frontend.handler.notification :as notification]
-            [frontend.handler.repo :as repo-handler]
-            [frontend.handler.user :as user]
-            [dommy.core :as dom]))
+  (:require
+    [cljs-bean.core :as bean]
+    [clojure.string :as string]
+    [datascript.core :as d]
+    [dommy.core :as dom]
+    [electron.ipc :as ipc]
+    [frontend.config :as config]
+    [frontend.context.i18n :refer [t]]
+    [frontend.date :as date]
+    [frontend.db :as db]
+    [frontend.db.model :as db-model]
+    [frontend.fs.sync :as sync]
+    [frontend.fs.watcher-handler :as watcher-handler]
+    [frontend.handler.editor :as editor-handler]
+    [frontend.handler.file-sync :as file-sync-handler]
+    [frontend.handler.notification :as notification]
+    [frontend.handler.repo :as repo-handler]
+    [frontend.handler.route :as route-handler]
+    [frontend.handler.ui :as ui-handler]
+    [frontend.handler.user :as user]
+    [frontend.state :as state]
+    [frontend.ui :as ui]))
+
 
 (defn persist-dbs!
   []
   ;; only persist current db!
   ;; TODO rename the function and event to persist-db
   (repo-handler/persist-db! {:before     #(notification/show!
-                                           (ui/loading (t :graph/persist))
-                                           :warning)
+                                            (ui/loading (t :graph/persist))
+                                            :warning)
                              :on-success #(ipc/ipc "persistent-dbs-saved")
                              :on-error   #(ipc/ipc "persistent-dbs-error")}))
 
+
 (defn listen-persistent-dbs!
   []
   ;; TODO: move "file-watcher" to electron.ipc.channels
   (js/window.apis.on
-   "persistent-dbs"
-   (fn [_req]
-     (persist-dbs!))))
+    "persistent-dbs"
+    (fn [_req]
+      (persist-dbs!))))
+
 
 (defn ^:large-vars/cleanup-todo listen-to-electron!
   []
@@ -124,14 +128,14 @@
                      (fn [data]
                        (let [repo (bean/->clj data)
                              before-f #(notification/show!
-                                        (ui/loading (t :graph/persist))
-                                        :warning)
+                                         (ui/loading (t :graph/persist))
+                                         :warning)
                              after-f #(ipc/ipc "broadcastPersistGraphDone")
                              error-f (fn []
                                        (after-f)
                                        (notification/show!
-                                        (t :graph/persist-error)
-                                        :error))
+                                         (t :graph/persist-error)
+                                         :error))
                              handlers {:before     before-f
                                        :on-success after-f
                                        :on-error   error-f}]
@@ -153,12 +157,14 @@
   (js/window.apis.on "quickCapture"
                      (fn [args]
                        (let [{:keys [url title content]} (bean/->clj args)
-                             page (or (state/get-current-page)
-                                      (string/lower-case (date/journal-name)))
+                             insert-today? (get-in (state/get-config)
+                                                   [:quick-capture-options :insert-today]
+                                                   false)
+                             page (if (true? insert-today?) (string/lower-case (date/journal-name)) (state/get-current-page))
                              format (db/get-page-format page)
                              time (date/get-current-time)
                              text (or (and content (not-empty (string/trim content))) "")
-                             link (if (not-empty title) (config/link-format format title url) url)
+                             link (if (string/includes? url "www.youtube.com/watch") (str title " {{video " url "}}") (if (not-empty title) (config/link-format format title url) url))
                              template (get-in (state/get-config)
                                               [:quick-capture-templates :text]
                                               "**{time}** [[quick capture]]: {text} {url}")
@@ -166,18 +172,20 @@
                                          (string/replace "{time}" time)
                                          (string/replace "{url}" link)
                                          (string/replace "{text}" text))]
-                         (if (and (state/get-edit-block) (state/editing?))
+                         (if (and (state/get-edit-block) (not state/editing?)) ; changed to not so that block is created at the end of the page
                            (editor-handler/insert content)
                            (editor-handler/api-insert-new-block! content {:page page
-                                                                          :edit-block? false
+                                                                          :edit-block? true
                                                                           :replace-empty-target? true})))))
 
+
   (js/window.apis.on "openNewWindowOfGraph"
                      ;; Handle open new window in renderer, until the destination graph doesn't rely on setting local storage
                      ;; No db cache persisting ensured. Should be handled by the caller
                      (fn [repo]
                        (ui-handler/open-new-window! repo))))
 
+
 (defn listen!
   []
   (listen-to-electron!)