From 2e31a7fbdb01b1d680cac2ee35e2def0590b3011 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Sun, 2 Dec 2018 00:34:57 +0100 Subject: [PATCH] enable easy sharing of lbrynet log file --- app/src/page/about/index.js | 2 ++ app/src/page/about/view.js | 19 +++++++++-- app/src/styles/about.js | 2 +- .../build/templates/AndroidManifest.tmpl.xml | 10 ++++++ .../browser/reactmodules/UtilityModule.java | 33 +++++++++++++++++++ src/main/res/xml/filepaths.xml | 3 ++ 6 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 src/main/res/xml/filepaths.xml diff --git a/app/src/page/about/index.js b/app/src/page/about/index.js index e389db20..fd767ed9 100644 --- a/app/src/page/about/index.js +++ b/app/src/page/about/index.js @@ -1,4 +1,5 @@ import { connect } from 'react-redux'; +import { doToast } from 'lbry-redux'; import { doFetchAccessToken, selectAccessToken, selectUserEmail } from 'lbryinc'; import AboutPage from './view'; @@ -9,6 +10,7 @@ const select = state => ({ const perform = dispatch => ({ fetchAccessToken: () => dispatch(doFetchAccessToken()), + notify: data => dispatch(doToast(data)), }); export default connect(select, perform)(AboutPage); \ No newline at end of file diff --git a/app/src/page/about/view.js b/app/src/page/about/view.js index 190fe3f1..d67b586a 100644 --- a/app/src/page/about/view.js +++ b/app/src/page/about/view.js @@ -33,7 +33,7 @@ class AboutPage extends React.PureComponent { } render() { - const { accessToken, navigation, userEmail } = this.props; + const { accessToken, navigation, notify, userEmail } = this.props; const loading = 'Loading...'; const ver = this.state.versionInfo ? this.state.versionInfo : null; @@ -75,7 +75,7 @@ class AboutPage extends React.PureComponent { @@ -102,6 +102,21 @@ class AboutPage extends React.PureComponent { {this.state.lbryId ? this.state.lbryId : loading} + + + Logs + + { + if (NativeModules.UtilityModule) { + NativeModules.UtilityModule.shareLogFile((error) => { + if (error) { + notify(error); + } + }); + } + }} /> + + ); diff --git a/app/src/styles/about.js b/app/src/styles/about.js index 784bb72f..d5765b77 100644 --- a/app/src/styles/about.js +++ b/app/src/styles/about.js @@ -56,7 +56,7 @@ const aboutStyle = StyleSheet.create({ fontSize: 16, marginBottom: 24 }, - emailPreferencesLink: { + listLink: { color: Colors.LbryGreen, fontFamily: 'Metropolis-Regular', fontSize: 15, diff --git a/p4a/pythonforandroid/bootstraps/lbry/build/templates/AndroidManifest.tmpl.xml b/p4a/pythonforandroid/bootstraps/lbry/build/templates/AndroidManifest.tmpl.xml index 198f4a4d..f96f8d87 100644 --- a/p4a/pythonforandroid/bootstraps/lbry/build/templates/AndroidManifest.tmpl.xml +++ b/p4a/pythonforandroid/bootstraps/lbry/build/templates/AndroidManifest.tmpl.xml @@ -140,6 +140,16 @@ {% endif %} + + + + diff --git a/src/main/java/io/lbry/browser/reactmodules/UtilityModule.java b/src/main/java/io/lbry/browser/reactmodules/UtilityModule.java index 84dee733..39ad8143 100644 --- a/src/main/java/io/lbry/browser/reactmodules/UtilityModule.java +++ b/src/main/java/io/lbry/browser/reactmodules/UtilityModule.java @@ -2,21 +2,30 @@ package io.lbry.browser.reactmodules; import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; import android.Manifest; +import android.net.Uri; import android.os.Build; +import android.support.v4.content.FileProvider; import android.telephony.TelephonyManager; import android.view.View; import android.view.WindowManager; +import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; +import java.io.File; + import io.lbry.browser.MainActivity; +import io.lbry.browser.Utils; public class UtilityModule extends ReactContextBaseJavaModule { + private static final String FILE_PROVIDER = "io.lbry.browser.fileprovider"; + private Context context; public UtilityModule(ReactApplicationContext reactContext) { @@ -139,6 +148,30 @@ public class UtilityModule extends ReactContextBaseJavaModule { } } + @ReactMethod + public void shareLogFile(Callback errorCallback) { + String logFileName = "lbrynet.log"; + File logFile = new File(String.format("%s/%s", Utils.getAppInternalStorageDir(context), "lbrynet"), logFileName); + if (!logFile.exists()) { + errorCallback.invoke("The lbrynet.log file could not be found."); + return; + } + + try { + Uri fileUri = FileProvider.getUriForFile(context, FILE_PROVIDER, logFile); + if (fileUri != null) { + Intent shareIntent = new Intent(); + shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + shareIntent.setAction(Intent.ACTION_SEND); + shareIntent.setType("text/plain"); + shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri); + context.startActivity(Intent.createChooser(shareIntent, "Send LBRY log")); + } + } catch (IllegalArgumentException e) { + errorCallback.invoke("The lbrynet.log file cannot be shared due to permission restrictions."); + } + } + private static boolean isEmulator() { String buildModel = Build.MODEL.toLowerCase(); return (// Check FINGERPRINT diff --git a/src/main/res/xml/filepaths.xml b/src/main/res/xml/filepaths.xml new file mode 100644 index 00000000..6c65d1c7 --- /dev/null +++ b/src/main/res/xml/filepaths.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file