-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
settings.cljs
1195 lines (1085 loc) · 51.8 KB
/
settings.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(ns frontend.components.settings
(:require [clojure.string :as string]
[electron.ipc :as ipc]
[logseq.shui.core :as shui]
[frontend.shui :refer [make-shui-context]]
[frontend.colors :as colors]
[frontend.components.assets :as assets]
[frontend.components.conversion :as conversion-component]
[frontend.components.file-sync :as fs]
[frontend.components.plugins :as plugins]
[frontend.components.svg :as svg]
[frontend.config :as config]
[frontend.context.i18n :refer [t]]
[frontend.date :as date]
[frontend.db :as db]
[frontend.dicts :as dicts]
[frontend.handler :as handler]
[frontend.handler.config :as config-handler]
[frontend.handler.file-sync :as file-sync-handler]
[frontend.handler.global-config :as global-config-handler]
[frontend.handler.notification :as notification]
[frontend.handler.plugin :as plugin-handler]
[frontend.handler.route :as route-handler]
[frontend.handler.ui :as ui-handler]
[frontend.handler.user :as user-handler]
[frontend.mobile.util :as mobile-util]
[frontend.modules.instrumentation.core :as instrument]
[frontend.modules.shortcut.data-helper :as shortcut-helper]
[frontend.components.shortcut :as shortcut]
[frontend.spec.storage :as storage-spec]
[frontend.state :as state]
[frontend.storage :as storage]
[frontend.ui :as ui]
[frontend.util :refer [classnames web-platform?] :as util]
[frontend.version :refer [version]]
[goog.object :as gobj]
[goog.string :as gstring]
[promesa.core :as p]
[reitit.frontend.easy :as rfe]
[rum.core :as rum]))
(defn toggle
[label-for name state on-toggle & [detail-text]]
[:div.it.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-center
[:label.block.text-sm.font-medium.leading-5.opacity-70
{:for label-for}
name]
[:div.rounded-md.sm:max-w-tss.sm:col-span-2
[:div.rounded-md {:style {:display "flex" :gap "1rem" :align-items "center"}}
(ui/toggle state on-toggle true)
detail-text]]])
(rum/defcs app-updater < rum/reactive
[state version]
(let [update-pending? (state/sub :electron/updater-pending?)
{:keys [type payload]} (state/sub :electron/updater)]
[:span.cp__settings-app-updater
[:div.ctls.flex.items-center
[:div.mt-1.sm:mt-0.sm:col-span-2
{:style {:display "flex" :gap "0.5rem" :align-items "center"}}
[:div (cond
(mobile-util/native-android?)
(ui/button
(t :settings-page/check-for-updates)
:class "text-sm p-1 mr-1"
:href "https://github.com/logseq/logseq/releases")
(mobile-util/native-ios?)
(ui/button
(t :settings-page/check-for-updates)
:class "text-sm p-1 mr-1"
:href "https://apps.apple.com/app/logseq/id1601013908")
(util/electron?)
(ui/button
(if update-pending? (t :settings-page/checking) (t :settings-page/check-for-updates))
:class "text-sm p-1 mr-1"
:disabled update-pending?
:on-click #(js/window.apis.checkForUpdates false))
:else
nil)]
[:div.text-sm.cursor
{:title (str (t :settings-page/revision) config/revision)
:on-click (fn []
(notification/show! [:div "Current Revision: "
[:a {:target "_blank"
:href (str "https://github.com/logseq/logseq/commit/" config/revision)}
config/revision]]
:info
false))}
version]
[:a.text-sm.fade-link.underline.inline
{:target "_blank"
:href "https://docs.logseq.com/#/page/changelog"}
(t :settings-page/changelog)]]]
(when-not (or update-pending?
(string/blank? type))
[:div.update-state.text-sm
(case type
"update-not-available"
[:p (t :settings-page/app-updated)]
"update-available"
(let [{:keys [name url]} payload]
[:p (str (t :settings-page/update-available))
[:a.link
{:on-click
(fn [e]
(js/window.apis.openExternal url)
(util/stop e))}
svg/external-link name " 🎉"]])
"error"
[:p (t :settings-page/update-error-1) [:br] (t :settings-page/update-error-2)
[:a.link
{:on-click
(fn [e]
(js/window.apis.openExternal "https://github.com/logseq/logseq/releases")
(util/stop e))}
svg/external-link " release channel"]])])]))
(rum/defc outdenting-hint
[]
[:div.ui__modal-panel
{:style {:box-shadow "0 4px 20px 4px rgba(0, 20, 60, .1), 0 4px 80px -8px rgba(0, 20, 60, .2)"}}
[:div {:style {:margin "12px" :max-width "500px"}}
[:p.text-sm
(t :settings-page/preferred-outdenting-tip)
[:a.text-sm
{:target "_blank" :href "https://discuss.logseq.com/t/whats-your-preferred-outdent-behavior-the-direct-one-or-the-logical-one/978"}
(t :settings-page/preferred-outdenting-tip-more)]]
[:img {:src "https://discuss.logseq.com/uploads/default/original/1X/e8ea82f63a5e01f6d21b5da827927f538f3277b9.gif"
:width 500
:height 500}]]])
(rum/defc auto-expand-hint
[]
[:div.ui__modal-panel
{:style {:box-shadow "0 4px 20px 4px rgba(0, 20, 60, .1), 0 4px 80px -8px rgba(0, 20, 60, .2)"}}
[:div {:style {:margin "12px" :max-width "500px"}}
[:p.text-sm
(t :settings-page/auto-expand-block-refs-tip)]
[:img {:src "https://user-images.githubusercontent.com/28241963/225818326-118deda9-9d1e-477d-b0ce-771ca0bcd976.gif"
:width 500
:height 500}]]])
(defn row-with-button-action
[{:keys [left-label description action button-label href on-click desc -for stretch center?]
:or {center? true}}]
[:div.it.sm:grid.sm:grid-cols-3.sm:gap-4
{:class (if center? "sm:items-center" "sm:items-start")}
;; left column
[:div.flex.flex-col
[:label.block.text-sm.font-medium.leading-5.opacity-70
{:for -for}
left-label]
(when description
[:div.text-xs.text-gray-10 description])]
;; right column
[:div.mt-1.sm:mt-0.sm:col-span-2.flex.items-center
{:style {:display "flex" :gap "0.5rem" :align-items "center"}}
[:div {:style (when stretch {:width "100%"})}
(if action action (shui/button {:text button-label
:href href
:on-click on-click}
(make-shui-context)))]
(when-not (or (util/mobile?)
(mobile-util/native-platform?))
[:div.text-sm.flex desc])]])
(defn edit-config-edn []
(row-with-button-action
{:left-label (t :settings-page/custom-configuration)
:button-label (t :settings-page/edit-config-edn)
:href (rfe/href :file {:path (config/get-repo-config-path)})
:on-click ui-handler/toggle-settings-modal!
:-for "config_edn"}))
(defn edit-global-config-edn []
(row-with-button-action
{:left-label (t :settings-page/custom-global-configuration)
:button-label (t :settings-page/edit-global-config-edn)
:href (rfe/href :file {:path (global-config-handler/global-config-path)})
:on-click ui-handler/toggle-settings-modal!
:-for "global_config_edn"}))
(defn edit-custom-css []
(row-with-button-action
{:left-label (t :settings-page/custom-theme)
:button-label (t :settings-page/edit-custom-css)
:href (rfe/href :file {:path (config/get-custom-css-path)})
:on-click ui-handler/toggle-settings-modal!
:-for "customize_css"}))
(defn edit-export-css []
(row-with-button-action
{:left-label (t :settings-page/export-theme)
:button-label (t :settings-page/edit-export-css)
:href (rfe/href :file {:path (config/get-export-css-path)})
:on-click ui-handler/toggle-settings-modal!
:-for "export_css"}))
(defn show-brackets-row [t show-brackets?]
[:div.it.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-center
[:label.block.text-sm.font-medium.leading-5.opacity-70
{:for "show_brackets"}
(t :settings-page/show-brackets)]
[:div
[:div.rounded-md.sm:max-w-xs
(ui/toggle show-brackets?
config-handler/toggle-ui-show-brackets!
true)]]
(when (not (or (util/mobile?) (mobile-util/native-platform?)))
[:div {:style {:text-align "right"}}
(ui/render-keyboard-shortcut (shortcut-helper/gen-shortcut-seq :ui/toggle-brackets))])])
(rum/defcs switch-spell-check-row < rum/reactive
[state t]
(let [enabled? (state/sub [:electron/user-cfgs :spell-check])]
[:div.it.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-center
[:label.block.text-sm.font-medium.leading-5.opacity-70
(t :settings-page/spell-checker)]
[: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?))
#(when (js/confirm (t :relaunch-confirm-to-work))
(js/logseq.api.relaunch))))
true)]]]))
(rum/defcs switch-git-auto-commit-row < rum/reactive
[state t]
(let [enabled? (state/get-git-auto-commit-enabled?)]
[:div.it.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-center
[:label.block.text-sm.font-medium.leading-5.opacity-70
(t :settings-page/git-switcher-label)]
[: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-center
[:label.block.text-sm.font-medium.leading-5.opacity-70
(t :settings-page/git-commit-delay)]
[: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]
(let [value (-> (util/evalue event)
util/safe-parse-int)]
(if (and (number? value)
(< 0 value (inc 600)))
(do
(state/set-state! [:electron/user-cfgs :git/auto-commit-seconds] value)
(ipc/ipc :userAppCfgs :git/auto-commit-seconds value))
(when-let [elem (gobj/get event "target")]
(notification/show!
[:div "Invalid value! Must be a number between 1 and 600."]
:warning true)
(gobj/set elem "value" secs)))))}]]]]))
(rum/defc app-auto-update-row < rum/reactive [t]
(let [enabled? (state/sub [:electron/user-cfgs :auto-update])
enabled? (if (nil? enabled?) true enabled?)]
(toggle "usage-diagnostics"
(t :settings-page/auto-updater)
enabled?
#((state/set-state! [:electron/user-cfgs :auto-update] (not enabled?))
(ipc/ipc :userAppCfgs :auto-update (not enabled?))))))
(defn language-row [t preferred-language]
(let [on-change (fn [e]
(let [lang-code (util/evalue e)]
(state/set-preferred-language! lang-code)
(ui-handler/re-render-root!)))
action [:select.form-select.is-small {:value preferred-language
:on-change on-change}
(for [language dicts/languages]
(let [lang-code (name (:value language))
lang-label (:label language)]
[:option {:key lang-code :value lang-code} lang-label]))]]
(row-with-button-action {:left-label (t :language)
:-for "preferred_language"
:action action})))
(defn theme-modes-row [t switch-theme system-theme? dark?]
(let [color-accent (state/sub :ui/radix-color)
pick-theme [:ul.theme-modes-options
[:li {:on-click (partial state/use-theme-mode! "light")
:class (classnames [{:active (and (not system-theme?) (not dark?))}])} [:i.mode-light {:class (when color-accent "radix")}] [:strong (t :settings-page/theme-light)]]
[:li {:on-click (partial state/use-theme-mode! "dark")
:class (classnames [{:active (and (not system-theme?) dark?)}])} [:i.mode-dark {:class (when color-accent "radix")}] [:strong (t :settings-page/theme-dark)]]
[:li {:on-click (partial state/use-theme-mode! "system")
:class (classnames [{:active system-theme?}])} [:i.mode-system {:class (when color-accent "radix")}] [:strong (t :settings-page/theme-system)]]]]
(row-with-button-action {:left-label (t :right-side-bar/switch-theme (string/capitalize switch-theme))
:-for "toggle_theme"
:action pick-theme
:desc (ui/render-keyboard-shortcut (shortcut-helper/gen-shortcut-seq :ui/toggle-theme))})))
(defn accent-color-row []
(let [color-accent (state/sub :ui/radix-color)
pick-theme [:div.grid {:style {:grid-template-columns "repeat(5, 1fr)"
:gap "0.75rem"
:width "100%"
:max-width "16rem"}}
(for [color colors/color-list
:let [active? (= color color-accent)]]
[:div.flex.items-center {:style {:height 28}}
[:div {:class "w-5 h-5 rounded-full flex justify-center items-center transition ease-in duration-100 hover:cursor-pointer hover:opacity-100"
:style {:background-color (colors/variable color :09)
:outline-color (colors/variable color (if active? :07 :06))
:outline-width (if active? "4px" "1px")
:outline-style :solid
:opacity (if active? 1 0.5)}
:on-click (fn [_e] (state/set-color-accent! color))}
[:div {:class "w-2 h-2 rounded-full transition ease-in duration-100"
:style {:background-color (str "var(--rx-" (name color) "-07)")
:opacity (if active? 1 0)}}]]])
(when color-accent
[:div.col-span-5
(shui/button {:text "Back to default color"
:theme :gray
:on-click (fn [_e] (state/unset-color-accent!))}
(make-shui-context nil nil))])]]
[:<>
(row-with-button-action {:left-label "Accent color"
:description "Choosing an accent color will override any theme you have selected."
:-for "toggle_radix_theme"
:stretch true
:action pick-theme})]))
(defn file-format-row [t preferred-format]
[:div.it.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-center
[:label.block.text-sm.font-medium.leading-5.opacity-70
{:for "preferred_format"}
(t :settings-page/preferred-file-format)]
[:div.mt-1.sm:mt-0.sm:col-span-2
[:div.max-w-lg.rounded-md
[:select.form-select.is-small
{:value (name preferred-format)
:on-change (fn [e]
(let [format (-> (util/evalue e)
(string/lower-case)
keyword)]
(user-handler/set-preferred-format! format)))}
(for [format (map name [:org :markdown])]
[:option {:key format :value format} (string/capitalize format)])]]]])
(defn date-format-row [t preferred-date-format]
[:div.it.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-:div.it.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-center
[:label.block.text-sm.font-medium.leading-5.opacity-70
{:for "custom_date_format"}
(t :settings-page/custom-date-format)
(ui/tippy {:html (t :settings-page/custom-date-format-warning)
:class "tippy-hover ml-2"
:interactive true
:disabled false}
(svg/info))]
[:div.mt-1.sm:mt-0.sm:col-span-2
[:div.max-w-lg.rounded-md
[:select.form-select.is-small
{:value preferred-date-format
:on-change (fn [e]
(let [format (util/evalue e)]
(when-not (string/blank? format)
(config-handler/set-config! :journal/page-title-format format)
(notification/show!
[:div (t :settings-page/custom-date-format-notification)]
:warning false)
(state/close-modal!)
(route-handler/redirect! {:to :repos}))))}
(for [format (sort (date/journal-title-formatters))]
[:option {:key format} format])]]]])
(defn workflow-row [t preferred-workflow]
[:div.it.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-center
[:label.block.text-sm.font-medium.leading-5.opacity-70
{:for "preferred_workflow"}
(t :settings-page/preferred-workflow)]
[:div.mt-1.sm:mt-0.sm:col-span-2
[:div.max-w-lg.rounded-md
[:select.form-select.is-small
{:value (name preferred-workflow)
:on-change (fn [e]
(-> (util/evalue e)
string/lower-case
keyword
(#(if (= % :now) :now :todo))
user-handler/set-preferred-workflow!))}
(for [workflow [:now :todo]]
[:option {:key (name workflow) :value (name workflow)}
(if (= workflow :now) "NOW/LATER" "TODO/DOING")])]]]])
(defn outdenting-row [t logical-outdenting?]
(toggle "preferred_outdenting"
[(t :settings-page/preferred-outdenting)
(ui/tippy {:html (outdenting-hint)
:class "tippy-hover ml-2"
:interactive true
:disabled false}
(svg/info))]
logical-outdenting?
config-handler/toggle-logical-outdenting!))
(defn showing-full-blocks [t show-full-blocks?]
(toggle "show_full_blocks"
(t :settings-page/show-full-blocks)
show-full-blocks?
config-handler/toggle-show-full-blocks!))
(defn preferred-pasting-file [t preferred-pasting-file?]
(toggle "preferred_pasting_file"
[(t :settings-page/preferred-pasting-file)
(ui/tippy {:html (t :settings-page/preferred-pasting-file-hint)
:class "tippy-hover ml-2"
:interactive true
:disabled false}
(svg/info))]
preferred-pasting-file?
config-handler/toggle-preferred-pasting-file!))
(defn auto-expand-row [t auto-expand-block-refs?]
(toggle "auto_expand_block_refs"
[(t :settings-page/auto-expand-block-refs)
(ui/tippy {:html (auto-expand-hint)
:class "tippy-hover ml-2"
:interactive true
:disabled false}
(svg/info))]
auto-expand-block-refs?
config-handler/toggle-auto-expand-block-refs!))
(defn tooltip-row [t enable-tooltip?]
(toggle "enable_tooltip"
(t :settings-page/enable-tooltip)
enable-tooltip?
(fn []
(config-handler/toggle-ui-enable-tooltip!))))
(defn shortcut-tooltip-row [t enable-shortcut-tooltip?]
(toggle "enable_tooltip"
(t :settings-page/enable-shortcut-tooltip)
enable-shortcut-tooltip?
(fn []
(state/toggle-shortcut-tooltip!))))
(defn timetracking-row [t enable-timetracking?]
(toggle "enable_timetracking"
(t :settings-page/enable-timetracking)
enable-timetracking?
#(let [value (not enable-timetracking?)]
(config-handler/set-config! :feature/enable-timetracking? value))))
(defn update-home-page
[event]
(let [value (util/evalue event)]
(cond
(string/blank? value)
(let [home (get (state/get-config) :default-home {})
new-home (dissoc home :page)]
(config-handler/set-config! :default-home new-home)
(notification/show! "Home default page updated successfully!" :success))
(db/page-exists? value)
(let [home (get (state/get-config) :default-home {})
new-home (assoc home :page value)]
(config-handler/set-config! :default-home new-home)
(notification/show! "Home default page updated successfully!" :success))
:else
(notification/show! (str "The page \"" value "\" doesn't exist yet. Please create that page first, and then try again.") :warning))))
(defn journal-row [enable-journals?]
(toggle "enable_journals"
(t :settings-page/enable-journals)
enable-journals?
(fn []
(let [value (not enable-journals?)]
(config-handler/set-config! :feature/enable-journals? value)))))
(defn enable-all-pages-public-row [t enable-all-pages-public?]
(toggle "all pages public"
(t :settings-page/enable-all-pages-public)
enable-all-pages-public?
(fn []
(let [value (not enable-all-pages-public?)]
(config-handler/set-config! :publishing/all-pages-public? value)))))
;; (defn enable-block-timestamps-row [t enable-block-timestamps?]
;; (toggle "block timestamps"
;; (t :settings-page/enable-block-time)
;; enable-block-timestamps?
;; (fn []
;; (let [value (not enable-block-timestamps?)]
;; (config-handler/set-config! :feature/enable-block-timestamps? value)))))
(defn zotero-settings-row []
[:div.it.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-center
[:label.block.text-sm.font-medium.leading-5.opacity-70
{:for "zotero_settings"}
"Zotero"]
[:div.mt-1.sm:mt-0.sm:col-span-2
[:div
(ui/button
(t :settings)
:class "text-sm p-1"
:style {:margin-top "0px"}
:on-click
(fn []
(state/close-settings!)
(route-handler/redirect! {:to :zotero-setting})))]]])
(defn auto-push-row [_t current-repo enable-git-auto-push?]
(when (and current-repo (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))))))
(defn usage-diagnostics-row [t instrument-disabled?]
(toggle "usage-diagnostics"
(t :settings-page/disable-sentry)
(not instrument-disabled?)
(fn [] (instrument/disable-instrument
(not instrument-disabled?)))
[:span.text-sm.opacity-50 (t :settings-page/disable-sentry-desc)]))
(defn clear-cache-row [t]
(row-with-button-action {:left-label (t :settings-page/clear-cache)
:button-label (t :settings-page/clear)
:on-click handler/clear-cache!
:-for "clear_cache"}))
(defn version-row [t version]
(row-with-button-action {:left-label (t :settings-page/current-version)
:action (app-updater version)
:-for "current-version"}))
(defn developer-mode-row [t developer-mode?]
(toggle "developer_mode"
(t :settings-page/developer-mode)
developer-mode?
(fn []
(let [mode (not developer-mode?)]
(state/set-developer-mode! mode)))
[:div.text-sm.opacity-50 (t :settings-page/developer-mode-desc)]))
(rum/defc plugin-enabled-switcher
[t]
(let [value (state/lsp-enabled?-or-theme)
[on? set-on?] (rum/use-state value)
on-toggle #(let [v (not on?)]
(set-on? v)
(storage/set ::storage-spec/lsp-core-enabled v))]
[:div.flex.items-center.gap-2
(ui/toggle on? on-toggle true)
(when (not= (boolean value) on?)
(ui/button (t :plugin/restart)
:on-click #(js/logseq.api.relaunch)
:small? true :intent "logseq"))]))
(rum/defc http-server-enabled-switcher
[t]
(let [[value _] (rum/use-state (boolean (storage/get ::storage-spec/http-server-enabled)))
[on? set-on?] (rum/use-state value)
on-toggle #(let [v (not on?)]
(set-on? v)
(storage/set ::storage-spec/http-server-enabled v))]
[:div.flex.items-center.gap-2
(ui/toggle on? on-toggle true)
(when (not= (boolean value) on?)
(ui/button (t :plugin/restart)
:on-click #(js/logseq.api.relaunch)
:small? true :intent "logseq"))]))
(rum/defc flashcards-enabled-switcher
[enable-flashcards?]
(ui/toggle enable-flashcards?
(fn []
(let [value (not enable-flashcards?)]
(config-handler/set-config! :feature/enable-flashcards? value)))
true))
(rum/defc user-proxy-settings
[{:keys [type protocol host port] :as agent-opts}]
(ui/button [:span.flex.items-center
[:span.pr-1
(case type
"system" "System Default"
"direct" "Direct"
(and protocol host port (str protocol "://" host ":" port)))]
(ui/icon "edit")]
:class "text-sm p-1"
:on-click #(state/set-sub-modal!
(fn [_] (plugins/user-proxy-settings-panel agent-opts))
{:id :https-proxy-panel :center? true})))
(defn plugin-system-switcher-row []
(row-with-button-action
{:left-label (t :settings-page/plugin-system)
:action (plugin-enabled-switcher t)}))
(defn http-server-switcher-row []
(row-with-button-action
{:left-label "HTTP APIs server"
:action (http-server-enabled-switcher t)}))
(defn flashcards-switcher-row [enable-flashcards?]
(row-with-button-action
{:left-label (t :settings-page/enable-flashcards)
:action (flashcards-enabled-switcher enable-flashcards?)}))
(defn https-user-agent-row [agent-opts]
(row-with-button-action
{:left-label (t :settings-page/network-proxy)
:action (user-proxy-settings agent-opts)}))
(rum/defcs auto-chmod-row < rum/reactive
[state t]
(let [enabled? (if (= nil (state/sub [:electron/user-cfgs :feature/enable-automatic-chmod?]))
true
(state/sub [:electron/user-cfgs :feature/enable-automatic-chmod?]))]
(toggle
"automatic-chmod"
(t :settings-page/auto-chmod)
enabled?
#(do
(state/set-state! [:electron/user-cfgs :feature/enable-automatic-chmod?] (not enabled?))
(ipc/ipc :userAppCfgs :feature/enable-automatic-chmod? (not enabled?)))
[:span.text-sm.opacity-50 (t :settings-page/auto-chmod-desc)])))
(defn filename-format-row []
(row-with-button-action
{:left-label (t :settings-page/filename-format)
:button-label (t :settings-page/edit-setting)
:on-click #(state/set-sub-modal!
(fn [_] (conversion-component/files-breaking-changed))
{:id :filename-format-panel :center? true})}))
(rum/defcs native-titlebar-row < rum/reactive
[state t]
(let [enabled? (state/sub [:electron/user-cfgs :window/native-titlebar?])]
(toggle
"native-titlebar"
(t :settings-page/native-titlebar)
enabled?
#(when (js/confirm (t :relaunch-confirm-to-work))
(state/set-state! [:electron/user-cfgs :window/native-titlebar?] (not enabled?))
(ipc/ipc :userAppCfgs :window/native-titlebar? (not enabled?))
(js/logseq.api.relaunch))
[:span.text-sm.opacity-50 (t :settings-page/native-titlebar-desc)])))
(rum/defcs settings-general < rum/reactive
[_state current-repo]
(let [preferred-language (state/sub [:preferred-language])
theme (state/sub :ui/theme)
dark? (= "dark" theme)
show-radix-themes? true
system-theme? (state/sub :ui/system-theme?)
switch-theme (if dark? "light" "dark")]
[:div.panel-wrap.is-general
(version-row t version)
(language-row t preferred-language)
(theme-modes-row t switch-theme system-theme? dark?)
(when (and (util/electron?) (not util/mac?)) (native-titlebar-row t))
(when show-radix-themes? (accent-color-row))
(when (config/global-config-enabled?) (edit-global-config-edn))
(when current-repo (edit-config-edn))
(when current-repo (edit-custom-css))
(when current-repo (edit-export-css))]))
(rum/defcs settings-editor < rum/reactive
[_state current-repo]
(let [preferred-format (state/get-preferred-format)
preferred-date-format (state/get-date-formatter)
preferred-workflow (state/get-preferred-workflow)
enable-timetracking? (state/enable-timetracking?)
enable-all-pages-public? (state/all-pages-public?)
logical-outdenting? (state/logical-outdenting?)
show-full-blocks? (state/show-full-blocks?)
preferred-pasting-file? (state/preferred-pasting-file?)
auto-expand-block-refs? (state/auto-expand-block-refs?)
enable-tooltip? (state/enable-tooltip?)
enable-shortcut-tooltip? (state/sub :ui/shortcut-tooltip?)
show-brackets? (state/show-brackets?)
enable-git-auto-push? (state/enable-git-auto-push? current-repo)]
[:div.panel-wrap.is-editor
(file-format-row t preferred-format)
(date-format-row t preferred-date-format)
(workflow-row t preferred-workflow)
;; (enable-block-timestamps-row t enable-block-timestamps?)
(show-brackets-row t show-brackets?)
(when (util/electron?) (switch-spell-check-row t))
(outdenting-row t logical-outdenting?)
(showing-full-blocks t show-full-blocks?)
(preferred-pasting-file t preferred-pasting-file?)
(auto-expand-row t auto-expand-block-refs?)
(when-not (or (util/mobile?) (mobile-util/native-platform?))
(shortcut-tooltip-row t enable-shortcut-tooltip?))
(when-not (or (util/mobile?) (mobile-util/native-platform?))
(tooltip-row t enable-tooltip?))
(timetracking-row t enable-timetracking?)
(enable-all-pages-public-row t enable-all-pages-public?)
(auto-push-row t current-repo enable-git-auto-push?)]))
(rum/defc settings-git
[]
[:div.panel-wrap
[:div.text-sm.my-4
(ui/admonition
:tip
[:p (t :settings-page/git-tip)])
[:span.text-sm.opacity-50.my-4
(t :settings-page/git-desc-1)]
[:br][:br]
[:span.text-sm.opacity-50.my-4
(t :settings-page/git-desc-2)]
[:a {:href "https://git-scm.com/" :target "_blank"}
"Git"]
[:span.text-sm.opacity-50.my-4
(t :settings-page/git-desc-3)]]
[:br]
(switch-git-auto-commit-row t)
(git-auto-commit-seconds t)
(ui/admonition
:warning
[:p (t :settings-page/git-confirm)])])
(rum/defc settings-advanced < rum/reactive
[current-repo]
(let [instrument-disabled? (state/sub :instrument/disabled?)
developer-mode? (state/sub [:ui/developer-mode?])
https-agent-opts (state/sub [:electron/user-cfgs :settings/agent])]
[:div.panel-wrap.is-advanced
(when (and (or util/mac? util/win32?) (util/electron?)) (app-auto-update-row t))
(usage-diagnostics-row t instrument-disabled?)
(when-not (mobile-util/native-platform?) (developer-mode-row t developer-mode?))
(when (util/electron?) (https-user-agent-row https-agent-opts))
(when (util/electron?) (auto-chmod-row t))
(when (and (util/electron?) (not (config/demo-graph? current-repo))) (filename-format-row))
(clear-cache-row t)
(ui/admonition
:warning
[:p (t :settings-page/clear-cache-warning)])]))
(rum/defc sync-enabled-switcher
[enabled?]
(ui/toggle enabled?
(fn []
(file-sync-handler/set-sync-enabled! (not enabled?)))
true))
(rum/defc sync-diff-merge-enabled-switcher
[enabled?]
(ui/toggle enabled?
(fn []
(file-sync-handler/set-sync-diff-merge-enabled! (not enabled?)))
true))
(defn sync-switcher-row [enabled?]
(row-with-button-action
{:left-label (t :settings-page/sync)
:action (sync-enabled-switcher enabled?)}))
(defn sync-diff-merge-switcher-row [enabled?]
(row-with-button-action
{:left-label (str (t :settings-page/sync-diff-merge) " (Experimental!)") ;; Not included in i18n to avoid outdating translations
:action (sync-diff-merge-enabled-switcher enabled?)
:desc (ui/tippy {:html [:div
[:div (t :settings-page/sync-diff-merge-desc)]
[:div (t :settings-page/sync-diff-merge-warn)]]
:class "tippy-hover ml-2"
:interactive true
:disabled false}
(svg/info))}))
(rum/defc whiteboards-enabled-switcher
[enabled?]
(ui/toggle enabled?
(fn []
(let [value (not enabled?)]
(config-handler/set-config! :feature/enable-whiteboards? value)))
true))
(defn whiteboards-switcher-row [enabled?]
(row-with-button-action
{:left-label (t :settings-page/enable-whiteboards)
:action (whiteboards-enabled-switcher enabled?)}))
(rum/defc settings-account-usage-description [pro-account? graph-usage]
(let [count-usage (count graph-usage)
count-limit (if pro-account? 10 1)
count-percent (js/Math.round (/ count-usage count-limit 0.01))
storage-usage (->> (map :used-gbs graph-usage)
(reduce + 0))
storage-usage-formatted (cond
(zero? storage-usage) "0.0"
(< storage-usage 0.01) "Less than 0.01"
:else (gstring/format "%.2f" storage-usage))
;; TODO: check logic on this. What are the rules around storage limits?
;; do we, and should we be able to, give individual users more storage?
;; should that be on a per graph or per user basis?
default-storage-limit (if pro-account? 10 0.05)
storage-limit (->> (range 0 count-limit)
(map #(get-in graph-usage [% :limit-gbs] default-storage-limit))
(reduce + 0))
storage-percent (/ storage-usage storage-limit 0.01)
storage-percent-formatted (gstring/format "%.1f" storage-percent)]
[:div.text-sm
(when pro-account?
[:<>
(gstring/format "%s of %s synced graphs " count-usage count-limit)
[:strong.text-white (gstring/format "(%s%%)" count-percent)]
", "])
(gstring/format "%sGB of %sGB total storage " storage-usage-formatted storage-limit)
[:strong.text-white (gstring/format "(%s%%)" storage-percent-formatted)]]))
; storage-usage-formatted "GB of " storage-limit "GB total storage"
; [:strong.text-white " (" storage-percent-formatted "%)"]]))
(rum/defc settings-account-usage-graphs [_pro-account? graph-usage]
(when (< 0 (count graph-usage))
[:div.grid.gap-3 {:style {:grid-template-columns (str "repeat(" (count graph-usage) ", 1fr)")}}
(for [{:keys [name used-percent]} graph-usage
:let [color (if (<= 100 used-percent) "bg-red-500" "bg-blue-500")]]
[:div.rounded-full.w-full.h-2 {:class "bg-black/50"
:tooltip name}
[:div.rounded-full.h-2 {:class color
:style {:width (str used-percent "%")
:min-width "0.5rem"
:max-width "100%"}}]])]))
(rum/defc ^:large-vars/cleanup-todo settings-account < rum/reactive
[]
(let [current-graph-uuid (state/sub-current-file-sync-graph-uuid)
graph-usage (state/get-remote-graph-usage)
current-graph-is-remote? ((set (map :uuid graph-usage)) current-graph-uuid)
logged-in? (user-handler/logged-in?)
user-info (state/get-user-info)
paid-user? (#{"active" "on_trial" "cancelled"} (:LemonStatus user-info))
gift-user? (some #{"pro"} (:UserGroups user-info))
pro-account? (or paid-user? gift-user?)
expiration-date (some-> user-info :LemonEndsAt date/parse-iso)
renewal-date (some-> user-info :LemonRenewsAt date/parse-iso)
has-subscribed? (some? (:LemonStatus user-info))]
[:div.panel-wrap.is-features.mb-8
[:div.mt-1.sm:mt-0.sm:col-span-2
(cond
logged-in?
[:div.grid.grid-cols-3.gap-8.pt-2
[:div "Current plan"]
[:div.col-span-2
[:div {:class "w-full bg-gray-500/10 rounded-lg p-4 flex flex-col gap-4"}
[:div.flex.gap-4.items-center
(if pro-account?
[:div.flex-1 "Pro"]
[:div.flex-1 "Free"])
(cond
has-subscribed?
(ui/button "Manage plan" {:class "p-1 h-8 justify-center"
:disabled true
:icon "upload"})
; :on-click user-handler/upgrade})
(not pro-account?)
(ui/button "Upgrade plan" {:class "p-1 h-8 justify-center"
:icon "upload"
:on-click user-handler/upgrade})
:else nil)]
(settings-account-usage-graphs pro-account? graph-usage)
(settings-account-usage-description pro-account? graph-usage)
(if current-graph-is-remote?
(ui/button "Deactivate syncing" {:class "p-1 h-8 justify-center"
:disabled true
:background "gray"
:icon "cloud-off"})
(ui/button "Activate syncing" {:class "p-1 h-8 justify-center"
:background "blue"
:icon "cloud"
:on-click #(fs/maybe-onboarding-show :sync-initiate)}))]]
(when has-subscribed?
[:<>
[:div "Billing"]
[:div.col-span-2.flex.flex-col.gap-4
(cond
;; If there is no expiration date, print the renewal date
(and renewal-date (nil? expiration-date))
[:div
[:strong.font-semibold "Next billing date: "
(date/get-locale-string renewal-date)]]
;; If the expiration date is in the future, word it as such
(< (js/Date.) expiration-date)
[:div
[:strong.font-semibold "Pro plan expires on: "
(date/get-locale-string expiration-date)]]
;; Otherwise, ind
:else
[:div
[:strong.font-semibold "Pro plan expired on: "
(date/get-locale-string expiration-date)]])
[:div (ui/button "Open invoices" {:class "w-full h-8 p-1 justify-center"
:disabled true
:background "gray"
:icon "receipt"})]]])
[:div "Profile"]
[:div.col-span-2.grid.grid-cols-2.gap-4
[:div.flex.flex-col.gap-2.box-border {:class "basis-1/2"}
[:label.text-sm.font-semibold "First name"]
[:input.rounded.border.px-2.py-1.box-border {:class "border-blue-500 bg-black/25 w-full"}]]
[:div.flex.flex-col.gap-2 {:class "basis-1/2"}
[:label.text-sm.font-semibold "Last name"]
[:input.rounded.border.px-2.py-1.box-border {:class "border-blue-500 bg-black/25 w-full"}]]
[:div.flex-1.flex.flex-col.gap-2.col-span-2
[:label.text-sm.font-semibold "Username"]
[:input.rounded.border.px-2.py-1.box-border {:class "border-blue-500 bg-black/25"
:value (user-handler/email)}]]]
[:div "Authentication"]
[:div.col-span-2
[:div.grid.grid-cols-2.gap-4
[:div (ui/button (t :logout) {:class "p-1 h-8 justify-center w-full"
:background "gray"
:icon "logout"
:on-click user-handler/logout})]
[:div (ui/button "Reset password" {:class "p-1 h-8 justify-center w-full"
:disabled true
:background "gray"
:icon "key"
:on-click user-handler/logout})]
[:div.col-span-2 (ui/button "Delete Account" {:class "p-1 h-8 justify-center w-full"
:disabled true
:background "red"})]]]]
(not logged-in?)
[:div.grid.grid-cols-3.gap-8.pt-2
[:div "Authentication"]
[:div.col-span-2.flex.flex-wrap.gap-4
[:div.w-full.text-white "With a Logseq account, you can access cloud-based services like Logseq Sync and alpha/beta features."]
[:div.flex-1 (ui/button "Sign up" {:class "h-8 w-full text-center justify-center"
:on-click (fn []
(state/close-settings!)
(state/pub-event! [:user/login]))})]
[:div.flex-1 (ui/button (t :login) {:icon "login"
:class "h-8 w-full text-center justify-center"
:background "gray"
:on-click (fn []
(state/close-settings!)
(state/pub-event! [:user/login]))})]]
[:div.col-span-3.flex.flex-col.gap-4 {:class "bg-black/20 p-4 rounded-lg"}
[:div.flex.w-full.items-center
[:div {:class "w-1/2 text-lg"}
"Discover the power of "
[:strong {:class "text-white/80"} "Logseq Sync"]]
[:div {:class "w-1/2 bg-gradient-to-r from-white/10 to-transparent p-3 rounded-lg flex items-center gap-2 px-5 ml-5"}
[:div.w-3.h-3.rounded-full.bg-green-500]
"Synced"]]
[:div.flex.w-full.gap-4
[:div {:class "w-1/2 bg-black/50 rounded-lg p-4 pt-10 relative flex flex-col gap-4"}
[:div.absolute.top-0.left-4.bg-gray-700.uppercase.px-2.py-1.rounded-b-lg.font-bold.text-xs "Free"]
[:div
[:strong.text-white.text-xl.font-normal "$0"]]
[:div.text-white.font-bold {:class "h-[2.5rem] "} "Get started with basic syncing"]
[:ul.text-xs.list-none.m-0.flex.flex-col.gap-0.5
[:li "Unlimited unsynced graphs"]
[:li "1 synced graph (up to 50MB, notes only)"]
[:li "No asset syncing"]
[:li "Access to core Logseq features"]]]
[:div {:class "w-1/2 bg-black/50 rounded-lg p-4 pt-10 relative flex flex-col gap-4"}
[:div.absolute.top-0.left-4.bg-blue-700.uppercase.px-2.py-1.rounded-b-lg.font-bold.text-xs "Pro"]
[:div
[:strong.text-white.text-xl.font-normal "$10"]
[:span.text-xs.font-base {:class "ml-0.5"} "/ month"]]
[:div.text-white.font-bold {:class "h-[2.5rem]"} "Unlock advanced syncing and more"]
[:ul.text-xs.list-none.m-0.flex.flex-col.gap-0.5
[:li "Unlimited unsynced graphs"]
[:li "10 synced graphs (up to 5GB each)"]