Explorar o código

feat: add git auto push option to settings

Also, add ctrl-s for auto-pushing
Tienson Qin %!s(int64=4) %!d(string=hai) anos
pai
achega
1b38b9deb1

+ 10 - 0
src/main/frontend/components/settings.cljs

@@ -81,6 +81,7 @@
         enable-timetracking? (state/enable-timetracking?)
         current-repo (state/get-current-repo)
         enable-journals? (state/enable-journals? current-repo)
+        enable-git-auto-push? (state/enable-git-auto-push? current-repo)
         enable-block-time? (state/enable-block-time?)
         show-brackets? (state/show-brackets?)
         github-token (state/sub [:me :access-token])
@@ -234,6 +235,15 @@
                                 :else
                                 (notification/show! "Please make sure the page exists!" :warning))))}]]]])
 
+         (when (string/starts-with? current-repo "https://")
+           (toggle "enable_git_auto_push"
+                  "Enable Git auto push"
+                  enable-git-auto-push?
+                  (fn []
+                    (let [value (not enable-git-auto-push?)]
+                      (config-handler/set-config! :git-auto-push value)))))
+
+
          [:hr]
 
          (when logged?

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

@@ -2101,4 +2101,11 @@
 
 (defn periodically-save!
   []
-  (js/setInterval save-current-block-when-idle! 1000))
+  (js/setInterval save-current-block-when-idle! 500))
+
+(defn save!
+  []
+  (when-let [repo (state/get-current-repo)]
+    (save-current-block-when-idle! {:check-idle? false})
+    (when (string/starts-with? repo "https://") ; git repo
+      (repo-handler/auto-push!))))

+ 4 - 0
src/main/frontend/handler/repo.cljs

@@ -659,3 +659,7 @@
 (defn get-repo-name
   [url]
   (last (string/split url #"/")))
+
+(defn auto-push!
+  []
+  (git-commit-and-push! "Logseq auto save"))

+ 3 - 2
src/main/frontend/keyboards.cljs

@@ -93,8 +93,9 @@
    "t r" ui-handler/toggle-right-sidebar!
    "t e" state/toggle-new-block-shortcut!
    "s" route-handler/toggle-between-page-and-file!
-   "ctrl+c ctrl+s" (chord-aux search-handler/rebuild-indices!)
-   "ctrl+c ctrl+b" (chord-aux config-handler/toggle-ui-show-brackets!)})
+   "mod+s" (chord-aux editor-handler/save!)
+   "mod+c mod+s" (chord-aux search-handler/rebuild-indices!)
+   "mod+c mod+b" (chord-aux config-handler/toggle-ui-show-brackets!)})
 
 (defonce bind! (gobj/get mousetrap "bind"))
 

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

@@ -15,7 +15,7 @@
     {:name :home
      :view home/home}]
 
-   ["/repos"
+   ["/graphs"
     {:name :repos
      :view repo/repos}]
 

+ 5 - 0
src/main/frontend/state.cljs

@@ -182,6 +182,11 @@
   (not (false? (:feature/enable-journals?
                 (get (sub-config) repo)))))
 
+(defn enable-git-auto-push?
+  [repo]
+  (not (false? (:git-auto-push
+                (get (sub-config) repo)))))
+
 (defn enable-block-time?
   []
   (true? (:feature/enable-block-time?