mirror of
https://github.com/logseq/logseq.git
synced 2026-05-18 01:42:19 +00:00
fix: notify when no microphone permission
This commit is contained in:
26
src/main/frontend/mobile/audio_recorder.cljs
Normal file
26
src/main/frontend/mobile/audio_recorder.cljs
Normal file
@@ -0,0 +1,26 @@
|
||||
(ns frontend.mobile.audio-recorder
|
||||
(:require [clojure.string :as string]
|
||||
[frontend.handler.notification :as notification]
|
||||
[lambdaisland.glogi :as log]
|
||||
[logseq.shui.ui :as shui]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(defn- microphone-permission-denied-error?
|
||||
[error]
|
||||
(let [message (some-> error str string/lower-case)]
|
||||
(and (string/includes? message "microphone")
|
||||
(or (string/includes? message "denied")
|
||||
(string/includes? message "not authorized")
|
||||
(string/includes? message "permission")))))
|
||||
|
||||
(defn start-recording!
|
||||
[recorder]
|
||||
(-> (.startRecording ^js recorder)
|
||||
(p/catch (fn [error]
|
||||
(log/error :audio/record-start-failed {:error error})
|
||||
(when (microphone-permission-denied-error? error)
|
||||
(notification/show!
|
||||
"Microphone access is denied. Enable it in Settings > Logseq."
|
||||
:warning)
|
||||
(shui/popup-hide!))
|
||||
nil))))
|
||||
@@ -8,6 +8,7 @@
|
||||
[frontend.db :as db]
|
||||
[frontend.db.model :as db-model]
|
||||
[frontend.handler.editor :as editor-handler]
|
||||
[frontend.mobile.audio-recorder :as audio-recorder]
|
||||
[frontend.mobile.util :as mobile-util]
|
||||
[frontend.state :as state]
|
||||
[frontend.util :as util]
|
||||
@@ -144,7 +145,7 @@
|
||||
(.notify beats value')))))
|
||||
|
||||
;; auto start
|
||||
(.startRecording r)
|
||||
(audio-recorder/start-recording! r)
|
||||
#(stop)))
|
||||
[])
|
||||
|
||||
|
||||
38
src/test/frontend/mobile/audio_recorder_test.cljs
Normal file
38
src/test/frontend/mobile/audio_recorder_test.cljs
Normal file
@@ -0,0 +1,38 @@
|
||||
(ns frontend.mobile.audio-recorder-test
|
||||
(:require [cljs.test :refer [is testing]]
|
||||
[frontend.handler.notification :as notification]
|
||||
[frontend.mobile.audio-recorder :as audio-recorder]
|
||||
[frontend.test.helper :include-macros true :refer [deftest-async]]
|
||||
[logseq.shui.ui :as shui]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(deftest-async start-recording-shows-warning-when-microphone-permission-denied
|
||||
(testing "Shows actionable warning and closes recorder popup when mic permission is denied"
|
||||
(let [warning (atom nil)
|
||||
popup-hidden? (atom false)]
|
||||
(p/with-redefs
|
||||
[notification/show! (fn [content & _]
|
||||
(reset! warning content))
|
||||
shui/popup-hide! (fn []
|
||||
(reset! popup-hidden? true))]
|
||||
(p/let [_ (audio-recorder/start-recording! #js {:startRecording
|
||||
(fn []
|
||||
(p/rejected (js/Error. "Error accessing the microphone: Permission denied")))})]
|
||||
(is (string? @warning))
|
||||
(is (re-find #"Settings" @warning))
|
||||
(is (true? @popup-hidden?)))))))
|
||||
|
||||
(deftest-async start-recording-does-not-show-warning-for-non-permission-errors
|
||||
(testing "Avoids permission warning for unrelated start recording failures"
|
||||
(let [warning (atom nil)
|
||||
popup-hidden? (atom false)]
|
||||
(p/with-redefs
|
||||
[notification/show! (fn [content & _]
|
||||
(reset! warning content))
|
||||
shui/popup-hide! (fn []
|
||||
(reset! popup-hidden? true))]
|
||||
(p/let [_ (audio-recorder/start-recording! #js {:startRecording
|
||||
(fn []
|
||||
(p/rejected (js/Error. "Error: No microphone device found")))})]
|
||||
(is (nil? @warning))
|
||||
(is (false? @popup-hidden?)))))))
|
||||
Reference in New Issue
Block a user