|
1 | 1 | import React, { Component } from 'react'; |
2 | | -import { remote } from 'electron'; |
3 | | -import fs from 'fs'; |
| 2 | +// import { remote } from 'electron'; |
| 3 | +// import fs from 'fs'; |
4 | 4 | import GRPCAutoInputForm from "./GRPCAutoInputForm.jsx"; |
5 | | -import protoParserFunc from "../../../../client/protoParser.js"; |
| 5 | +// import protoParserFunc from "../../../protoParser.js"; |
6 | 6 | import dropDownArrow from '../../../../assets/icons/arrow_drop_down_white_192x192.png'; |
7 | 7 |
|
| 8 | +const { api } = window; |
| 9 | + |
8 | 10 | class GRPCProtoEntryForm extends Component { |
9 | 11 | constructor(props) { |
10 | 12 | super(props); |
@@ -44,30 +46,43 @@ class GRPCProtoEntryForm extends Component { |
44 | 46 | protoContent: '' |
45 | 47 | }); |
46 | 48 | } |
47 | | - // use electron dialog to import files that has .proto ext only |
48 | | - remote.dialog.showOpenDialog({ |
49 | | - buttonLabel : "Import Proto File", |
50 | | - properties: ['openFile', 'multiSelections'], |
51 | | - filters: [ { name: 'Protos', extensions: ['proto'] } ] |
52 | | - }) |
53 | | - .then(filePaths => { |
54 | | - if (!filePaths) return; |
55 | | - // read uploaded proto file & save protoContent in the store |
56 | | - const importedProto = fs.readFileSync(filePaths.filePaths[0], 'utf-8'); |
| 49 | + |
| 50 | + api.receive('proto-info', (readProto, parsedProto) => { |
| 51 | + console.log('received from main readProto : ', readProto, 'and parsed Proto : ', parsedProto) |
57 | 52 | this.props.setNewRequestStreams({ |
58 | 53 | ...this.props.newRequestStreams, |
59 | | - protoContent: importedProto |
| 54 | + protoContent: readProto, |
| 55 | + services: parsedProto.serviceArr, |
| 56 | + protoPath: parsedProto.protoPath |
60 | 57 | }); |
61 | | - // parse proto file via protoParserFunc imported from protoParser.js & save parsed proto file details in the store |
62 | | - protoParserFunc(this.props.newRequestStreams.protoContent) |
63 | | - .then(data => { |
64 | | - this.props.setNewRequestStreams({ |
65 | | - ...this.props.newRequestStreams, |
66 | | - services: data.serviceArr, |
67 | | - protoPath: data.protoPath |
68 | | - }) |
69 | | - }).catch((err) => console.log(err)); |
70 | 58 | }); |
| 59 | + |
| 60 | + api.send('import-proto'); |
| 61 | + |
| 62 | + // // use electron dialog to import files that has .proto ext only |
| 63 | + // remote.dialog.showOpenDialog({ |
| 64 | + // buttonLabel : "Import Proto File", |
| 65 | + // properties: ['openFile', 'multiSelections'], |
| 66 | + // filters: [ { name: 'Protos', extensions: ['proto'] } ] |
| 67 | + // }) |
| 68 | + // .then(filePaths => { |
| 69 | + // if (!filePaths) return; |
| 70 | + // // read uploaded proto file & save protoContent in the store |
| 71 | + // const importedProto = fs.readFileSync(filePaths.filePaths[0], 'utf-8'); |
| 72 | + // this.props.setNewRequestStreams({ |
| 73 | + // ...this.props.newRequestStreams, |
| 74 | + // protoContent: importedProto |
| 75 | + // }); |
| 76 | + // // parse proto file via protoParserFunc imported from protoParser.js & save parsed proto file details in the store |
| 77 | + // protoParserFunc(this.props.newRequestStreams.protoContent) |
| 78 | + // .then(data => { |
| 79 | + // this.props.setNewRequestStreams({ |
| 80 | + // ...this.props.newRequestStreams, |
| 81 | + // services: data.serviceArr, |
| 82 | + // protoPath: data.protoPath |
| 83 | + // }) |
| 84 | + // }).catch((err) => console.log(err)); |
| 85 | + // }); |
71 | 86 | } |
72 | 87 |
|
73 | 88 | // saves protoContent in the store whenever client make changes to proto file or pastes a copy |
|
0 commit comments