Browse Source

feat(multiple-windows): ensure backward compatibility

Tienson Qin 4 years ago
parent
commit
a09ece4b0a

+ 10 - 0
src/electron/electron/core.cljs

@@ -219,6 +219,14 @@
                                           :secure          true
                                           :bypassCSP       true
                                           :supportFetchAPI true}}]))
+
+      (.on app "second-instance"
+           (fn [_event _commandLine _workingDirectory]
+             (when-let [win @*win]
+               (when (.isMinimized ^object win)
+                 (.restore win))
+               (.focus win))))
+
       (.on app "window-all-closed" (fn []
                                      (try
                                        (fs-watcher/close-watcher!)
@@ -276,6 +284,8 @@
                                                     (.setFullScreen win false))
                                                 (.hide win)))))))))
 
+               (.on app "before-quit" (fn [_e] (reset! *quitting? true)))
+
                (.on app "activate" #(if @*win (.show win)))))))))
 
 (defn start []

+ 2 - 1
src/electron/electron/handler.cljs

@@ -194,7 +194,8 @@
   [graph-name]
   (when graph-name
     (when-let [file-path (get-graph-path graph-name)]
-      (utils/read-file file-path))))
+      (when (fs/existsSync file-path)
+        (utils/read-file file-path)))))
 
 (defmethod handle :getSerializedGraph [window [_ graph-name]]
   (get-serialized-graph graph-name))

+ 18 - 5
src/main/frontend/db/persist.cljs

@@ -2,6 +2,7 @@
   (:require [frontend.util :as util]
             [frontend.mobile.util :as mobile]
             [frontend.idb :as idb]
+            [frontend.config :as config]
             [electron.ipc :as ipc]
             [frontend.db.conn :as db-conn]
             [promesa.core :as p]))
@@ -9,25 +10,37 @@
 (defn get-all-graphs
   []
   (if (util/electron?)
-    (p/let [result (ipc/ipc "getGraphs")]
-      (vec result))
+    (p/let [result (ipc/ipc "getGraphs")
+            result (vec result)
+            ;; backward compatibility (release <= 0.5.4)
+            result (if (seq result) result (idb/get-nfs-dbs))]
+      result)
     (idb/get-nfs-dbs)))
 
 (defn get-serialized-graph
   [graph-name]
   (if (util/electron?)
-    (ipc/ipc "getSerializedGraph" graph-name)
+    (p/let [result (ipc/ipc "getSerializedGraph" graph-name)
+            result (if result result
+                       (let [graph-name (str config/idb-db-prefix graph-name)]
+                         (idb/get-item graph-name)))]
+      result)
     (idb/get-item graph-name)))
 
 (defn save-graph!
   [key value]
   (if (util/electron?)
-    (ipc/ipc "saveGraph" key value)
+    (do
+      (ipc/ipc "saveGraph" key value)
+      ;; remove cache before 0.5.5
+      (idb/remove-item! key))
     (idb/set-batch! [{:key key :value value}])))
 
 (defn delete-graph!
   [graph]
   (let [key (db-conn/datascript-db graph)]
     (if (util/electron?)
-     (ipc/ipc "deleteGraph" key)
+      (do
+        (ipc/ipc "deleteGraph" key)
+        (idb/remove-item! key))
      (idb/remove-item! key))))