Decouple open/save dialogs, reload, shouldUseDarkColors from Electron
Summary: Per title. Less imports from Electron. Reviewed By: timur-valiev, aigoncharov Differential Revision: D31923504 fbshipit-source-id: dc7557cf7c88c0c8168ba22f7dca7b3e2d339a09
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d5e4b0c360
commit
9763af4c96
@@ -10,7 +10,7 @@
|
||||
import fs from 'fs';
|
||||
// eslint-disable-next-line
|
||||
import electron, {OpenDialogOptions, remote} from 'electron';
|
||||
import {Atom, DataTableManager} from 'flipper-plugin';
|
||||
import {Atom, DataTableManager, getFlipperLib} from 'flipper-plugin';
|
||||
import {createContext} from 'react';
|
||||
import {Header, Request} from '../types';
|
||||
import {message} from 'antd';
|
||||
@@ -137,16 +137,13 @@ export function createNetworkManager(
|
||||
informClientMockChange(routes.get());
|
||||
},
|
||||
importRoutes() {
|
||||
const options: OpenDialogOptions = {
|
||||
properties: ['openFile'],
|
||||
filters: [{extensions: ['json'], name: 'Flipper Route Files'}],
|
||||
};
|
||||
remote.dialog
|
||||
.showOpenDialog(options)
|
||||
.then((result) => {
|
||||
const filePaths = result.filePaths;
|
||||
if (filePaths.length > 0) {
|
||||
fs.readFile(filePaths[0], 'utf8', (err, data) => {
|
||||
getFlipperLib()
|
||||
.showOpenDialog?.({
|
||||
filter: {extensions: ['json'], name: 'Flipper Route Files'},
|
||||
})
|
||||
.then((filePath) => {
|
||||
if (filePath) {
|
||||
fs.readFile(filePath, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
message.error('Unable to import file');
|
||||
return;
|
||||
@@ -177,17 +174,12 @@ export function createNetworkManager(
|
||||
);
|
||||
},
|
||||
exportRoutes() {
|
||||
remote.dialog
|
||||
.showSaveDialog(
|
||||
// @ts-ignore This appears to work but isn't allowed by the types
|
||||
null,
|
||||
{
|
||||
title: 'Export Routes',
|
||||
defaultPath: 'NetworkPluginRoutesExport.json',
|
||||
},
|
||||
)
|
||||
.then((result: electron.SaveDialogReturnValue) => {
|
||||
const file = result.filePath;
|
||||
getFlipperLib()
|
||||
.showSaveDialog?.({
|
||||
title: 'Export Routes',
|
||||
defaultPath: 'NetworkPluginRoutesExport.json',
|
||||
})
|
||||
.then((file) => {
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user