Refactor the type of os from String to an closest enum kind of thing
Summary: This diff updates the type of os in Store from string to a custom enum kind of type. Reviewed By: passy Differential Revision: D13622598 fbshipit-source-id: c57a1f2eedbe9e88d43c681c2fa6ca72b93e8808
This commit is contained in:
committed by
Facebook Github Bot
parent
d868cd6405
commit
3b9253680f
@@ -10,7 +10,7 @@ import type BaseDevice from './devices/BaseDevice.js';
|
|||||||
import type {App} from './App.js';
|
import type {App} from './App.js';
|
||||||
import type Logger from './fb-stubs/Logger.js';
|
import type Logger from './fb-stubs/Logger.js';
|
||||||
import type {Store} from './reducers/index.js';
|
import type {Store} from './reducers/index.js';
|
||||||
|
import type {OS} from './devices/BaseDevice.js';
|
||||||
import {FlipperDevicePlugin} from './plugin.js';
|
import {FlipperDevicePlugin} from './plugin.js';
|
||||||
import {setPluginState} from './reducers/pluginStates.js';
|
import {setPluginState} from './reducers/pluginStates.js';
|
||||||
import {ReactiveSocket, PartialResponder} from 'rsocket-core';
|
import {ReactiveSocket, PartialResponder} from 'rsocket-core';
|
||||||
@@ -22,7 +22,7 @@ type Plugins = Array<string>;
|
|||||||
|
|
||||||
export type ClientQuery = {|
|
export type ClientQuery = {|
|
||||||
app: string,
|
app: string,
|
||||||
os: string,
|
os: OS,
|
||||||
device: string,
|
device: string,
|
||||||
device_id: string,
|
device_id: string,
|
||||||
|};
|
|};
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ export type DeviceLogListener = (entry: DeviceLogEntry) => void;
|
|||||||
|
|
||||||
export type DeviceType = 'emulator' | 'physical';
|
export type DeviceType = 'emulator' | 'physical';
|
||||||
|
|
||||||
|
export type OS = 'iOS' | 'Android' | 'Windows';
|
||||||
|
|
||||||
export default class BaseDevice {
|
export default class BaseDevice {
|
||||||
constructor(serial: string, deviceType: DeviceType, title: string) {
|
constructor(serial: string, deviceType: DeviceType, title: string) {
|
||||||
this.serial = serial;
|
this.serial = serial;
|
||||||
@@ -44,7 +46,7 @@ export default class BaseDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// operating system of this device
|
// operating system of this device
|
||||||
os: string;
|
os: OS;
|
||||||
|
|
||||||
// human readable name for this device
|
// human readable name for this device
|
||||||
title: string;
|
title: string;
|
||||||
@@ -61,7 +63,7 @@ export default class BaseDevice {
|
|||||||
logListeners: Map<Symbol, DeviceLogListener> = new Map();
|
logListeners: Map<Symbol, DeviceLogListener> = new Map();
|
||||||
logEntries: Array<DeviceLogEntry> = [];
|
logEntries: Array<DeviceLogEntry> = [];
|
||||||
|
|
||||||
supportsOS(os: string) {
|
supportsOS(os: OS) {
|
||||||
return os.toLowerCase() === this.os.toLowerCase();
|
return os.toLowerCase() === this.os.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,3 +33,4 @@ export {default as DetailSidebar} from './chrome/DetailSidebar.js';
|
|||||||
export {default as AndroidDevice} from './devices/AndroidDevice.js';
|
export {default as AndroidDevice} from './devices/AndroidDevice.js';
|
||||||
export {default as Device} from './devices/BaseDevice.js';
|
export {default as Device} from './devices/BaseDevice.js';
|
||||||
export {default as IOSDevice} from './devices/IOSDevice.js';
|
export {default as IOSDevice} from './devices/IOSDevice.js';
|
||||||
|
export type {OS} from './devices/BaseDevice.js';
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import os from 'os';
|
|||||||
import util from 'util';
|
import util from 'util';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import type {Notification} from '../../plugin';
|
import type {Notification} from '../../plugin';
|
||||||
import type {Store, DeviceLogEntry} from 'flipper';
|
import type {Store, DeviceLogEntry, OS} from 'flipper';
|
||||||
|
|
||||||
export type Crash = {|
|
export type Crash = {|
|
||||||
notificationID: string,
|
notificationID: string,
|
||||||
@@ -82,7 +82,7 @@ export function getNewPersisitedStateFromCrashLog(
|
|||||||
persistedState: ?PersistedState,
|
persistedState: ?PersistedState,
|
||||||
persistingPlugin: Class<FlipperDevicePlugin<> | FlipperPlugin<>>,
|
persistingPlugin: Class<FlipperDevicePlugin<> | FlipperPlugin<>>,
|
||||||
content: string,
|
content: string,
|
||||||
os: ?string,
|
os: ?OS,
|
||||||
): ?PersistedState {
|
): ?PersistedState {
|
||||||
const persistedStateReducer = persistingPlugin.persistedStateReducer;
|
const persistedStateReducer = persistingPlugin.persistedStateReducer;
|
||||||
if (!os || !persistedStateReducer) {
|
if (!os || !persistedStateReducer) {
|
||||||
@@ -145,9 +145,9 @@ export function parseCrashLogAndUpdateState(
|
|||||||
export function shouldShowCrashNotification(
|
export function shouldShowCrashNotification(
|
||||||
baseDevice: ?BaseDevice,
|
baseDevice: ?BaseDevice,
|
||||||
content: string,
|
content: string,
|
||||||
os: ?string,
|
os: ?OS,
|
||||||
): boolean {
|
): boolean {
|
||||||
if (os && os.includes('Android')) {
|
if (os && os === 'Android') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const appPath = parsePath(content);
|
const appPath = parsePath(content);
|
||||||
@@ -159,9 +159,10 @@ export function shouldShowCrashNotification(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseCrashLog(content: string, os: string): CrashLog {
|
export function parseCrashLog(content: string, os: OS): CrashLog {
|
||||||
const stubString = 'Cannot figure out the cause';
|
const stubString = 'Cannot figure out the cause';
|
||||||
if (os.includes('iOS')) {
|
switch (os) {
|
||||||
|
case 'iOS': {
|
||||||
const regex = /Exception Type: *[\w]*/;
|
const regex = /Exception Type: *[\w]*/;
|
||||||
const arr = regex.exec(content);
|
const arr = regex.exec(content);
|
||||||
const exceptionString = arr ? arr[0] : '';
|
const exceptionString = arr ? arr[0] : '';
|
||||||
@@ -175,7 +176,8 @@ export function parseCrashLog(content: string, os: string): CrashLog {
|
|||||||
reason: exception,
|
reason: exception,
|
||||||
};
|
};
|
||||||
return crash;
|
return crash;
|
||||||
} else if (os.includes('Android')) {
|
}
|
||||||
|
case 'Android': {
|
||||||
const regForName = /.*\n/;
|
const regForName = /.*\n/;
|
||||||
const nameRegArr = regForName.exec(content);
|
const nameRegArr = regForName.exec(content);
|
||||||
let name = nameRegArr ? nameRegArr[0] : stubString;
|
let name = nameRegArr ? nameRegArr[0] : stubString;
|
||||||
@@ -201,7 +203,10 @@ export function parseCrashLog(content: string, os: string): CrashLog {
|
|||||||
};
|
};
|
||||||
return crash;
|
return crash;
|
||||||
}
|
}
|
||||||
|
default: {
|
||||||
throw new Error('Unsupported OS');
|
throw new Error('Unsupported OS');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parsePath(content: string): ?string {
|
export function parsePath(content: string): ?string {
|
||||||
|
|||||||
Reference in New Issue
Block a user