request permissions before saving images

Signed-off-by: Michele Balistreri <michele@bitgamma.com>
This commit is contained in:
Michele Balistreri 2021-08-30 11:29:36 +03:00
parent aaff386146
commit ad29cc7e30
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
3 changed files with 32 additions and 14 deletions

View File

@ -78,6 +78,8 @@
<string>Location access is required for some DApps to function properly.</string> <string>Location access is required for some DApps to function properly.</string>
<key>NSPhotoLibraryUsageDescription</key> <key>NSPhotoLibraryUsageDescription</key>
<string>Photos access is required to give you the ability to send images.</string> <string>Photos access is required to give you the ability to send images.</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Photos access is required to give you the ability to save images.</string>
<key>NSMicrophoneUsageDescription</key> <key>NSMicrophoneUsageDescription</key>
<string>Need microphone access for sending audio messages.</string> <string>Need microphone access for sending audio messages.</string>
<key>UIAppFonts</key> <key>UIAppFonts</key>

View File

@ -83,6 +83,8 @@
<string>Location access is required for some DApps to function properly.</string> <string>Location access is required for some DApps to function properly.</string>
<key>NSPhotoLibraryUsageDescription</key> <key>NSPhotoLibraryUsageDescription</key>
<string>Photos access is required to give you the ability to send images.</string> <string>Photos access is required to give you the ability to send images.</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Photos access is required to give you the ability to save images.</string>
<key>NSMicrophoneUsageDescription</key> <key>NSMicrophoneUsageDescription</key>
<string>Need microphone access for sending audio messages.</string> <string>Need microphone access for sending audio messages.</string>
<key>UIAppFonts</key> <key>UIAppFonts</key>

View File

@ -9,6 +9,8 @@
[status-im.utils.image-processing :as image-processing] [status-im.utils.image-processing :as image-processing]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[clojure.string :as string] [clojure.string :as string]
[status-im.i18n.i18n :as i18n]
[status-im.utils.utils :as utils]
[status-im.utils.platform :as platform] [status-im.utils.platform :as platform]
[status-im.chat.models :as chat])) [status-im.chat.models :as chat]))
@ -35,24 +37,36 @@
(.-localIdentifier result) (.-localIdentifier result)
(.-path result))) (.-path result)))
(defn android-save-image-to-gallery [base64-uri]
(react/image-get-size
base64-uri
(fn [width height]
(image-processing/resize
base64-uri
width
height
100
(fn [^js resized-image]
(let [path (.-path resized-image)
path (if (string/starts-with? path "file") path (str "file://" path))]
(.saveToCameraRoll CameraRoll path)))
#(log/error "could not resize image" %)))))
(re-frame/reg-fx (re-frame/reg-fx
::save-image-to-gallery ::save-image-to-gallery
(fn [base64-uri] (fn [base64-uri]
(if platform/ios? (if platform/ios?
(.saveToCameraRoll CameraRoll base64-uri) (-> (.saveToCameraRoll CameraRoll base64-uri)
(react/image-get-size (.catch #(utils/show-popup (i18n/label :t/error)
base64-uri (i18n/label :t/external-storage-denied))))
(fn [width height] (permissions/request-permissions
(image-processing/resize {:permissions [:write-external-storage]
base64-uri :on-allowed #(android-save-image-to-gallery base64-uri)
width :on-denied (fn []
height (utils/set-timeout
100 #(utils/show-popup (i18n/label :t/error)
(fn [^js resized-image] (i18n/label :t/external-storage-denied))
(let [path (.-path resized-image) 50))}))))
path (if (string/starts-with? path "file") path (str "file://" path))]
(.saveToCameraRoll CameraRoll path)))
#(log/error "could not resize image" %)))))))
(re-frame/reg-fx (re-frame/reg-fx
::chat-open-image-picker-camera ::chat-open-image-picker-camera