Migrate application from js to tsx

Summary: As per the title

Reviewed By: jknoxville

Differential Revision: D16690005

fbshipit-source-id: 8975da8aa7221b731358eacb4040f48198bf073b
This commit is contained in:
Pritesh Nandgaonkar
2019-08-09 07:47:34 -07:00
committed by Facebook Github Bot
parent 03b5b133b8
commit c3807a6ba2
3 changed files with 11 additions and 11 deletions

View File

@@ -0,0 +1,107 @@
/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
import {remote, ipcRenderer} from 'electron';
import {toggleAction} from '../reducers/application';
import {Store} from '../reducers/index.js';
import {Logger} from '../fb-interfaces/Logger.js';
import {parseFlipperPorts} from '../utils/environmentVariables';
import {
importDataToStore,
importFileToStore,
IMPORT_FLIPPER_TRACE_EVENT,
} from '../utils/exportData';
import {tryCatchReportPlatformFailures} from '../utils/metrics';
import {selectPlugin} from '../reducers/connections';
import qs from 'query-string';
export const uriComponents = (url: string): Array<string> => {
if (!url) {
return [];
}
const match: Array<string> | undefined | null = url.match(
/^flipper:\/\/([^\/]*)\/([^\/]*)\/?(.*)$/,
);
if (match) {
return match
.map(decodeURIComponent)
.slice(1)
.filter(Boolean);
}
return [];
};
export default (store: Store, logger: Logger) => {
const currentWindow = remote.getCurrentWindow();
currentWindow.on('focus', () => {
store.dispatch({
type: 'windowIsFocused',
payload: true,
});
});
currentWindow.on('blur', () => {
store.dispatch({
type: 'windowIsFocused',
payload: false,
});
});
ipcRenderer.on('flipper-protocol-handler', (event, url) => {
if (url.startsWith('flipper://import')) {
const {search} = new URL(url);
const download = qs.parse(search) ? qs.parse(search) : undefined;
store.dispatch(toggleAction('downloadingImportData', true));
return (
download &&
fetch(String(download))
.then(res => res.text())
.then(data => importDataToStore(data, store))
.then(() => {
store.dispatch(toggleAction('downloadingImportData', false));
})
.catch((e: Error) => {
console.error(e);
store.dispatch(toggleAction('downloadingImportData', false));
})
);
}
const match = uriComponents(url);
if (match.length > 1) {
// flipper://<client>/<pluginId>/<payload>
return store.dispatch(
selectPlugin({
selectedApp: match[0],
selectedPlugin: match[1],
deepLinkPayload: match[2],
}),
);
}
});
ipcRenderer.on('open-flipper-file', (event, url) => {
tryCatchReportPlatformFailures(() => {
return importFileToStore(url, store);
}, `${IMPORT_FLIPPER_TRACE_EVENT}:Deeplink`);
});
if (process.env.FLIPPER_PORTS) {
const portOverrides = parseFlipperPorts(process.env.FLIPPER_PORTS);
if (portOverrides) {
store.dispatch({
type: 'SET_SERVER_PORTS',
payload: portOverrides,
});
} else {
console.error(
`Ignoring malformed FLIPPER_PORTS env variable:
"${process.env.FLIPPER_PORTS || ''}".
Example expected format: "1111,2222".`,
);
}
}
};