Skip to content

Commit

Permalink
fix: graph unlink is not executed on all the windows
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Dec 21, 2021
1 parent 96b9ccb commit 94a4011
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/electron/electron/handler.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@
(defmethod handle :quitAndInstall []
(.quitAndInstall autoUpdater))

(defmethod handle :graphUnlinked [^js win [_ repo]]
(doseq [window (win/get-all-windows)]
(utils/send-to-renderer window "graphUnlinked" (bean/->clj repo))))

(defmethod handle :default [args]
(println "Error: no ipc handler for: " (bean/->js args)))

Expand Down
10 changes: 6 additions & 4 deletions src/electron/electron/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
(.getFocusedWindow BrowserWindow))

(defn send-to-renderer
[kind payload]
(when-let [window (get-focused-window)]
(.. ^js window -webContents
(send kind (bean/->js payload)))))
([kind payload]
(send-to-renderer (get-focused-window) kind payload))
([window kind payload]
(when window
(.. ^js window -webContents
(send kind (bean/->js payload))))))
6 changes: 6 additions & 0 deletions src/main/electron/listener.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[electron.ipc :as ipc]
[frontend.handler.notification :as notification]
[frontend.handler.metadata :as metadata-handler]
[frontend.handler.repo :as repo-handler]
[frontend.ui :as ui]
[frontend.db.persist :as db-persist]))

Expand Down Expand Up @@ -59,6 +60,11 @@
comp [:div (str payload)]]
(notification/show! comp type false))))

(js/window.apis.on "graphUnlinked"
(fn [data]
(let [repo (bean/->clj data)]
(repo-handler/remove-repo! repo))))

(js/window.apis.on "setGitUsernameAndEmail"
(fn []
(state/pub-event! [:modal/set-git-username-and-email])))
Expand Down
13 changes: 8 additions & 5 deletions src/main/frontend/handler/repo.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
[shadow.resource :as rc]
[clojure.set :as set]
[frontend.mobile.util :as mobile]
[frontend.db.persist :as db-persist]))
[frontend.db.persist :as db-persist]
[electron.ipc :as ipc]))

;; Project settings should be checked in two situations:
;; 1. User changes the config.edn directly in logseq.com (fn: alter-file)
Expand Down Expand Up @@ -537,10 +538,12 @@
[{:keys [id url] :as repo}]
;; (spec/validate :repos/repo repo)
(let [delete-db-f (fn []
(db/remove-conn! url)
(db-persist/delete-graph! url)
(search/remove-db! url)
(state/delete-repo! repo))]
(let [graph-exists? (db/get-conn url)]
(db/remove-conn! url)
(db-persist/delete-graph! url)
(search/remove-db! url)
(state/delete-repo! repo)
(when graph-exists? (ipc/ipc "graphUnlinked" repo))))]
(if (or (config/local-db? url) (= url "local"))
(p/let [_ (idb/clear-local-db! url)] ; clear file handles
(delete-db-f))
Expand Down

0 comments on commit 94a4011

Please sign in to comment.