diff --git a/src/electron/electron/configs.cljs b/src/electron/electron/configs.cljs index a20f780dce..837e15e5ec 100644 --- a/src/electron/electron/configs.cljs +++ b/src/electron/electron/configs.cljs @@ -8,7 +8,6 @@ (defonce cfg-root (.getPath app "userData")) (defonce cfg-path (.join path cfg-root "configs.edn")) - (defn- ensure-cfg [] (try @@ -17,7 +16,8 @@ (let [body (.toString (.readFileSync fs cfg-path))] (if (seq body) (reader/read-string body) {}))) (catch js/Error e - (js/console.error :cfg-error e)))) + (js/console.error :cfg-error e) + {}))) (defn- write-cfg! [cfg] @@ -43,7 +43,6 @@ (when-let [cfg (and k (ensure-cfg))] (get cfg k))) - -(defn whole +(defn get-config [] - (ensure-cfg)) \ No newline at end of file + (ensure-cfg)) diff --git a/src/electron/electron/git.cljs b/src/electron/electron/git.cljs index cd5457edb4..819a0fa7fd 100644 --- a/src/electron/electron/git.cljs +++ b/src/electron/electron/git.cljs @@ -105,9 +105,11 @@ (defn auto-commit-current-graph! [] - (when (installed?) + (when (and (installed?) + (not (state/git-auto-commit-disabled?))) (state/clear-git-commit-interval!) (p/let [_ (add-all-and-commit!)] - (let [seconds (state/get-git-commit-seconds) - interval (js/setInterval add-all-and-commit! (* seconds 1000))] - (state/set-git-commit-interval! interval))))) + (let [seconds (state/get-git-commit-seconds)] + (when (int? seconds) + (let [interval (js/setInterval add-all-and-commit! (* seconds 1000))] + (state/set-git-commit-interval! interval))))))) diff --git a/src/electron/electron/handler.cljs b/src/electron/electron/handler.cljs index ed048ff6ca..e5bce7766a 100644 --- a/src/electron/electron/handler.cljs +++ b/src/electron/electron/handler.cljs @@ -190,11 +190,12 @@ (.quit app)) (defmethod handle :userAppCfgs [_window [_ k v]] - (if-not k - (cfgs/whole) - (if-not (nil? v) - (cfgs/set-item! (keyword k) v) - (cfgs/get-item (keyword k))))) + (let [config (cfgs/get-config)] + (if-not k + config + (if-not (nil? v) + (cfgs/set-item! (keyword k) v) + (cfgs/get-item (keyword k)))))) (defmethod handle :getDirname [_] js/__dirname) diff --git a/src/electron/electron/state.cljs b/src/electron/electron/state.cljs index c67c786558..3c01894a7e 100644 --- a/src/electron/electron/state.cljs +++ b/src/electron/electron/state.cljs @@ -1,12 +1,14 @@ (ns electron.state - (:require [clojure.core.async :as async])) + (:require [clojure.core.async :as async] + [electron.configs :as config])) (defonce persistent-dbs-chan (async/chan 1)) (defonce state (atom {:graph/current nil - :git/auto-commit-seconds 60 - :git/auto-commit-interval nil})) + :git/auto-commit-interval nil + + :config (config/get-config)})) (defn set-state! [path value] @@ -23,13 +25,10 @@ (when-let [interval (get @state :git/auto-commit-interval)] (js/clearInterval interval))) -(defn set-git-commit-seconds! - [v] - (let [v (if (and (integer? v) (< 0 v (inc (* 60 10)))) ; max 10 minutes - v - 60)] - (set-state! :git/auto-commit-seconds v))) - (defn get-git-commit-seconds [] - (or (get @state :git/auto-commit-seconds) 60)) + (get-in @state [:config :git/auto-commit-seconds] 60)) + +(defn git-auto-commit-disabled? + [] + (get-in @state [:config :git/disable-auto-commit?])) diff --git a/src/main/frontend/components/settings.cljs b/src/main/frontend/components/settings.cljs index 0836dec487..f096196b7c 100644 --- a/src/main/frontend/components/settings.cljs +++ b/src/main/frontend/components/settings.cljs @@ -128,21 +128,21 @@ (rum/defc delete-account-confirm [close-fn] (rum/with-context [[t] i18n/*tongue-context*] - [:div - (ui/admonition - :important - [:p.text-gray-700 (t :user/delete-account-notice)]) - [:div.mt-5.sm:mt-4.sm:flex.sm:flex-row-reverse - [:span.flex.w-full.rounded-md.sm:ml-3.sm:w-auto - [:button.inline-flex.justify-center.w-full.rounded-md.border.border-transparent.px-4.py-2.bg-indigo-600.text-base.leading-6.font-medium.text-white.shadow-sm.hover:bg-indigo-500.focus:outline-none.focus:border-indigo-700.focus:shadow-outline-indigo.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5 - {:type "button" - :on-click user-handler/delete-account!} - (t :user/delete-account)]] - [:span.mt-3.flex.w-full.rounded-md.sm:mt-0.sm:w-auto - [:button.inline-flex.justify-center.w-full.rounded-md.border.border-gray-300.px-4.py-2.bg-white.text-base.leading-6.font-medium.text-gray-700.shadow-sm.hover:text-gray-500.focus:outline-none.focus:border-blue-300.focus:shadow-outline-blue.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5 - {:type "button" - :on-click close-fn} - "Cancel"]]]])) + [:div + (ui/admonition + :important + [:p.text-gray-700 (t :user/delete-account-notice)]) + [:div.mt-5.sm:mt-4.sm:flex.sm:flex-row-reverse + [:span.flex.w-full.rounded-md.sm:ml-3.sm:w-auto + [:button.inline-flex.justify-center.w-full.rounded-md.border.border-transparent.px-4.py-2.bg-indigo-600.text-base.leading-6.font-medium.text-white.shadow-sm.hover:bg-indigo-500.focus:outline-none.focus:border-indigo-700.focus:shadow-outline-indigo.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5 + {:type "button" + :on-click user-handler/delete-account!} + (t :user/delete-account)]] + [:span.mt-3.flex.w-full.rounded-md.sm:mt-0.sm:w-auto + [:button.inline-flex.justify-center.w-full.rounded-md.border.border-gray-300.px-4.py-2.bg-white.text-base.leading-6.font-medium.text-gray-700.shadow-sm.hover:text-gray-500.focus:outline-none.focus:border-blue-300.focus:shadow-outline-blue.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5 + {:type "button" + :on-click close-fn} + "Cancel"]]]])) (rum/defc outdenting-hint [] @@ -160,10 +160,10 @@ (defn edit-config-edn [] (rum/with-context [[t] i18n/*tongue-context*] - [:div.text-sm - [:a.text-xs {:href (rfe/href :file {:path (config/get-config-path)}) - :on-click #(js/setTimeout (fn [] (ui-handler/toggle-settings-modal!)))} - (t :settings-page/edit-config-edn)]])) + [:div.text-sm + [:a.text-xs {:href (rfe/href :file {:path (config/get-config-path)}) + :on-click #(js/setTimeout (fn [] (ui-handler/toggle-settings-modal!)))} + (t :settings-page/edit-config-edn)]])) (defn show-brackets-row [t show-brackets?] [:div.it.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-start @@ -178,12 +178,7 @@ [:div {:style {:text-align "right"}} (ui/keyboard-shortcut (shortcut-helper/gen-shortcut-seq :ui/toggle-brackets))]]) -(rum/defcs switch-spell-check-row - < {:will-mount - (fn [state] - (state/load-app-user-cfgs) - state)} - rum/reactive +(rum/defcs switch-spell-check-row < rum/reactive [state t] (let [enabled? (state/sub [:electron/user-cfgs :spell-check]) enabled? (if (nil? enabled?) true enabled?)] @@ -194,21 +189,48 @@ [:div [:div.rounded-md.sm:max-w-xs (ui/toggle - enabled? - (fn [] - (state/set-state! [:electron/user-cfgs :spell-check] (not enabled?)) - (p/then (ipc/ipc "userAppCfgs" :spell-check (not enabled?)) - #(if (js/confirm (t :relaunch-confirm-to-work)) - (js/logseq.api.relaunch)))) - true)]]])) + enabled? + (fn [] + (state/set-state! [:electron/user-cfgs :spell-check] (not enabled?)) + (p/then (ipc/ipc "userAppCfgs" :spell-check (not enabled?)) + #(if (js/confirm (t :relaunch-confirm-to-work)) + (js/logseq.api.relaunch)))) + true)]]])) -(rum/defcs app-auto-update-row - < {:will-mount - (fn [state] - (state/load-app-user-cfgs) - state)} - rum/reactive +(rum/defcs switch-git-auto-commit-row < rum/reactive [state t] + (let [enabled? (not (state/sub [:electron/user-cfgs :git/disable-auto-commit?]))] + [:div.it.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-start + [:label.block.text-sm.font-medium.leading-5.opacity-70 + "Git auto commit"] + [:div + [:div.rounded-md.sm:max-w-xs + (ui/toggle + enabled? + (fn [] + (state/set-state! [:electron/user-cfgs :git/disable-auto-commit?] enabled?) + (ipc/ipc "userAppCfgs" :git/disable-auto-commit? enabled?)) + true)]]])) + +(rum/defcs git-auto-commit-seconds < rum/reactive + [state t] + (let [secs (or (state/sub [:electron/user-cfgs :git/auto-commit-seconds]) 60)] + [:div.it.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-start + [:label.block.text-sm.font-medium.leading-5.opacity-70 + "Git auto commit seconds"] + [:div.mt-1.sm:mt-0.sm:col-span-2 + [:div.max-w-lg.rounded-md.sm:max-w-xs + [:input#home-default-page.form-input.is-small.transition.duration-150.ease-in-out + {:default-value secs + :on-blur (fn [event] + (when-let [value (-> (util/evalue event) + util/safe-parse-int)] + (when (< 0 value (inc 600)) + (state/set-state! [:electron/user-cfgs :git/auto-commit-seconds] value) + (ipc/ipc "userAppCfgs" :git/auto-commit-seconds value))))}]]]])) + +(rum/defc app-auto-update-row < rum/reactive + [t] (let [enabled? (state/sub [:electron/user-cfgs :auto-update]) enabled? (if (nil? enabled?) true enabled?)] @@ -218,11 +240,11 @@ [:div [:div.rounded-md.sm:max-w-xs (ui/toggle - enabled? - (fn [] - (state/set-state! [:electron/user-cfgs :auto-update] (not enabled?)) - (ipc/ipc "userAppCfgs" :auto-update (not enabled?))) - true)]]])) + enabled? + (fn [] + (state/set-state! [:electron/user-cfgs :auto-update] (not enabled?)) + (ipc/ipc "userAppCfgs" :auto-update (not enabled?))) + true)]]])) (rum/defcs current-graph [state t] @@ -314,8 +336,8 @@ (when-not (string/blank? format) (config-handler/set-config! :journal/page-title-format format) (notification/show! - [:div "You need to re-index your graph to make the change works"] - :success) + [:div "You need to re-index your graph to make the change works"] + :success) (state/close-modal!) (route-handler/redirect! {:to :repos}))))} (for [format (sort (date/journal-title-formatters))] @@ -478,7 +500,7 @@ (t :settings-page/disable-sentry) (not instrument-disabled?) (fn [] (instrument/disable-instrument - (not instrument-disabled?))) + (not instrument-disabled?))) [:span.text-sm.opacity-50 "Logseq will never collect your local graph database or sell your data."])) (defn clear-cache-row [t] @@ -516,9 +538,12 @@ (rum/defcs settings < (rum/local :general ::active) - rum/reactive + {:will-mount + (fn [state] + (state/load-app-user-cfgs) + state)} + rum/reactive [state] - (let [preferred-format (state/get-preferred-format) preferred-date-format (state/get-date-formatter) preferred-workflow (state/get-preferred-workflow) @@ -558,6 +583,7 @@ (for [[label text icon] [[:general (t :settings-page/tab-general) (svg/adjustments 16)] [:editor (t :settings-page/tab-editor) (svg/icon-editor 16)] [:shortcuts (t :settings-page/tab-shortcuts) (svg/icon-cmd 18)] + [:git (t :settings-page/tab-version-control) svg/git] [:advanced (t :settings-page/tab-advanced) (svg/icon-cli 16)]]] [:li @@ -599,6 +625,15 @@ [:div.panel-wrap (keyboard-shortcuts-row t)] + :git + [:div.panel-wrap + (switch-git-auto-commit-row t) + (git-auto-commit-seconds t) + + (ui/admonition + :warning + [:p "You need to restart the app after updating the settings."])] + :advanced [:div.panel-wrap.is-advanced (when (and util/mac? (util/electron?)) (app-auto-update-row t)) @@ -627,11 +662,11 @@ (user-handler/set-cors! server) (notification/show! "Custom CORS proxy updated successfully!" :success)))))}]]]] (ui/admonition - :important - [:p (t :settings-page/dont-use-other-peoples-proxy-servers) - [:a {:href "https://github.com/isomorphic-git/cors-proxy" - :target "_blank"} - "https://github.com/isomorphic-git/cors-proxy"]])]) + :important + [:p (t :settings-page/dont-use-other-peoples-proxy-servers) + [:a {:href "https://github.com/isomorphic-git/cors-proxy" + :target "_blank"} + "https://github.com/isomorphic-git/cors-proxy"]])]) (when logged? [:div @@ -643,8 +678,8 @@ [:div.mt-1.sm:mt-0.sm:col-span-2 [:div.max-w-lg.rounded-md.sm:max-w-xs (ui/button (t :user/delete-your-account) - :on-click (fn [] - (ui-handler/toggle-settings-modal!) - (js/setTimeout #(state/set-modal! delete-account-confirm))))]]]])] + :on-click (fn [] + (ui-handler/toggle-settings-modal!) + (js/setTimeout #(state/set-modal! delete-account-confirm))))]]]])] nil)]]]))) diff --git a/src/main/frontend/components/settings.css b/src/main/frontend/components/settings.css index 73f0b59f68..8b7f564cc1 100644 --- a/src/main/frontend/components/settings.css +++ b/src/main/frontend/components/settings.css @@ -242,3 +242,13 @@ } } } + + +svg.git { + margin-left: -4px; + transform: scale(0.9); +} + +svg.cmd { + margin-left: -1px; +} diff --git a/src/main/frontend/components/svg.cljs b/src/main/frontend/components/svg.cljs index 24762ac695..9dc39d9492 100644 --- a/src/main/frontend/components/svg.cljs +++ b/src/main/frontend/components/svg.cljs @@ -567,6 +567,9 @@ :height "20"} opts) [:path {:d "M512 12.63616c-282.74688 0-512 229.21216-512 512 0 226.22208 146.69824 418.14016 350.12608 485.82656 25.57952 4.73088 35.00032-11.10016 35.00032-24.63744 0-12.20608-0.47104-52.55168-0.69632-95.31392-142.4384 30.96576-172.50304-60.416-172.50304-60.416-23.28576-59.16672-56.85248-74.91584-56.85248-74.91584-46.44864-31.78496 3.50208-31.1296 3.50208-31.1296 51.4048 3.60448 78.47936 52.75648 78.47936 52.75648 45.6704 78.27456 119.76704 55.64416 149.01248 42.55744 4.58752-33.09568 17.85856-55.68512 32.50176-68.46464-113.72544-12.94336-233.2672-56.85248-233.2672-253.0304 0-55.88992 20.00896-101.5808 52.75648-137.4208-5.3248-12.9024-22.85568-64.96256 4.95616-135.49568 0 0 43.008-13.74208 140.84096 52.49024 40.83712-11.34592 84.64384-17.03936 128.16384-17.24416 43.49952 0.2048 87.32672 5.87776 128.24576 17.24416 97.73056-66.2528 140.65664-52.49024 140.65664-52.49024 27.87328 70.53312 10.3424 122.59328 5.03808 135.49568 32.82944 35.86048 52.69504 81.53088 52.69504 137.4208 0 196.64896-119.78752 239.94368-233.79968 252.6208 18.37056 15.89248 34.73408 47.04256 34.73408 94.80192 0 68.5056-0.59392 123.63776-0.59392 140.51328 0 13.6192 9.216 29.5936 35.16416 24.576 203.32544-67.76832 349.83936-259.62496 349.83936-485.76512 0-282.78784-229.23264-512-512-512z"}]])) +(def git + [:svg.icon.git {:width 24 :height 24 :viewbox "0 0 24 24" :stroke-width "2" :stroke "currentColor" :fill "none" :stroke-linecap "round" :stroke-linejoin "round"} [:path {:stroke "none" :d "M0 0h24v24H0z" :fill "none"}] [:circle {:cx "12" :cy "18" :r "2"}] [:circle {:cx "7" :cy "6" :r "2"}] [:circle {:cx "17" :cy "6" :r "2"}] [:path {:d "M7 8v2a2 2 0 0 0 2 2h6a2 2 0 0 0 2 -2v-2"}] [:line {:x1 "12" :y1 "12" :x2 "12" :y2 "16"}]]) + (defn info [] [:svg {:class "info" :view-box "0 0 16 16" :width "16px" :height "16px"} @@ -622,7 +625,7 @@ (defn icon-cmd ([] (icon-cmd 16)) ([size] - [:svg {:viewBox "0 0 1024 1024" :width size :height size} + [:svg.cmd {:viewBox "0 0 1024 1024" :width size :height size} [:path {:d "M880 112H144c-17.7 0-32 14.3-32 32v736c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V144c0-17.7-14.3-32-32-32z m-40 728H184V184h656v656z" :fill "currentColor"}] [:path {:d "M370.8 554.4c-54.6 0-98.8 44.2-98.8 98.8s44.2 98.8 98.8 98.8 98.8-44.2 98.8-98.8v-42.4h84.7v42.4c0 54.6 44.2 98.8 98.8 98.8s98.8-44.2 98.8-98.8-44.2-98.8-98.8-98.8h-42.4v-84.7h42.4c54.6 0 98.8-44.2 98.8-98.8 0-54.6-44.2-98.8-98.8-98.8s-98.8 44.2-98.8 98.8v42.4h-84.7v-42.4c0-54.6-44.2-98.8-98.8-98.8S272 316.2 272 370.8s44.2 98.8 98.8 98.8h42.4v84.7h-42.4z m42.4 98.8c0 23.4-19 42.4-42.4 42.4s-42.4-19-42.4-42.4 19-42.4 42.4-42.4h42.4v42.4z m197.6-282.4c0-23.4 19-42.4 42.4-42.4s42.4 19 42.4 42.4-19 42.4-42.4 42.4h-42.4v-42.4z m0 240h42.4c23.4 0 42.4 19 42.4 42.4s-19 42.4-42.4 42.4-42.4-19-42.4-42.4v-42.4zM469.6 469.6h84.7v84.7h-84.7v-84.7z m-98.8-56.4c-23.4 0-42.4-19-42.4-42.4s19-42.4 42.4-42.4 42.4 19 42.4 42.4v42.4h-42.4z" :fill "currentColor"}]])) @@ -657,4 +660,4 @@ [:path {:stroke-linecap "round" :stroke-linejoin "round" :stroke-width "2" :d "M5 13l4 4L19 7"}]])) (def arrow-expand - (hero-icon "M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4")) \ No newline at end of file + (hero-icon "M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4")) diff --git a/src/main/frontend/dicts.cljs b/src/main/frontend/dicts.cljs index 93a560f4ac..a3445dedc7 100644 --- a/src/main/frontend/dicts.cljs +++ b/src/main/frontend/dicts.cljs @@ -237,6 +237,7 @@ :settings-page/tab-general "General" :settings-page/tab-editor "Editor" :settings-page/tab-shortcuts "Shortcuts" + :settings-page/tab-version-control "Git" :settings-page/tab-advanced "Advanced" :logseq "Logseq" :on "ON" @@ -918,6 +919,7 @@ :settings-page/tab-editor "编辑器" :settings-page/tab-shortcuts "快捷键" :settings-page/tab-advanced "高级设置" + :settings-page/tab-version-control "多版本控制" :logseq "Logseq" :on "已打开" :more-options "更多选项" diff --git a/src/main/frontend/extensions/zotero.cljs b/src/main/frontend/extensions/zotero.cljs index 8d461475fd..7be1fe8b6e 100644 --- a/src/main/frontend/extensions/zotero.cljs +++ b/src/main/frontend/extensions/zotero.cljs @@ -330,8 +330,8 @@ (rum/defc zotero-profile-selector < rum/reactive [profile*] - [:div.zotero-profile-selector.m-2 - [:label.mr-1 {:for "profile-select"} "Choose a profile:"] + [:div.zotero-profile-selector.my-4 + [:label.mr-32 {:for "profile-select"} "Choose a profile:"] [:select {:value @profile* :on-change @@ -346,7 +346,7 @@ (ui/button "New profile" :small? true - :class "ml-2" + :class "ml-4" :on-click (fn [] (state/set-modal! @@ -356,7 +356,7 @@ "Delete profile!" :small? true :background "red" - :class "ml-2" + :class "ml-4" :on-click (fn [] (p/let [_ (setting/remove-profile @profile*)]