[#5047] Do not show QR code scanner when camera permissions has not been granted

This commit is contained in:
Roman Volosovskyi 2018-07-06 12:15:50 +03:00
parent b6a68e79c7
commit 229c64f002
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
4 changed files with 17 additions and 8 deletions

View File

@ -14,7 +14,7 @@
(defn all-granted? [permissions] (defn all-granted? [permissions]
(let [permission-vals (distinct (vals permissions))] (let [permission-vals (distinct (vals permissions))]
(and (= (count permission-vals) 1) (and (= (count permission-vals) 1)
(not= (first permission-vals) "denied")))) (not (#{"denied" "never_ask_again"} (first permission-vals))))))
(defn request-permissions [{:keys [permissions on-allowed on-denied] (defn request-permissions [{:keys [permissions on-allowed on-denied]
:or {on-allowed #() :or {on-allowed #()

View File

@ -53,8 +53,11 @@
:action (fn [] :action (fn []
(re-frame/dispatch [:request-permissions {:permissions [:camera :write-external-storage] (re-frame/dispatch [:request-permissions {:permissions [:camera :write-external-storage]
:on-allowed #(re-frame/dispatch [:navigate-to :profile-photo-capture]) :on-allowed #(re-frame/dispatch [:navigate-to :profile-photo-capture])
:on-denied #(utils/show-popup (i18n/label :t/error) :on-denied (fn []
(i18n/label :t/camera-access-error))}]))}]) (utils/set-timeout
#(utils/show-popup (i18n/label :t/error)
(i18n/label :t/camera-access-error))
50))}]))}])
(defn qr-viewer-toolbar [label value] (defn qr-viewer-toolbar [label value]
[toolbar/toolbar {} [toolbar/toolbar {}

View File

@ -8,11 +8,14 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:scan-qr-code :scan-qr-code
(fn [{:keys [db]} [_ identifier handler]] (fn [{:keys [db]} [_ identifier handler]]
{:db (assoc-in db [:qr-codes identifier] handler) {:db (assoc-in db [:qr-codes identifier] handler)
:request-permissions-fx {:permissions [:camera] :request-permissions-fx {:permissions [:camera]
:on-allowed #(re-frame/dispatch [:navigate-to :qr-scanner {:current-qr-context identifier}]) :on-allowed #(re-frame/dispatch [:navigate-to :qr-scanner {:current-qr-context identifier}])
:on-denied #(utils/show-popup (i18n/label :t/error) :on-denied (fn []
(i18n/label :t/camera-access-error))}})) (utils/set-timeout
#(utils/show-popup (i18n/label :t/error)
(i18n/label :t/camera-access-error))
50))}}))
(handlers/register-handler-fx (handlers/register-handler-fx
:clear-qr-code :clear-qr-code

View File

@ -163,8 +163,11 @@
(defn- request-camera-permissions [] (defn- request-camera-permissions []
(re-frame/dispatch [:request-permissions {:permissions [:camera] (re-frame/dispatch [:request-permissions {:permissions [:camera]
:on-allowed #(re-frame/dispatch [:navigate-to :recipient-qr-code]) :on-allowed #(re-frame/dispatch [:navigate-to :recipient-qr-code])
:on-denied #(utils/show-popup (i18n/label :t/error) :on-denied #(utils/set-timeout
(i18n/label :t/camera-access-error))}])) (fn []
(utils/show-popup (i18n/label :t/error)
(i18n/label :t/camera-access-error)))
50)}]))
(defn- on-choose-recipient [contact-only?] (defn- on-choose-recipient [contact-only?]
(list-selection/show {:title (i18n/label :t/wallet-choose-recipient) (list-selection/show {:title (i18n/label :t/wallet-choose-recipient)