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 Logger from './fb-stubs/Logger.js';
|
||||
import type {Store} from './reducers/index.js';
|
||||
|
||||
import type {OS} from './devices/BaseDevice.js';
|
||||
import {FlipperDevicePlugin} from './plugin.js';
|
||||
import {setPluginState} from './reducers/pluginStates.js';
|
||||
import {ReactiveSocket, PartialResponder} from 'rsocket-core';
|
||||
@@ -22,7 +22,7 @@ type Plugins = Array<string>;
|
||||
|
||||
export type ClientQuery = {|
|
||||
app: string,
|
||||
os: string,
|
||||
os: OS,
|
||||
device: string,
|
||||
device_id: string,
|
||||
|};
|
||||
|
||||
@@ -36,6 +36,8 @@ export type DeviceLogListener = (entry: DeviceLogEntry) => void;
|
||||
|
||||
export type DeviceType = 'emulator' | 'physical';
|
||||
|
||||
export type OS = 'iOS' | 'Android' | 'Windows';
|
||||
|
||||
export default class BaseDevice {
|
||||
constructor(serial: string, deviceType: DeviceType, title: string) {
|
||||
this.serial = serial;
|
||||
@@ -44,7 +46,7 @@ export default class BaseDevice {
|
||||
}
|
||||
|
||||
// operating system of this device
|
||||
os: string;
|
||||
os: OS;
|
||||
|
||||
// human readable name for this device
|
||||
title: string;
|
||||
@@ -61,7 +63,7 @@ export default class BaseDevice {
|
||||
logListeners: Map<Symbol, DeviceLogListener> = new Map();
|
||||
logEntries: Array<DeviceLogEntry> = [];
|
||||
|
||||
supportsOS(os: string) {
|
||||
supportsOS(os: OS) {
|
||||
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 Device} from './devices/BaseDevice.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 path from 'path';
|
||||
import type {Notification} from '../../plugin';
|
||||
import type {Store, DeviceLogEntry} from 'flipper';
|
||||
import type {Store, DeviceLogEntry, OS} from 'flipper';
|
||||
|
||||
export type Crash = {|
|
||||
notificationID: string,
|
||||
@@ -82,7 +82,7 @@ export function getNewPersisitedStateFromCrashLog(
|
||||
persistedState: ?PersistedState,
|
||||
persistingPlugin: Class<FlipperDevicePlugin<> | FlipperPlugin<>>,
|
||||
content: string,
|
||||
os: ?string,
|
||||
os: ?OS,
|
||||
): ?PersistedState {
|
||||
const persistedStateReducer = persistingPlugin.persistedStateReducer;
|
||||
if (!os || !persistedStateReducer) {
|
||||
@@ -145,9 +145,9 @@ export function parseCrashLogAndUpdateState(
|
||||
export function shouldShowCrashNotification(
|
||||
baseDevice: ?BaseDevice,
|
||||
content: string,
|
||||
os: ?string,
|
||||
os: ?OS,
|
||||
): boolean {
|
||||
if (os && os.includes('Android')) {
|
||||
if (os && os === 'Android') {
|
||||
return true;
|
||||
}
|
||||
const appPath = parsePath(content);
|
||||
@@ -159,9 +159,10 @@ export function shouldShowCrashNotification(
|
||||
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';
|
||||
if (os.includes('iOS')) {
|
||||
switch (os) {
|
||||
case 'iOS': {
|
||||
const regex = /Exception Type: *[\w]*/;
|
||||
const arr = regex.exec(content);
|
||||
const exceptionString = arr ? arr[0] : '';
|
||||
@@ -175,7 +176,8 @@ export function parseCrashLog(content: string, os: string): CrashLog {
|
||||
reason: exception,
|
||||
};
|
||||
return crash;
|
||||
} else if (os.includes('Android')) {
|
||||
}
|
||||
case 'Android': {
|
||||
const regForName = /.*\n/;
|
||||
const nameRegArr = regForName.exec(content);
|
||||
let name = nameRegArr ? nameRegArr[0] : stubString;
|
||||
@@ -201,7 +203,10 @@ export function parseCrashLog(content: string, os: string): CrashLog {
|
||||
};
|
||||
return crash;
|
||||
}
|
||||
default: {
|
||||
throw new Error('Unsupported OS');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function parsePath(content: string): ?string {
|
||||
|
||||
Reference in New Issue
Block a user