Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit a1e1950

Browse files
committed
Make share more functional.
1 parent afaad41 commit a1e1950

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/action/index-mobile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
NativeModules,
1515
ActionSheetIOS,
1616
NativeEventEmitter,
17+
Share,
1718
} from 'react-native';
1819
import * as Random from 'expo-random';
1920
import * as LocalAuthentication from 'expo-local-authentication';
@@ -47,7 +48,7 @@ store.init(); // initialize computed values
4748
export const db = new AppStorage(store, AsyncStorage);
4849
export const grpc = new GrpcAction(store, NativeModules, NativeEventEmitter);
4950
export const ipc = new IpcAction(grpc);
50-
export const log = new LogAction(store, ipc, false, RNFS);
51+
export const log = new LogAction(store, ipc, false, RNFS, Share);
5152
export const nav = new NavAction(store, NavigationActions, StackActions);
5253
export const notify = new NotificationAction(store, nav);
5354
export const wallet = new WalletAction(store, grpc, db, nav, notify, RNFS);

src/action/log.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ let _store;
1111
let _ipc;
1212
let _printErrObj;
1313
let _FS;
14+
let _Share;
1415

1516
/**
1617
* Log an info event e.g. when something relevant but non-critical happens.
@@ -73,6 +74,23 @@ export function getLogs() {
7374
return _FS.readFile(getLogPath(_store.network), 'utf8');
7475
}
7576

77+
/**
78+
* Shares the log file using whatever native share function we have.
79+
* @return {Promise}
80+
*/
81+
export async function shareLogs() {
82+
if (!_Share) {
83+
return Promise.reject(
84+
'Cannot share logs with no Share library in action/log.js'
85+
);
86+
}
87+
const logs = await getLogs();
88+
return _Share.share({
89+
title: 'Lightning App logs',
90+
message: logs,
91+
});
92+
}
93+
7694
function pushLogs(message) {
7795
if (!_store) return;
7896
_store.logs += '\n' + message.replace(/\s+$/, '');
@@ -83,11 +101,12 @@ function pushLogs(message) {
83101
}
84102

85103
class LogAction {
86-
constructor(store, ipc, printErrObj = true, FS) {
104+
constructor(store, ipc, printErrObj = true, FS, Share) {
87105
_store = store;
88106
_ipc = ipc;
89107
_printErrObj = printErrObj;
90108
_FS = FS;
109+
_Share = Share;
91110
_ipc.listen('logs', (event, message) => pushLogs(message));
92111
_ipc.send('logs-ready', null, true);
93112
}

src/view/cli.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react';
2-
import { ScrollView, StyleSheet, Share, Platform } from 'react-native';
2+
import { ScrollView, StyleSheet, Platform } from 'react-native';
33
import { observer } from 'mobx-react';
44
import PropTypes from 'prop-types';
55
import { SplitBackground } from '../component/background';
@@ -8,7 +8,7 @@ import Text from '../component/text';
88
import { BackButton, ShareButton, Button } from '../component/button';
99
import { createStyles, maxWidth } from '../component/media-query';
1010
import { color, font, breakWidth } from '../component/style';
11-
import { getLogs, error } from '../action/log';
11+
import { shareLogs, error } from '../action/log';
1212

1313
//
1414
// CLI View
@@ -41,11 +41,7 @@ class CLIView extends Component {
4141

4242
async shareLogs() {
4343
try {
44-
const logs = await getLogs();
45-
await Share.share({
46-
title: 'Lightning App logs',
47-
message: logs,
48-
});
44+
await shareLogs();
4945
} catch (err) {
5046
error(err);
5147
}

0 commit comments

Comments
 (0)