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

Commit 17c109b

Browse files
committed
Export logs from filesystem instead of store. Add isMobile conditional to store and dont show share button on desktop.
1 parent 0044dd1 commit 17c109b

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

src/action/index-mobile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ import AtplAction from './autopilot';
4343
//
4444

4545
store.init(); // initialize computed values
46+
store.isMobile = true;
4647

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);
51+
export const log = new LogAction(store, ipc, false, RNFS);
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: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { MAX_LOG_LENGTH } from '../config';
1010
let _store;
1111
let _ipc;
1212
let _printErrObj;
13+
let _FS;
1314

1415
/**
1516
* Log an info event e.g. when something relevant but non-critical happens.
@@ -49,6 +50,29 @@ export function error(...args) {
4950
_ipc && _ipc.send('log-error', null, args);
5051
}
5152

53+
/**
54+
* Gets the location of the LND log file as a string.
55+
* @param {string} network The network the user's on
56+
* @return {string}
57+
*/
58+
export function getLogPath(network) {
59+
const lndDir = _FS.DocumentDirectoryPath;
60+
return `${lndDir}/logs/bitcoin/${network}/lnd.log`;
61+
}
62+
63+
/**
64+
* Retrieves the entire LND log file as a string.
65+
* @return {Promise}
66+
*/
67+
export function getLogs() {
68+
if (!_FS) {
69+
return Promise.reject(
70+
'Cannot get logs when no filesystem is available in action/log.js'
71+
);
72+
}
73+
return _FS.readFile(getLogPath(_store.network), 'utf8');
74+
}
75+
5276
function pushLogs(message) {
5377
if (!_store) return;
5478
_store.logs += '\n' + message.replace(/\s+$/, '');
@@ -59,10 +83,11 @@ function pushLogs(message) {
5983
}
6084

6185
class LogAction {
62-
constructor(store, ipc, printErrObj = true) {
86+
constructor(store, ipc, printErrObj = true, FS) {
6387
_store = store;
6488
_ipc = ipc;
6589
_printErrObj = printErrObj;
90+
_FS = FS;
6691
_ipc.listen('logs', (event, message) => pushLogs(message));
6792
_ipc.send('logs-ready', null, true);
6893
}

src/store.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { DEFAULT_ROUTE, DEFAULT_UNIT, DEFAULT_FIAT } from './config';
1919
export class Store {
2020
constructor() {
2121
extendObservable(this, {
22+
isMobile: false, // Mobile app or desktop electron
2223
navReady: false, // the navigator on mobile is ready
2324
loaded: false, // Is persistent data loaded
2425
unlockerReady: false, // Is wallet unlocker running

src/view/cli.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import PropTypes from 'prop-types';
55
import { SplitBackground } from '../component/background';
66
import { Header, Title } from '../component/header';
77
import Text from '../component/text';
8-
import { BackButton, ShareButton } from '../component/button';
8+
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';
1112

1213
//
1314
// CLI View
@@ -27,20 +28,26 @@ class CLIView extends Component {
2728
<Header separator style={styles.header}>
2829
<BackButton onPress={() => nav.goSettings()} />
2930
<Title title="Logs" />
30-
<ShareButton onPress={() => this.shareLogs()} />
31+
{store.isMobile ? (
32+
<ShareButton onPress={() => this.shareLogs()} />
33+
) : (
34+
<Button onPress={() => {}} />
35+
)}
3136
</Header>
3237
<LogOutput logs={store.logs} />
3338
</SplitBackground>
3439
);
3540
}
3641

37-
shareLogs() {
42+
async shareLogs() {
3843
try {
39-
Share.share({
40-
message: this.props.store.logs,
44+
const logs = await getLogs();
45+
await Share.share({
46+
title: 'Lightning App logs',
47+
message: logs,
4148
});
4249
} catch (err) {
43-
console.error(err);
50+
error(err);
4451
}
4552
}
4653
}

0 commit comments

Comments
 (0)