Parcourir la source

feat: add error alert for keyboard conflict

Weihua Lu il y a 4 ans
Parent
commit
f9d2af770a
1 fichiers modifiés avec 11 ajouts et 5 suppressions
  1. 11 5
      src/main/frontend/modules/shortcut/core.cljs

+ 11 - 5
src/main/frontend/modules/shortcut/core.cljs

@@ -1,14 +1,14 @@
 (ns frontend.modules.shortcut.core
   (:require [clojure.string :as str]
-            [frontend.state :as state]
-            [frontend.util :as util]
+            [frontend.handler.notification :as notification]
             [frontend.modules.shortcut.data-helper :as dh]
+            [frontend.util :as util]
             [goog.events :as events]
             [goog.ui.KeyboardShortcutHandler.EventType :as EventType]
             [lambdaisland.glogi :as log]
             [medley.core :as medley])
-  (:import [goog.ui KeyboardShortcutHandler]
-           [goog.events KeyCodes]))
+  (:import [goog.events KeyCodes]
+           [goog.ui KeyboardShortcutHandler]))
 
 (def *installed (atom {}))
 
@@ -35,7 +35,13 @@
     (doseq [[id _] shortcut-map]
       ;; (log/info :shortcut/install-shortcut {:id id :shortcut (dh/shortcut-binding id)})
       (doseq [k (dh/shortcut-binding id)]
-        (.registerShortcut handler (util/keyname id) k)))
+        (try
+          (.registerShortcut handler (util/keyname id) k)
+          (catch js/Object e
+            (log/error :shortcut/register-shortcut {:id id
+                                                    :binding k
+                                                    :error e})
+            (notification/show! (str/join " " [id k (.-message e)]) :error)))))
 
     (let [f (fn [e]
               (let [dispatch-fn (get shortcut-map (keyword (.-identifier e)))]