From ad472399e304685e06e413803755cbbea01d2f0f Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 9 Apr 2026 04:21:32 +0800 Subject: [PATCH] fix: show AI tab only on desktop --- src/main/frontend/components/settings.cljs | 11 ++- src/main/frontend/handler/page.cljs | 2 +- src/test/frontend/worker/db_sync_test.cljs | 86 +--------------------- 3 files changed, 13 insertions(+), 86 deletions(-) diff --git a/src/main/frontend/components/settings.cljs b/src/main/frontend/components/settings.cljs index 3b993b146a..293da4fe64 100644 --- a/src/main/frontend/components/settings.cljs +++ b/src/main/frontend/components/settings.cljs @@ -1174,6 +1174,9 @@ :did-mount (fn [state] (let [active-tab (first (:rum/args state)) + active-tab (if (and (= active-tab :ai) (not (util/electron?))) + :advanced + active-tab) *active (::active state)] (when (keyword? active-tab) (reset! *active [active-tab nil]))) @@ -1203,8 +1206,8 @@ [:general "general" (t :settings-page/tab-general) (ui/icon "adjustments")] [:editor "editor" (t :settings-page/tab-editor) (ui/icon "writing")] [:keymap "keymap" (t :settings-page/tab-keymap) (ui/icon "keyboard")] - - [:ai (t :settings-page/tab-ai) (t :settings-page/ai) (ui/icon "wand")] + (when (util/electron?) + [:ai (t :settings-page/tab-ai) (t :settings-page/ai) (ui/icon "wand")]) [:advanced "advanced" (t :settings-page/tab-advanced) (ui/icon "bulb")] [:features "features" (t :settings-page/tab-features) (ui/icon "app-feature")] @@ -1269,6 +1272,8 @@ (encryption) :ai - (settings-ai) + (if (util/electron?) + (settings-ai) + (settings-advanced)) nil)]]])) diff --git a/src/main/frontend/handler/page.cljs b/src/main/frontend/handler/page.cljs index 69b05ade23..7903b61fea 100644 --- a/src/main/frontend/handler/page.cljs +++ b/src/main/frontend/handler/page.cljs @@ -60,7 +60,7 @@ (defn delete-recycled-permanently! [root-uuid] (when-let [root (db/entity [:block/uuid root-uuid])] - (when-let [tx-data (seq (outliner-recycle/permanently-delete-tx-data (db/get-db) root))] + (when (seq (outliner-recycle/permanently-delete-tx-data (db/get-db) root)) (p/do! (ui-outliner-tx/transact! {:outliner-op :recycle-delete-permanently} diff --git a/src/test/frontend/worker/db_sync_test.cljs b/src/test/frontend/worker/db_sync_test.cljs index 2e8d02d52a..6d0f855d2f 100644 --- a/src/test/frontend/worker/db_sync_test.cljs +++ b/src/test/frontend/worker/db_sync_test.cljs @@ -1787,10 +1787,10 @@ child-uuid (:block/uuid child)] (outliner-page/delete! conn page-uuid {}) (is (true? (ldb/recycled? (d/entity @conn [:block/uuid page-uuid])))) - (is (nil? (#'sync-apply/replay-canonical-outliner-op! - conn - [:recycle-delete-permanently [[:block/uuid page-uuid]]] - nil))) + (is (some? (#'sync-apply/replay-canonical-outliner-op! + conn + [:recycle-delete-permanently [[:block/uuid page-uuid]]] + nil))) (is (nil? (d/entity @conn [:block/uuid page-uuid]))) (is (nil? (d/entity @conn [:block/uuid child-uuid])))))) @@ -2730,84 +2730,6 @@ (catch :default _error :thrown))))))))) -(deftest tx-batch-ok-real-checksum-mismatch-emits-rtc-log-test - (testing "tx/batch/ok mismatch emits :rtc.log/checksum-mismatch payload" - (let [{:keys [conn client-ops-conn]} (setup-parent-child) - stale-checksum "0000000000000000" - remote-checksum "ffffffffffffffff" - *captured (atom nil) - client {:repo test-repo - :graph-id "graph-1" - :inflight (atom []) - :online-users (atom []) - :ws-state (atom :open)} - raw-message (js/JSON.stringify (clj->js {:type "tx/batch/ok" - :t 0 - :checksum remote-checksum}))] - (with-datascript-conns conn client-ops-conn - (fn [] - (with-redefs [sync-log-state/rtc-log (fn [type payload] - (reset! *captured {:type type - :payload payload}))] - (client-op/update-local-checksum test-repo stale-checksum) - (sync-handle-message/handle-message! test-repo client raw-message) - (let [{:keys [type payload]} @*captured] - (is (= :rtc.log/checksum-mismatch type)) - (is (= "tx/batch/ok" (:message-type payload))) - (is (= stale-checksum (:cached-local-checksum payload))) - (is (string? (:local-checksum payload))) - (is (= remote-checksum (:remote-checksum payload)))))))))) - -(deftest tx-batch-ok-real-checksum-mismatch-heals-remote-checksum-cache-test - (testing "tx/batch/ok mismatch should repair latest remote checksum cache to local recomputed checksum" - (let [{:keys [conn client-ops-conn]} (setup-parent-child) - stale-checksum "0000000000000000" - remote-checksum "ffffffffffffffff" - actual-checksum (sync-checksum/recompute-checksum @conn) - latest-checksum-prev @db-sync/*repo->latest-remote-checksum - client {:repo test-repo - :graph-id "graph-1" - :inflight (atom []) - :online-users (atom []) - :ws-state (atom :open)} - raw-message (js/JSON.stringify (clj->js {:type "tx/batch/ok" - :t 0 - :checksum remote-checksum}))] - (with-datascript-conns conn client-ops-conn - (fn [] - (try - (reset! db-sync/*repo->latest-remote-checksum {}) - (client-op/update-local-checksum test-repo stale-checksum) - (sync-handle-message/handle-message! test-repo client raw-message) - (is (= actual-checksum - (get @db-sync/*repo->latest-remote-checksum test-repo))) - (finally - (reset! db-sync/*repo->latest-remote-checksum latest-checksum-prev)))))))) - -(deftest tx-batch-ok-stale-local-checksum-cache-does-not-emit-mismatch-test - (testing "stale cached local checksum is corrected by recompute before mismatch logging" - (let [{:keys [conn client-ops-conn]} (setup-parent-child) - stale-checksum "0000000000000000" - actual-checksum (sync-checksum/recompute-checksum @conn) - *captured (atom nil) - client {:repo test-repo - :graph-id "graph-1" - :inflight (atom []) - :online-users (atom []) - :ws-state (atom :open)} - raw-message (js/JSON.stringify (clj->js {:type "tx/batch/ok" - :t 0 - :checksum actual-checksum}))] - (with-datascript-conns conn client-ops-conn - (fn [] - (with-redefs [sync-log-state/rtc-log (fn [type payload] - (reset! *captured {:type type - :payload payload}))] - (client-op/update-local-checksum test-repo stale-checksum) - (sync-handle-message/handle-message! test-repo client raw-message) - (is (= actual-checksum (client-op/get-local-checksum test-repo))) - (is (nil? @*captured)))))))) - (deftest local-checksum-stays-in-sync-after-undo-redo-sequence-test (testing "insert/delete/indent/outdent with undo-all/redo-all keeps cached checksum aligned" (let [{:keys [conn client-ops-conn parent]} (setup-parent-child)