remove re-index from db-only version

This commit is contained in:
Tienson Qin
2023-05-22 13:11:21 +08:00
parent df11ccc17a
commit 17e8ef2308
4 changed files with 50 additions and 39 deletions

View File

@@ -172,9 +172,9 @@
reindex-link {:title (t :re-index)
:hover-detail (t :re-index-detail)
:options (cond->
{:on-click
(fn []
(state/pub-event! [:graph/ask-for-re-index *multiple-windows? nil]))})}
{:on-click
(fn []
(state/pub-event! [:graph/ask-for-re-index *multiple-windows? nil]))})}
new-window-link (when (and (util/electron?)
;; New Window button in menu bar of macOS is available.
(not util/mac?))
@@ -190,7 +190,8 @@
:options {:on-click #(state/pub-event! [:graph/new-db-graph])}}
{:title (t :all-graphs) :options {:href (rfe/href :repos)}}
refresh-link
reindex-link
(when-not (config/db-only? current-repo)
reindex-link)
new-window-link])
(remove nil?))))

View File

@@ -361,6 +361,11 @@
(and (string? s)
(string/starts-with? s local-db-prefix)))
(defn db-only?
[s]
(and (string? s)
(string/starts-with? s db-version-prefix)))
(defn get-local-asset-absolute-path
[s]
(str "/" (string/replace s #"^[./]*" "")))
@@ -382,6 +387,9 @@
(js/console.error "BUG: nil repo")
nil)
(db-only? repo-url)
nil
(and (util/electron?) (local-db? repo-url))
(get-local-dir repo-url)

View File

@@ -387,7 +387,8 @@
;; FIXME: an ugly implementation for redirecting to page on new window is restored
(repo-handler/graph-ready! repo)
;; Replace initial fs watcher
(fs-watcher/load-graph-files! repo)
(when-not (config/db-only? repo)
(fs-watcher/load-graph-files! repo))
;; TODO(junyi): Notify user to update filename format when the UX is smooth enough
;; (when-not config/test?
;; (js/setTimeout

View File

@@ -136,40 +136,41 @@
(defn exec-js-if-exists-&-allowed!
[t]
(when-let [href (or
(state/get-custom-js-link)
(config/get-custom-js-path))]
(let [k (str "ls-js-allowed-" href)
execed #(swap! *js-execed conj href)
execed? (contains? @*js-execed href)
ask-allow #(let [r (js/confirm (t :plugin/custom-js-alert))]
(if r
(storage/set k (js/Date.now))
(storage/set k false))
r)
allowed! (storage/get k)
should-ask? (or (nil? allowed!)
(> (- (js/Date.now) allowed!) 604800000))]
(when (and (not execed?)
(not= false allowed!))
(if (string/starts-with? href "http")
(when (or (not should-ask?)
(ask-allow))
(load href #(do (js/console.log "[custom js]" href) (execed))))
(let [repo-dir (config/get-repo-dir (state/get-current-repo))
rpath (path/relative-path repo-dir href)]
(p/let [exists? (fs/file-exists? repo-dir rpath)]
(when exists?
(util/p-handle
(fs/read-file repo-dir rpath)
#(when-let [scripts (and % (string/trim %))]
(when-not (string/blank? scripts)
(when (or (not should-ask?) (ask-allow))
(try
(js/eval scripts)
(execed)
(catch :default e
(js/console.error "[custom js]" e)))))))))))))))
(when-not (config/db-only? (state/get-current-repo))
(when-let [href (or
(state/get-custom-js-link)
(config/get-custom-js-path))]
(let [k (str "ls-js-allowed-" href)
execed #(swap! *js-execed conj href)
execed? (contains? @*js-execed href)
ask-allow #(let [r (js/confirm (t :plugin/custom-js-alert))]
(if r
(storage/set k (js/Date.now))
(storage/set k false))
r)
allowed! (storage/get k)
should-ask? (or (nil? allowed!)
(> (- (js/Date.now) allowed!) 604800000))]
(when (and (not execed?)
(not= false allowed!))
(if (string/starts-with? href "http")
(when (or (not should-ask?)
(ask-allow))
(load href #(do (js/console.log "[custom js]" href) (execed))))
(let [repo-dir (config/get-repo-dir (state/get-current-repo))
rpath (path/relative-path repo-dir href)]
(p/let [exists? (fs/file-exists? repo-dir rpath)]
(when exists?
(util/p-handle
(fs/read-file repo-dir rpath)
#(when-let [scripts (and % (string/trim %))]
(when-not (string/blank? scripts)
(when (or (not should-ask?) (ask-allow))
(try
(js/eval scripts)
(execed)
(catch :default e
(js/console.error "[custom js]" e))))))))))))))))
(defn toggle-wide-mode!
[]