Separate the concepts of archived and disconnected devices
Summary: Minor code cleanup to avoid future confusion: - archived: a device that was imported from a Flipper trace, and only has persisted state - (dis)connected: a real stateful device that might or might not have an active connection Reviewed By: nikoant Differential Revision: D26275459 fbshipit-source-id: eba554b37c39711e367c3795ff4456329a303c22
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1bb1cae167
commit
43c68c0e7c
@@ -13,6 +13,8 @@ import {OS, DeviceShell} from './BaseDevice';
|
||||
import {SupportFormRequestDetailsState} from '../reducers/supportForm';
|
||||
|
||||
export default class ArchivedDevice extends BaseDevice {
|
||||
isArchived = true;
|
||||
|
||||
constructor(options: {
|
||||
serial: string;
|
||||
deviceType: DeviceType;
|
||||
@@ -23,7 +25,7 @@ export default class ArchivedDevice extends BaseDevice {
|
||||
supportRequestDetails?: SupportFormRequestDetailsState;
|
||||
}) {
|
||||
super(options.serial, options.deviceType, options.title, options.os);
|
||||
this.archivedState.set(true);
|
||||
this.connected.set(false);
|
||||
this.source = options.source || '';
|
||||
this.supportRequestDetails = options.supportRequestDetails;
|
||||
this.archivedScreenshotHandle = options.screenshotHandle;
|
||||
|
||||
@@ -38,6 +38,8 @@ export type DeviceExport = {
|
||||
};
|
||||
|
||||
export default class BaseDevice {
|
||||
isArchived = false;
|
||||
|
||||
constructor(
|
||||
serial: string,
|
||||
deviceType: DeviceType,
|
||||
@@ -72,10 +74,7 @@ export default class BaseDevice {
|
||||
|
||||
logListeners: Map<Symbol, DeviceLogListener> = new Map();
|
||||
|
||||
archivedState = createState(false);
|
||||
get isArchived() {
|
||||
return this.archivedState.get();
|
||||
}
|
||||
readonly connected = createState(true);
|
||||
|
||||
// if imported, stores the original source location
|
||||
source = '';
|
||||
@@ -93,7 +92,7 @@ export default class BaseDevice {
|
||||
}
|
||||
|
||||
displayTitle(): string {
|
||||
return this.title;
|
||||
return this.connected.get() ? this.title : `${this.title} (Offline)`;
|
||||
}
|
||||
|
||||
async exportState(
|
||||
@@ -226,7 +225,7 @@ export default class BaseDevice {
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
this.archivedState.set(true);
|
||||
this.connected.set(false);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
|
||||
@@ -53,7 +53,7 @@ export default class IOSDevice extends BaseDevice {
|
||||
}
|
||||
|
||||
async screenshot(): Promise<Buffer> {
|
||||
if (this.isArchived) {
|
||||
if (!this.connected.get()) {
|
||||
return Buffer.from([]);
|
||||
}
|
||||
const tmpImageName = uuid() + '.png';
|
||||
@@ -192,7 +192,7 @@ export default class IOSDevice extends BaseDevice {
|
||||
}
|
||||
|
||||
async screenCaptureAvailable() {
|
||||
return this.deviceType === 'emulator' && !this.isArchived;
|
||||
return this.deviceType === 'emulator' && this.connected.get();
|
||||
}
|
||||
|
||||
async startScreenCapture(destination: string) {
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
import {LogLevel} from 'flipper-plugin';
|
||||
import BaseDevice from './BaseDevice';
|
||||
import ArchivedDevice from './ArchivedDevice';
|
||||
import {EventEmitter} from 'events';
|
||||
|
||||
// From xplat/js/metro/packages/metro/src/lib/reporting.js
|
||||
@@ -198,14 +197,4 @@ export default class MetroDevice extends BaseDevice {
|
||||
console.warn('Cannot send command, no connection', command);
|
||||
}
|
||||
}
|
||||
|
||||
archive() {
|
||||
return new ArchivedDevice({
|
||||
serial: this.serial,
|
||||
deviceType: this.deviceType,
|
||||
title: this.title,
|
||||
os: this.os,
|
||||
screenshotHandle: null,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user