Move crash reporting listener to the server
Summary: Changelog: Move crash watcher to the server. Add 'device-crash' event. Add 'device-start-crash-watcher', 'device-stop-crash-watcher' commands. Add 'onDeviceCrash' method to Plugin Client. Reviewed By: mweststrate Differential Revision: D33089810 fbshipit-source-id: ed62ee7c1129e5e25af18b444744b0796f567b72
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9fd45b96d2
commit
731749b41f
@@ -7,11 +7,8 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import type {FSWatcher} from 'fs';
|
||||
import {createState, DevicePluginClient} from 'flipper-plugin';
|
||||
import {createState, DevicePluginClient, CrashLog} from 'flipper-plugin';
|
||||
import {showCrashNotification} from './crash-utils';
|
||||
import {addFileWatcherForiOSCrashLogs} from './ios-crash-utils';
|
||||
import {startAndroidCrashWatcher} from './android-crash-utils';
|
||||
|
||||
export type Crash = {
|
||||
notificationID: string;
|
||||
@@ -21,16 +18,8 @@ export type Crash = {
|
||||
date: number;
|
||||
};
|
||||
|
||||
export type CrashLog = {
|
||||
callstack: string;
|
||||
reason: string;
|
||||
name: string;
|
||||
date?: number;
|
||||
};
|
||||
|
||||
export function devicePlugin(client: DevicePluginClient) {
|
||||
let notificationID = -1;
|
||||
let watcher: Promise<FSWatcher | undefined> | undefined = undefined;
|
||||
|
||||
const crashes = createState<Crash[]>([], {persist: 'crashes'});
|
||||
const selectedCrash = createState<string | undefined>();
|
||||
@@ -59,31 +48,13 @@ export function devicePlugin(client: DevicePluginClient) {
|
||||
|
||||
// Startup logic to establish log monitoring
|
||||
if (client.device.isConnected) {
|
||||
if (client.device.os.includes('iOS')) {
|
||||
watcher = addFileWatcherForiOSCrashLogs(
|
||||
client.device.serial,
|
||||
reportCrash,
|
||||
);
|
||||
} else {
|
||||
startAndroidCrashWatcher(client, reportCrash);
|
||||
}
|
||||
client.onDeviceCrash(reportCrash);
|
||||
}
|
||||
|
||||
client.onDestroy(() => {
|
||||
watcher
|
||||
?.then((watcher) => watcher?.close())
|
||||
.catch((e) =>
|
||||
console.error(
|
||||
'[crash_reporter] FSWatcher failed resoving on destroy:',
|
||||
e,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
return {
|
||||
reportCrash,
|
||||
crashes,
|
||||
selectedCrash,
|
||||
reportCrash,
|
||||
openInLogs(callstack: string) {
|
||||
client.selectPlugin('DeviceLogs', callstack);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user