enable easy sharing of lbrynet log file

This commit is contained in:
Akinwale Ariwodola 2018-12-02 00:34:57 +01:00
parent 48b92ed2a6
commit 2e31a7fbdb
6 changed files with 66 additions and 3 deletions

View file

@ -1,4 +1,5 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { doToast } from 'lbry-redux';
import { doFetchAccessToken, selectAccessToken, selectUserEmail } from 'lbryinc'; import { doFetchAccessToken, selectAccessToken, selectUserEmail } from 'lbryinc';
import AboutPage from './view'; import AboutPage from './view';
@ -9,6 +10,7 @@ const select = state => ({
const perform = dispatch => ({ const perform = dispatch => ({
fetchAccessToken: () => dispatch(doFetchAccessToken()), fetchAccessToken: () => dispatch(doFetchAccessToken()),
notify: data => dispatch(doToast(data)),
}); });
export default connect(select, perform)(AboutPage); export default connect(select, perform)(AboutPage);

View file

@ -33,7 +33,7 @@ class AboutPage extends React.PureComponent {
} }
render() { render() {
const { accessToken, navigation, userEmail } = this.props; const { accessToken, navigation, notify, userEmail } = this.props;
const loading = 'Loading...'; const loading = 'Loading...';
const ver = this.state.versionInfo ? this.state.versionInfo : null; const ver = this.state.versionInfo ? this.state.versionInfo : null;
@ -75,7 +75,7 @@ class AboutPage extends React.PureComponent {
</View> </View>
<View> <View>
<Link <Link
style={aboutStyle.emailPreferencesLink} style={aboutStyle.listLink}
href={`http://lbry.io/list/edit/${accessToken}`} href={`http://lbry.io/list/edit/${accessToken}`}
text="Update mailing preferences" /> text="Update mailing preferences" />
</View> </View>
@ -102,6 +102,21 @@ class AboutPage extends React.PureComponent {
<Text selectable={true} style={aboutStyle.lineValueText}>{this.state.lbryId ? this.state.lbryId : loading}</Text> <Text selectable={true} style={aboutStyle.lineValueText}>{this.state.lbryId ? this.state.lbryId : loading}</Text>
</View> </View>
</View> </View>
<View style={aboutStyle.row}>
<View style={aboutStyle.col}><Text style={aboutStyle.text}>Logs</Text></View>
<View style={aboutStyle.col}>
<Link style={aboutStyle.listLink} text="Send log" onPress={() => {
if (NativeModules.UtilityModule) {
NativeModules.UtilityModule.shareLogFile((error) => {
if (error) {
notify(error);
}
});
}
}} />
</View>
</View>
</ScrollView> </ScrollView>
</View> </View>
); );

View file

@ -56,7 +56,7 @@ const aboutStyle = StyleSheet.create({
fontSize: 16, fontSize: 16,
marginBottom: 24 marginBottom: 24
}, },
emailPreferencesLink: { listLink: {
color: Colors.LbryGreen, color: Colors.LbryGreen,
fontFamily: 'Metropolis-Regular', fontFamily: 'Metropolis-Regular',
fontSize: 15, fontSize: 15,

View file

@ -140,6 +140,16 @@
</intent-filter> </intent-filter>
</receiver> </receiver>
{% endif %} {% endif %}
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="io.lbry.browser.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>
</application> </application>
</manifest> </manifest>

View file

@ -2,21 +2,30 @@ package io.lbry.browser.reactmodules;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.Manifest; import android.Manifest;
import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.support.v4.content.FileProvider;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.ReactMethod;
import java.io.File;
import io.lbry.browser.MainActivity; import io.lbry.browser.MainActivity;
import io.lbry.browser.Utils;
public class UtilityModule extends ReactContextBaseJavaModule { public class UtilityModule extends ReactContextBaseJavaModule {
private static final String FILE_PROVIDER = "io.lbry.browser.fileprovider";
private Context context; private Context context;
public UtilityModule(ReactApplicationContext reactContext) { 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() { private static boolean isEmulator() {
String buildModel = Build.MODEL.toLowerCase(); String buildModel = Build.MODEL.toLowerCase();
return (// Check FINGERPRINT return (// Check FINGERPRINT

View file

@ -0,0 +1,3 @@
<paths>
<external-files-path path="lbrynet/" name="lbrynet" />
</paths>