Skip to content

Commit

Permalink
Merge branch 'main' into update-electron
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis authored Jan 27, 2022
2 parents 50b2eca + 08c09e6 commit 2c540b1
Show file tree
Hide file tree
Showing 56 changed files with 571 additions and 690 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ ext.deps = [
robolectric : 'org.robolectric:robolectric:4.5.1',
junit : 'junit:junit:4.13.2',
hamcrest : 'org.hamcrest:hamcrest-library:2.2',
mockito : 'org.mockito:mockito-core:4.2.0',
mockito : 'org.mockito:mockito-core:4.3.0',
okhttp3 : 'com.squareup.okhttp3:okhttp:4.9.3',
leakcanary : 'com.squareup.leakcanary:leakcanary-android:1.6.3',
leakcanary2 : 'com.squareup.leakcanary:leakcanary-android:2.6',
Expand Down
12 changes: 6 additions & 6 deletions desktop/babel-transformer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
"license": "MIT",
"bugs": "https://github.com/facebook/flipper/issues",
"dependencies": {
"@babel/core": "^7.16.7",
"@babel/generator": "^7.16.7",
"@babel/parser": "^7.16.7",
"@babel/core": "^7.16.12",
"@babel/generator": "^7.16.8",
"@babel/parser": "^7.16.12",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7",
"@babel/plugin-proposal-object-rest-spread": "^7.16.7",
"@babel/plugin-proposal-optional-chaining": "^7.16.7",
"@babel/plugin-transform-flow-strip-types": "^7.16.7",
"@babel/plugin-transform-modules-commonjs": "^7.16.7",
"@babel/plugin-transform-typescript": "^7.16.7",
"@babel/preset-env": "^7.16.8",
"@babel/plugin-transform-typescript": "^7.16.8",
"@babel/preset-env": "^7.16.11",
"@babel/preset-react": "^7.16.7",
"@babel/traverse": "^7.16.7",
"@babel/traverse": "^7.16.10",
"@babel/types": "^7.16.7",
"@emotion/babel-plugin": "^11.7.2",
"@types/fs-extra": "^9.0.13",
Expand Down
29 changes: 12 additions & 17 deletions desktop/flipper-dump/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@ const argv = yargs
.usage('$0 [args]')
.options({
device: {
describe: 'The device name to listen to',
describe: 'The device name or serial/udid to listen to',
type: 'string',
demandOption: true,
},
client: {
describe: 'The application name to listen to',
type: 'string',
demandOption: true,
},
plugin: {
describe: 'Plugin id to listen to',
type: 'string',
demandOption: true,
},
// TODO: support filtering events
// TODO: support verbose mode
Expand All @@ -54,7 +57,7 @@ const argv = yargs
// .strict()
.parse(process.argv.slice(1));

async function start(deviceTitle: string, appName: string, pluginId: string) {
async function start(deviceQuery: string, appName: string, pluginId: string) {
return new Promise(async (_resolve, reject) => {
const staticPath = path.resolve(__dirname, '..', '..', 'static');
let device: DeviceDescription | undefined;
Expand Down Expand Up @@ -96,7 +99,7 @@ async function start(deviceTitle: string, appName: string, pluginId: string) {
);

logger.info(
`Waiting for device '${deviceTitle}' client '${appName}' plugin '${pluginId}' ...`,
`Waiting for device '${deviceQuery}' client '${appName}' plugin '${pluginId}' ...`,
);

server.on('notification', ({type, title, description}) => {
Expand All @@ -116,8 +119,12 @@ async function start(deviceTitle: string, appName: string, pluginId: string) {
logger.info(
`Detected device [${deviceInfo.os}] ${deviceInfo.title} ${deviceInfo.serial}`,
);
if (deviceInfo.title === deviceTitle) {
logger.info('Device matched');
if (deviceInfo.serial == deviceQuery) {
logger.info(`Device matched on device serial ${deviceQuery}`);
device = deviceInfo;
deviceResolver();
} else if (deviceInfo.title === deviceQuery) {
logger.info(`Device matched on device title ${deviceQuery}`);
device = deviceInfo;
deviceResolver();
}
Expand Down Expand Up @@ -250,18 +257,6 @@ function createLogger(): Logger {
};
}

if (!argv.device) {
console.error('--device not specified');
process.exit(1);
}
if (!argv.client) {
console.error('--client not specified');
process.exit(1);
}
if (!argv.plugin) {
console.error('--plugin not specified');
process.exit(1);
}
start(argv.device!, argv.client!, argv.plugin!).catch((e) => {
// eslint-disable-next-line
console.error(e);
Expand Down
4 changes: 2 additions & 2 deletions desktop/flipper-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"@types/react-dom": "^17.0.11",
"eventemitter3": "^4.0.7",
"flipper-common": "0.0.0",
"immer": "^9.0.7",
"immer": "^9.0.12",
"js-base64": "^3.7.2",
"lodash": "^4.17.21",
"react-color": "^2.19.3",
"react-element-to-jsx-string": "^14.3.4",
"react-virtual": "^2.10.0",
"react-virtual": "^2.10.4",
"string-natural-compare": "^3.0.0",
"uuid": "^8.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion desktop/flipper-server-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"tmp": "^0.2.1",
"uuid": "^8.3.2",
"which": "^2.0.2",
"ws": "^8.4.0",
"ws": "^8.4.2",
"xdg-basedir": "^4.0.0"
},
"devDependencies": {
Expand Down
13 changes: 11 additions & 2 deletions desktop/flipper-server-core/src/FlipperServerImpl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,18 @@ export class FlipperServerImpl implements FlipperServer {
}

async startDeviceListeners() {
const asyncDeviceListenersPromises: Array<Promise<void>> = [];
if (this.config.settings.enableAndroid) {
asyncDeviceListenersPromises.push(this.android.watchAndroidDevices());
}
if (this.config.settings.enableIOS) {
asyncDeviceListenersPromises.push(this.ios.watchIOSDevices());
}
const asyncDeviceListeners = await Promise.all(
asyncDeviceListenersPromises,
);
this.disposers.push(
await this.android.watchAndroidDevices(),
await this.ios.watchIOSDevices(),
...asyncDeviceListeners,
metroDevice(this),
desktopDevice(this),
);
Expand Down
6 changes: 1 addition & 5 deletions desktop/flipper-server-core/src/comms/ServerController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ class ServerController extends EventEmitter implements ServerEventsListener {
constructor(flipperServer: FlipperServerImpl) {
super();
this.flipperServer = flipperServer;
this.certificateProvider = new CertificateProvider(
this,
getFlipperServerConfig().settings,
);
this.certificateProvider = new CertificateProvider(this);
this.connectionTracker = new ConnectionTracker(this.logger);
}

Expand All @@ -116,7 +113,6 @@ class ServerController extends EventEmitter implements ServerEventsListener {
if (isTest()) {
throw new Error('Spawing new server is not supported in test');
}
await this.certificateProvider.init();
const {insecure, secure} = getServerPortsConfig().serverPorts;

const options = await this.certificateProvider.loadSecureServerConfig();
Expand Down
24 changes: 17 additions & 7 deletions desktop/flipper-server-core/src/devices/android/adbClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,29 @@ import adbConfig from './adbConfig';
import adbkit, {Client} from 'adbkit';
import path from 'path';

let instance: Client;
let instance: Client | undefined;

type Config = {
androidHome: string;
};

export async function getAdbClient(config: Config): Promise<Client> {
if (!instance) {
instance = await reportPlatformFailures(
createClient(config),
'createADBClient',
export function getAdbClient(): Client | undefined {
return instance;
}

export async function setAdbClient(
config: Config,
): Promise<Client | undefined> {
instance = await reportPlatformFailures(
createClient(config),
'createADBClient',
).catch((e) => {
console.warn(
'Failed to initialize ADB. Please disable Android support in settings, or configure a correct path.',
e,
);
}
return undefined;
});
return instance;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import AndroidDevice from './AndroidDevice';
import KaiOSDevice from './KaiOSDevice';
import child_process from 'child_process';
import {getAdbClient} from './adbClient';
import which from 'which';
import {promisify} from 'util';
import {setAdbClient} from './adbClient';
import {Client as ADBClient, Device} from 'adbkit';
import {join} from 'path';
import {FlipperServerImpl} from '../../FlipperServerImpl';
Expand Down Expand Up @@ -172,7 +170,13 @@ export class AndroidDeviceManager {

async watchAndroidDevices() {
try {
const client = await getAdbClient(getFlipperServerConfig().settings);
const client = await setAdbClient(getFlipperServerConfig().settings);
if (!client) {
throw new Error(
'AndroidDeviceManager.watchAndroidDevices -> adb not initialized',
);
}

client
.trackDevices()
.then((tracker) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ test('test getAllPromisesForQueryingDevices when xcode detected', () => {
getLogger(),
);
flipperServer.ios.iosBridge = {} as IOSBridge;
(flipperServer.ios as any).idbConfig = getFlipperServerConfig().settings;
const promises = flipperServer.ios.getAllPromisesForQueryingDevices(
true,
false,
Expand All @@ -85,6 +86,7 @@ test('test getAllPromisesForQueryingDevices when xcode is not detected', () => {
getLogger(),
);
flipperServer.ios.iosBridge = {} as IOSBridge;
(flipperServer.ios as any).idbConfig = getFlipperServerConfig().settings;
const promises = flipperServer.ios.getAllPromisesForQueryingDevices(
false,
true,
Expand All @@ -98,6 +100,7 @@ test('test getAllPromisesForQueryingDevices when xcode and idb are both unavaila
getLogger(),
);
flipperServer.ios.iosBridge = {} as IOSBridge;
(flipperServer.ios as any).idbConfig = getFlipperServerConfig().settings;
const promises = flipperServer.ios.getAllPromisesForQueryingDevices(
false,
false,
Expand All @@ -111,6 +114,7 @@ test('test getAllPromisesForQueryingDevices when both idb and xcode are availabl
getLogger(),
);
flipperServer.ios.iosBridge = {} as IOSBridge;
(flipperServer.ios as any).idbConfig = getFlipperServerConfig().settings;
const promises = flipperServer.ios.getAllPromisesForQueryingDevices(
true,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ async function targets(
if (process.platform !== 'darwin') {
return [];
}

const isXcodeInstalled = await isXcodeDetected();
if (!isXcodeInstalled) {
if (!isPhysicalDeviceEnabled) {
Expand Down Expand Up @@ -203,6 +204,7 @@ async function push(
idbPath: string,
): Promise<void> {
await memoize(checkIdbIsInstalled)(idbPath);

return wrapWithErrorMessage(
reportPlatformFailures(
safeExec(
Expand All @@ -225,6 +227,7 @@ async function pull(
idbPath: string,
): Promise<void> {
await memoize(checkIdbIsInstalled)(idbPath);

return wrapWithErrorMessage(
reportPlatformFailures(
safeExec(
Expand Down
25 changes: 13 additions & 12 deletions desktop/flipper-server-core/src/devices/ios/iOSDeviceManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
import {FlipperServerImpl} from '../../FlipperServerImpl';
import {notNull} from '../../utils/typeUtils';
import {getFlipperServerConfig} from '../../FlipperServerConfig';
import {IdbConfig, setIdbConfig} from './idbConfig';
import {assertNotNull} from 'flipper-server-core/src/comms/Utilities';

type iOSSimulatorDevice = {
state: 'Booted' | 'Shutdown' | 'Shutting Down';
Expand All @@ -44,6 +46,7 @@ function isAvailable(simulator: iOSSimulatorDevice): boolean {

export class IOSDeviceManager {
private portForwarders: Array<ChildProcess> = [];
private idbConfig?: IdbConfig;

private portforwardingClient = path.join(
getFlipperServerConfig().paths.staticPath,
Expand Down Expand Up @@ -107,14 +110,15 @@ export class IOSDeviceManager {
isXcodeDetected: boolean,
isIdbAvailable: boolean,
): Array<Promise<any>> {
const config = getFlipperServerConfig().settings;
assertNotNull(this.idbConfig);
return [
isIdbAvailable
? getActiveDevices(config.idbPath, config.enablePhysicalIOS).then(
(devices: IOSDeviceParams[]) => {
this.processDevices(devices);
},
)
? getActiveDevices(
this.idbConfig.idbPath,
this.idbConfig.enablePhysicalIOS,
).then((devices: IOSDeviceParams[]) => {
this.processDevices(devices);
})
: null,
!isIdbAvailable && isXcodeDetected
? this.getSimulators(true).then((devices) =>
Expand All @@ -126,9 +130,9 @@ export class IOSDeviceManager {
}

private async queryDevices(): Promise<any> {
const config = getFlipperServerConfig().settings;
assertNotNull(this.idbConfig);
const isXcodeInstalled = await iosUtil.isXcodeDetected();
const isIdbAvailable = await iosUtil.isAvailable(config.idbPath);
const isIdbAvailable = await iosUtil.isAvailable(this.idbConfig.idbPath);
console.debug(
`[conn] queryDevices. isXcodeInstalled ${isXcodeInstalled}, isIdbAvailable ${isIdbAvailable}`,
);
Expand Down Expand Up @@ -177,11 +181,8 @@ export class IOSDeviceManager {
}

public async watchIOSDevices() {
// TODO: pull this condition up
const settings = getFlipperServerConfig().settings;
if (!settings.enableIOS) {
return;
}
this.idbConfig = setIdbConfig(settings);
try {
const isDetected = await iosUtil.isXcodeDetected();
this.xcodeCommandLineToolsDetected = isDetected;
Expand Down
22 changes: 22 additions & 0 deletions desktop/flipper-server-core/src/devices/ios/idbConfig.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

export type IdbConfig = {
idbPath: string;
enablePhysicalIOS: boolean;
};

let idbConfig: IdbConfig | undefined;

export const getIdbConfig = () => idbConfig;

export const setIdbConfig = (newIdbConfig: IdbConfig) => {
idbConfig = newIdbConfig;
return idbConfig;
};
Loading

0 comments on commit 2c540b1

Please sign in to comment.