Background events
Summary: `this.client.subscribe` was used to listen for navigation events. This means, navigation events are not collected while the plugin is in background. In this diff, this is changed to a persistedStateReducer, so the events are collected with the plugin not active. Reviewed By: jknoxville Differential Revision: D17419668 fbshipit-source-id: 88d9476cb7461ff6774d42a992d32b4c8948ac86
This commit is contained in:
committed by
Facebook Github Bot
parent
1d6fc9e3ac
commit
1666cf5ee5
@@ -59,45 +59,45 @@ export default class extends FlipperPlugin<State, any, PersistedState> {
|
||||
static persistedStateReducer = (
|
||||
persistedState: PersistedState,
|
||||
method: string,
|
||||
payload: any,
|
||||
) => {
|
||||
switch (method) {
|
||||
default:
|
||||
return {
|
||||
...persistedState,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
subscribeToNavigationEvents = () => {
|
||||
this.client.subscribe('nav_event', payload => {
|
||||
let {persistedState} = this.props;
|
||||
const {setPersistedState} = this.props;
|
||||
case 'nav_event':
|
||||
const navigationEvent: NavigationEvent = {
|
||||
uri: payload.uri === undefined ? null : decodeURIComponent(payload.uri),
|
||||
uri:
|
||||
payload.uri === undefined ? null : decodeURIComponent(payload.uri),
|
||||
date: new Date(payload.date) || new Date(),
|
||||
className: payload.class === undefined ? null : payload.class,
|
||||
screenshot: null,
|
||||
};
|
||||
setPersistedState({
|
||||
|
||||
return {
|
||||
...persistedState,
|
||||
currentURI:
|
||||
payload.uri == null
|
||||
navigationEvent.uri == null
|
||||
? persistedState.currentURI
|
||||
: decodeURIComponent(payload.uri),
|
||||
navigationEvents: [navigationEvent, ...persistedState.navigationEvents],
|
||||
});
|
||||
: decodeURIComponent(navigationEvent.uri),
|
||||
navigationEvents: [
|
||||
navigationEvent,
|
||||
...persistedState.navigationEvents,
|
||||
],
|
||||
};
|
||||
default:
|
||||
return persistedState;
|
||||
}
|
||||
};
|
||||
|
||||
subscribeToNavigationEvents = () => {
|
||||
this.client.subscribe('nav_event', () =>
|
||||
// Wait for view to render and then take a screenshot
|
||||
setTimeout(() => {
|
||||
persistedState = this.props.persistedState;
|
||||
this.getDevice()
|
||||
.then(device => device.screenshot())
|
||||
.then((buffer: Buffer) => {
|
||||
const blobURL = URL.createObjectURL(bufferToBlob(buffer));
|
||||
navigationEvent.screenshot = blobURL;
|
||||
setPersistedState({...persistedState});
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
setTimeout(async () => {
|
||||
const device = await this.getDevice();
|
||||
const screenshot = await device.screenshot();
|
||||
const blobURL = URL.createObjectURL(bufferToBlob(screenshot));
|
||||
this.props.persistedState.navigationEvents[0].screenshot = blobURL;
|
||||
this.props.setPersistedState({...this.props.persistedState});
|
||||
}, 1000),
|
||||
);
|
||||
};
|
||||
|
||||
componentDidMount = () => {
|
||||
|
||||
Reference in New Issue
Block a user