From b0be9ee9765d90938abf4297a849480d7d81311b Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 7 May 2019 09:37:43 +0300 Subject: [PATCH] Send logs on shaking device --- android/app/build.gradle | 3 +- .../im/status/ethereum/MainApplication.java | 4 +- android/settings.gradle | 2 + clj-rn.conf.edn | 3 +- ios/StatusIm.xcodeproj/project.pbxproj | 30 ++++++++++++ mobile_files/package.json.orig | 1 + mobile_files/yarn.lock | 9 +++- .../react_native/js_dependencies.cljs | 1 + .../react_native/js_dependencies.cljs | 1 + src/status_im/android/core.cljs | 13 +++++- src/status_im/events.cljs | 5 ++ src/status_im/ios/core.cljs | 13 +++++- src/status_im/utils/logging/core.cljs | 46 +++++++++++++++---- translations/en.json | 1 + 14 files changed, 115 insertions(+), 17 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index fda15b55f3..367dd49cfc 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -217,7 +217,7 @@ android { initWith release applicationIdSuffix ".pr" versionNameSuffix ".pr" - debuggable true + debuggable false matchingFallbacks = ["release"] // necessary to make react-native-config's code generation work resValue "string", "build_config_package", "im.status.ethereum" @@ -276,6 +276,7 @@ dependencies { implementation project(':react-native-webview') implementation project(':react-native-config') implementation project(':react-native-firebase') + implementation project(':react-native-shake') implementation project(':RNMail') compile ('com.google.android.gms:play-services-base:16.0.1') { force = true diff --git a/android/app/src/main/java/im/status/ethereum/MainApplication.java b/android/app/src/main/java/im/status/ethereum/MainApplication.java index 3af87055a9..c6886a07bb 100644 --- a/android/app/src/main/java/im/status/ethereum/MainApplication.java +++ b/android/app/src/main/java/im/status/ethereum/MainApplication.java @@ -36,6 +36,7 @@ import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage; import io.realm.react.RealmReactPackage; import me.alwx.HttpServer.HttpServerReactPackage; import com.chirag.RNMail.*; +import com.clipsub.RNShake.RNShakeEventPackage; public class MainApplication extends MultiDexApplication implements ReactApplication { @@ -72,7 +73,8 @@ public class MainApplication extends MultiDexApplication implements ReactApplica new WebViewBridgePackage(BuildConfig.DEBUG_WEBVIEW == "1", callRPC), new RNCWebViewPackage(), new ReactNativeConfigPackage(), - new KeychainPackage()); + new KeychainPackage(), + new RNShakeEventPackage()); } @Override diff --git a/android/settings.gradle b/android/settings.gradle index fb722f36bc..41ee4d0294 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -44,3 +44,5 @@ include ':react-native-android' project(':react-native-android').projectDir = new File(rootProject.projectDir, '../node_modules/react-native/ReactAndroid') include ':RNMail', ':app' project(':RNMail').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mail/android') +include ':react-native-shake' +project(':react-native-shake').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-shake/android') diff --git a/clj-rn.conf.edn b/clj-rn.conf.edn index b05bf05bf7..3e478ac9e8 100644 --- a/clj-rn.conf.edn +++ b/clj-rn.conf.edn @@ -44,7 +44,8 @@ "js-sha3" "react-navigation" "hi-base32" - "react-native-mail"] + "react-native-mail" + "react-native-shake"] ;; Desktop modules :desktop-modules ["realm" diff --git a/ios/StatusIm.xcodeproj/project.pbxproj b/ios/StatusIm.xcodeproj/project.pbxproj index 7bdd831cff..a3d6e24e16 100644 --- a/ios/StatusIm.xcodeproj/project.pbxproj +++ b/ios/StatusIm.xcodeproj/project.pbxproj @@ -33,6 +33,7 @@ 42B30EAD0EED4C72BB96D1AB /* Inter-ExtraBold.otf in Resources */ = {isa = PBXBuildFile; fileRef = 6B145D55D500476BB45C2232 /* Inter-ExtraBold.otf */; }; 475D202F20B7450D00879A77 /* libRNFirebase.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 475D1FC020B7413500879A77 /* libRNFirebase.a */; }; 4C16DE0C1F89508700AA10DB /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C16DE0B1F89508700AA10DB /* JavaScriptCore.framework */; }; + 4C5F69C322815E6A00D26222 /* libRNShakeEvent.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C5F69BE22815E4F00D26222 /* libRNShakeEvent.a */; }; 4C9FBC56227C85640024181F /* libRNMail.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C9FBC50227C85250024181F /* libRNMail.a */; }; 54BD2CE922134B6291FE1BFD /* Inter-Light-BETA.otf in Resources */ = {isa = PBXBuildFile; fileRef = 6864A92FD6844B928C52F5C1 /* Inter-Light-BETA.otf */; }; 57C854A7993C47A3B1AECD32 /* Inter-MediumItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = C6B1215047604CD59A4C74D6 /* Inter-MediumItalic.otf */; }; @@ -188,6 +189,13 @@ remoteGlobalIDString = 134814201AA4EA6300B7C361; remoteInfo = RNFirebase; }; + 4C5F69BD22815E4F00D26222 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 4C5F698522815E4E00D26222 /* RNShakeEvent.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 134814201AA4EA6300B7C361; + remoteInfo = RNShakeEvent; + }; 4C9FBC4F227C85250024181F /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 4C9FBC19227C85250024181F /* RNMail.xcodeproj */; @@ -556,6 +564,7 @@ 475D1FCD20B7415300879A77 /* libFirebaseCore.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libFirebaseCore.a; sourceTree = BUILT_PRODUCTS_DIR; }; 475D1FCE20B7415300879A77 /* libFirebaseMessaging.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libFirebaseMessaging.a; sourceTree = BUILT_PRODUCTS_DIR; }; 4C16DE0B1F89508700AA10DB /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; + 4C5F698522815E4E00D26222 /* RNShakeEvent.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RNShakeEvent.xcodeproj; path = "../node_modules/react-native-shake/ios/RNShakeEvent.xcodeproj"; sourceTree = ""; }; 4C9FBC19227C85250024181F /* RNMail.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RNMail.xcodeproj; path = "../node_modules/react-native-mail/RNMail.xcodeproj"; sourceTree = ""; }; 4E586E1B0E544F64AA9F5BD1 /* libz.tbd */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; 5535217F57E44D77AA9CF083 /* libRCTOrientation.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRCTOrientation.a; sourceTree = ""; }; @@ -629,6 +638,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 4C5F69C322815E6A00D26222 /* libRNShakeEvent.a in Frameworks */, ABC194E5221009A800EB06E6 /* libRNLanguages.a in Frameworks */, 475D202F20B7450D00879A77 /* libRNFirebase.a in Frameworks */, 4C9FBC56227C85640024181F /* libRNMail.a in Frameworks */, @@ -891,6 +901,14 @@ name = Products; sourceTree = ""; }; + 4C5F698622815E4E00D26222 /* Products */ = { + isa = PBXGroup; + children = ( + 4C5F69BE22815E4F00D26222 /* libRNShakeEvent.a */, + ); + name = Products; + sourceTree = ""; + }; 4C9FBC1A227C85250024181F /* Products */ = { isa = PBXGroup; children = ( @@ -922,6 +940,7 @@ 832341AE1AAA6A7D00B99B32 /* Libraries */ = { isa = PBXGroup; children = ( + 4C5F698522815E4E00D26222 /* RNShakeEvent.xcodeproj */, 4C9FBC19227C85250024181F /* RNMail.xcodeproj */, ABC194DC2210099B00EB06E6 /* RNLanguages.xcodeproj */, B461988B2210C98F00603CF2 /* RNCWebView.xcodeproj */, @@ -1324,6 +1343,10 @@ ProductGroup = 475D1EEE20B73EE000879A77 /* Products */; ProjectRef = AF409BB755B94FB1BBA01927 /* RNSecureRandom.xcodeproj */; }, + { + ProductGroup = 4C5F698622815E4E00D26222 /* Products */; + ProjectRef = 4C5F698522815E4E00D26222 /* RNShakeEvent.xcodeproj */; + }, { ProductGroup = 92925B361F571DE600203EEB /* Products */; ProjectRef = 1E74DC52A1E449A2BA858B14 /* RNSVG.xcodeproj */; @@ -1451,6 +1474,13 @@ remoteRef = 475D1FBF20B7413500879A77 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; + 4C5F69BE22815E4F00D26222 /* libRNShakeEvent.a */ = { + isa = PBXReferenceProxy; + fileType = archive.ar; + path = libRNShakeEvent.a; + remoteRef = 4C5F69BD22815E4F00D26222 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; 4C9FBC50227C85250024181F /* libRNMail.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; diff --git a/mobile_files/package.json.orig b/mobile_files/package.json.orig index f0287b9fa4..64c0057717 100644 --- a/mobile_files/package.json.orig +++ b/mobile_files/package.json.orig @@ -54,6 +54,7 @@ "react-native-randombytes": "3.5.0", "react-native-safe-area-view": "0.9.0", "react-native-securerandom": "git+https://github.com/status-im/react-native-securerandom.git#0.1.1-2", + "react-native-shake": "^3.3.1", "react-native-splash-screen": "3.1.1", "react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#v2.5.4", "react-native-svg": "^9.2.4", diff --git a/mobile_files/yarn.lock b/mobile_files/yarn.lock index 6d5b87ab06..121b6767c1 100644 --- a/mobile_files/yarn.lock +++ b/mobile_files/yarn.lock @@ -3526,7 +3526,7 @@ invariant@2.2.0: dependencies: loose-envify "^1.0.0" -invariant@^2.2.2, invariant@^2.2.4: +invariant@^2.2.2, invariant@^2.2.4, invariant@^2.2.x: version "2.2.4" resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6" integrity sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA== @@ -5581,6 +5581,13 @@ react-native-scrollable-mixin@^1.0.1: dependencies: base64-js "*" +react-native-shake@^3.3.1: + version "3.3.1" + resolved "https://registry.yarnpkg.com/react-native-shake/-/react-native-shake-3.3.1.tgz#e168827015db0cfb316f2bd428afe95f225fda6a" + integrity sha512-Z5W/tC3rsOcQmAOxe/uHsGNrXyZx3xwd1bFaRw0pbO0lhG4Z1g2MOcrO/Pa+ZA59ap/1tmwVP6/+IPtt6DPT1w== + dependencies: + invariant "^2.2.x" + react-native-splash-screen@3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/react-native-splash-screen/-/react-native-splash-screen-3.1.1.tgz#1a4e46c9fdce53ff52af2a2cb4181788c4e30b30" diff --git a/react-native/src/desktop/status_im/react_native/js_dependencies.cljs b/react-native/src/desktop/status_im/react_native/js_dependencies.cljs index 979226a911..6c1476b538 100644 --- a/react-native/src/desktop/status_im/react_native/js_dependencies.cljs +++ b/react-native/src/desktop/status_im/react_native/js_dependencies.cljs @@ -33,4 +33,5 @@ (def snoopy-buffer #js {}) (def background-timer #js {:setTimeout (fn [cb ms] (js/setTimeout cb ms))}) (def react-navigation (js/require "react-navigation")) +(def react-native-shake #js {}) (def react-native-mail #js {:mail (fn [])}) diff --git a/react-native/src/mobile/status_im/react_native/js_dependencies.cljs b/react-native/src/mobile/status_im/react_native/js_dependencies.cljs index aaaadf04bb..127683847d 100644 --- a/react-native/src/mobile/status_im/react_native/js_dependencies.cljs +++ b/react-native/src/mobile/status_im/react_native/js_dependencies.cljs @@ -28,6 +28,7 @@ (def snoopy-buffer (js/require "rn-snoopy/stream/buffer")) (def background-timer (.-default (js/require "react-native-background-timer"))) (def react-navigation (js/require "react-navigation")) +(def react-native-shake (js/require "react-native-shake")) (def react-native-mail (.-default (js/require "react-native-mail"))) (def desktop-linking #js {:addEventListener (fn [])}) (def desktop-menu #js {:addEventListener (fn [])}) diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index 923e664c70..b90e163b99 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -21,6 +21,9 @@ (defn on-languages-change [event] (set! (.-locale rn-dependencies/i18n) (.-language event))) +(defn on-shake [] + (dispatch [:shake-event])) + (defn app-root [props] (let [keyboard-height (subscribe [:keyboard-height])] (reagent/create-class @@ -42,7 +45,10 @@ (dispatch [:set :keyboard-height 0])))) (.hide react/splash-screen) (.addEventListener react/app-state "change" app-state-change-handler) - (.addEventListener rn-dependencies/react-native-languages "change" on-languages-change)) + (.addEventListener rn-dependencies/react-native-languages "change" on-languages-change) + (.addEventListener rn-dependencies/react-native-shake + "ShakeEvent" + on-shake)) :component-did-mount (fn [this] (dispatch [:set-initial-props (reagent/props this)])) @@ -50,7 +56,10 @@ (fn [] (.stop react/http-bridge) (.removeEventListener react/app-state "change" app-state-change-handler) - (.removeEventListener rn-dependencies/react-native-languages "change" on-languages-change)) + (.removeEventListener rn-dependencies/react-native-languages "change" on-languages-change) + (.removeEventListener rn-dependencies/react-native-shake + "ShakeEvent" + on-shake)) :display-name "root" :reagent-render views/main}))) diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 5e445e0932..ddd2234d05 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -2237,3 +2237,8 @@ (fx/merge cofx {:db (assoc-in db [:wallet :send-transaction] {})} (navigation/navigate-back)))) + +(handlers/register-handler-fx + :shake-event + (fn [cofx _] + (logging/show-logs-dialog cofx))) diff --git a/src/status_im/ios/core.cljs b/src/status_im/ios/core.cljs index 1280a8a52e..89efceb78d 100644 --- a/src/status_im/ios/core.cljs +++ b/src/status_im/ios/core.cljs @@ -19,6 +19,9 @@ (defn on-languages-change [event] (set! (.-locale rn-dependencies/i18n) (.-language event))) +(defn on-shake [] + (dispatch [:shake-event])) + (defn app-root [props] (let [keyboard-height (subscribe [:keyboard-height])] (reagent/create-class @@ -37,7 +40,10 @@ (dispatch [:set :keyboard-height 0]))) (.hide react/splash-screen) (.addEventListener react/app-state "change" app-state-change-handler) - (.addEventListener rn-dependencies/react-native-languages "change" on-languages-change)) + (.addEventListener rn-dependencies/react-native-languages "change" on-languages-change) + (.addEventListener rn-dependencies/react-native-shake + "ShakeEvent" + on-shake)) :component-did-mount (fn [this] (dispatch [:set-initial-props (reagent/props this)])) @@ -45,7 +51,10 @@ (fn [] (.stop react/http-bridge) (.removeEventListener react/app-state "change" app-state-change-handler) - (.removeEventListener rn-dependencies/react-native-languages "change" on-languages-change)) + (.removeEventListener rn-dependencies/react-native-languages "change" on-languages-change) + (.removeEventListener rn-dependencies/react-native-shake + "ShakeEvent" + on-shake)) :display-name "root" :reagent-render views/main}))) diff --git a/src/status_im/utils/logging/core.cljs b/src/status_im/utils/logging/core.cljs index b6abfe6343..52b82d89b2 100644 --- a/src/status_im/utils/logging/core.cljs +++ b/src/status_im/utils/logging/core.cljs @@ -6,7 +6,8 @@ [status-im.utils.handlers :as handlers] [status-im.utils.email :as mail] [taoensso.timbre :as log] - [status-im.utils.config :as config])) + [status-im.utils.config :as config] + [status-im.i18n :as i18n])) (def report-email "error-reports@status.im") (def max-log-entries 1000) @@ -63,14 +64,41 @@ :node/status]))] {:logs/archive-logs [db-json ::send-email]})) +(fx/defn show-logs-dialog + [{:keys [db]}] + (when-not (:logging/dialog-shown? db) + {:db + (assoc db :logging/dialog-shown? true) + :utils/show-confirmation + {:title (i18n/label :t/send-logs) + :content (i18n/label :t/send-logs-to + {:email report-email}) + :confirm-button-text (i18n/label :t/send-logs) + :on-accept #(re-frame/dispatch + [:logging.ui/send-logs-pressed]) + :on-cancel #(re-frame/dispatch + [:logging/dialog-canceled])}})) + +(fx/defn dialog-closed + [{:keys [db]}] + {:db (dissoc db :logging/dialog-shown?)}) + (handlers/register-handler-fx ::send-email (fn [cofx [_ archive-path]] - (mail/send-email cofx - {:subject "Error report" - :recipients [report-email] - :body "logs attached" - :attachment {:path archive-path - :type "zip" - :name "status_logs.zip"}} - (fn [])))) + (fx/merge + cofx + (dialog-closed) + (mail/send-email + {:subject "Error report" + :recipients [report-email] + :body "logs attached" + :attachment {:path archive-path + :type "zip" + :name "status_logs.zip"}} + (fn []))))) + +(handlers/register-handler-fx + :logging/dialog-canceled + (fn [cofx] + (dialog-closed cofx))) diff --git a/translations/en.json b/translations/en.json index a0b8ecff82..a375aa82e6 100644 --- a/translations/en.json +++ b/translations/en.json @@ -425,6 +425,7 @@ "status-not-sent-tap": "Not confirmed. Tap for options", "status-not-sent-click": "Not confirmed. Click for options", "send-logs": "Send logs", + "send-logs-to": "Send logs to {{email}}", "edit-network-config": "Edit network config", "clear-history-confirmation": "Clear history?", "currency-display-name-gyd": "Guyana Dollar",