Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/electron/electron/handler.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,15 @@
(async/put! state/persistent-dbs-chan true)
true)

;; The renderer sends this when frontend.db/persist! rejected. Without a method here
;; it fell through to :default, electron.window/close-handler stayed parked on
;; persistent-dbs-chan forever, and the window could never be closed again. Unblock the
;; close: the markdown files are the source of truth, the transit file is only a cache.
(defmethod handle :persistent-dbs-error [_window _]
(logger/error "Failed to persist the graph cache. Closing anyway - your files on disk are unaffected, but the next startup will re-index.")
(async/put! state/persistent-dbs-chan true)
true)

;; Search related IPCs
(defmethod handle :search-blocks [_window [_ repo q opts]]
(search/search-blocks repo q opts))
Expand Down Expand Up @@ -691,8 +700,11 @@
(defmethod handle :cancel-all-requests [_ args]
(apply rsapi/cancel-all-requests (rest args)))

(defmethod handle :default [args]
(logger/error "Error: no ipc handler for:" args))
;; `handle` is dispatched with two arguments, so a one-argument :default threw an arity
;; exception instead of logging -- and the exception was swallowed by set-ipc-handler!,
;; hiding the unhandled channel entirely. Log the channel name rather than the window.
(defmethod handle :default [_window args]
(logger/error "Error: no ipc handler for:" (first args)))

(defn broadcast-persist-graph!
"Receive graph-name (not graph path)
Expand Down
21 changes: 16 additions & 5 deletions src/electron/electron/window.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

(defonce *quitting? (atom false))

(def ^:private persist-dbs-timeout-ms
"How long close-handler waits for the renderer to confirm the graph cache was saved
before closing the window regardless. Generous enough for a large graph to serialize,
short enough that a user never faces a window that simply refuses to close."
10000)

(def MAIN_WINDOW_ENTRY (if dev?
;"http://localhost:3001"
(str "file://" (node-path/join js/__dirname "index.html"))
Expand Down Expand Up @@ -89,12 +95,17 @@
(.send web-contents "persist-zoom-level" (.getZoomLevel web-contents))
(.send web-contents "persistent-dbs"))
(async/go
(let [_ (async/<! state/persistent-dbs-chan)]
;; This runs after (.preventDefault e), so the window is already committed to not
;; closing on its own. A bare <! here means any renderer that never answers -- because
;; the save threw, or the renderer is wedged -- leaves the window permanently
;; unclosable, with no message to the user. Time the wait out and close regardless:
;; the graph's files on disk are the source of truth, the transit blob is a cache.
(let [timeout-ch (async/timeout persist-dbs-timeout-ms)
[_ port] (async/alts! [state/persistent-dbs-chan timeout-ch])]
(when (identical? port timeout-ch)
(logger/error "Timed out after" persist-dbs-timeout-ms
"ms waiting for the graph cache to be saved. Closing the window anyway; the next startup will re-index."))
(destroy-window! win)
;; (if @*quitting?
;; (doseq [win (get-all-windows)]
;; (destroy-window! win))
;; (destroy-window! win))
(when @*quitting?
(async/put! state/persistent-dbs-chan true)))))

Expand Down
Loading