Bits & pieces
Summary: Added a command to let a file be opened by the OS, and some other small bits and pieces to make Flipper browser compatible. Reviewed By: lblasa Differential Revision: D32721748 fbshipit-source-id: a4ad1c2f662f4651ddf6c20c57e5af1e123914a8
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f5f9608098
commit
eab4f0d3d3
@@ -10,40 +10,13 @@
|
||||
import {Button as AntButton, message} from 'antd';
|
||||
import React, {useState, useEffect, useCallback} from 'react';
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import open from 'open';
|
||||
import {capture, getCaptureLocation, getFileName} from '../utils/screenshot';
|
||||
import {CameraOutlined, VideoCameraOutlined} from '@ant-design/icons';
|
||||
import {useStore} from '../utils/useStore';
|
||||
import {getRenderHostInstance} from '../RenderHost';
|
||||
|
||||
async function openFile(path: string | null) {
|
||||
if (!path) {
|
||||
return;
|
||||
}
|
||||
|
||||
let fileStat;
|
||||
try {
|
||||
fileStat = await fs.stat(path);
|
||||
} catch (err) {
|
||||
message.error(`Couldn't open captured file: ${path}: ${err}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Rather randomly chosen. Some FSs still reserve 8 bytes for empty files.
|
||||
// If this doesn't reliably catch "corrupt" files, you might want to increase this.
|
||||
if (fileStat.size <= 8) {
|
||||
message.error(
|
||||
'Screencap file retrieved from device appears to be corrupt. Your device may not support screen recording. Sometimes restarting your device can help.',
|
||||
0,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await open(path);
|
||||
} catch (e) {
|
||||
console.warn(`Opening ${path} failed with error ${e}.`);
|
||||
}
|
||||
async function openFile(path: string) {
|
||||
getRenderHostInstance().flipperServer.exec('open-file', path);
|
||||
}
|
||||
|
||||
export default function ScreenCaptureButtons() {
|
||||
@@ -92,7 +65,11 @@ export default function ScreenCaptureButtons() {
|
||||
} else {
|
||||
return selectedDevice
|
||||
.stopScreenCapture()
|
||||
.then(openFile)
|
||||
.then((f) => {
|
||||
if (f) {
|
||||
return openFile(f);
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error('Failed to start recording', e);
|
||||
message.error('Failed to start recording' + e);
|
||||
|
||||
@@ -22,20 +22,20 @@ export default (store: Store, logger: Logger) => {
|
||||
const renderHost = getRenderHostInstance();
|
||||
|
||||
const onFocus = () => {
|
||||
setImmediate(() => {
|
||||
setTimeout(() => {
|
||||
store.dispatch({
|
||||
type: 'windowIsFocused',
|
||||
payload: {isFocused: true, time: Date.now()},
|
||||
});
|
||||
});
|
||||
}, 1);
|
||||
};
|
||||
const onBlur = () => {
|
||||
setImmediate(() => {
|
||||
setTimeout(() => {
|
||||
store.dispatch({
|
||||
type: 'windowIsFocused',
|
||||
payload: {isFocused: false, time: Date.now()},
|
||||
});
|
||||
});
|
||||
}, 1);
|
||||
};
|
||||
window.addEventListener('focus', onFocus);
|
||||
window.addEventListener('blur', onBlur);
|
||||
|
||||
@@ -235,8 +235,7 @@ RootElement.displayName = 'SandyAppRootElement';
|
||||
|
||||
function registerStartupTime(logger: Logger) {
|
||||
// track time since launch
|
||||
const [s, ns] = process.hrtime();
|
||||
const launchEndTime = s * 1e3 + ns / 1e6;
|
||||
const launchEndTime = performance.now();
|
||||
const renderHost = getRenderHostInstance();
|
||||
renderHost.onIpcEvent('getLaunchTime', (launchStartTime: number) => {
|
||||
logger.track('performance', 'launchTime', launchEndTime - launchStartTime);
|
||||
|
||||
Reference in New Issue
Block a user