electron - work with exported files

This commit is contained in:
Jan Prochazka
2020-06-07 18:42:21 +02:00
parent 2f363f6969
commit 22fa92520d
3 changed files with 68 additions and 15 deletions

View File

@@ -54,12 +54,16 @@ module.exports = {
DBGATE_API: process.argv[1], DBGATE_API: process.argv[1],
}, },
}); });
subprocess.stdout.on('data', (data) => this.dispatchMessage(runid, data.toString())); const pipeDispatcher = (severity) => (data) =>
subprocess.stderr.on('data', (data) => data
data.toString.split('\n').forEach((message) => { .toString()
this.dispatchMessage(runid, { severity: 'error', message }); .split('\n')
}) .forEach((message) => {
); if (message.trim()) this.dispatchMessage(runid, { severity, message: message.trim() });
});
subprocess.stdout.on('data', pipeDispatcher('info'));
subprocess.stderr.on('data', pipeDispatcher('error'));
subprocess.on('exit', (code) => { subprocess.on('exit', (code) => {
socket.emit(`runner-done-${runid}`, code); socket.emit(`runner-done-${runid}`, code);
}); });
@@ -101,6 +105,7 @@ module.exports = {
res.push({ res.push({
name: file, name: file,
size: stat.size, size: stat.size,
path: path.join(directory, file),
}); });
} }
return res; return res;

View File

@@ -5,6 +5,7 @@ import styled from 'styled-components';
import TableControl, { TableColumn } from '../utility/TableControl'; import TableControl, { TableColumn } from '../utility/TableControl';
import formatFileSize from '../utility/formatFileSize'; import formatFileSize from '../utility/formatFileSize';
import resolveApi from '../utility/resolveApi'; import resolveApi from '../utility/resolveApi';
import getElectron from '../utility/getElectron';
export default function RunnerOutputFiles({ runnerId, executeNumber }) { export default function RunnerOutputFiles({ runnerId, executeNumber }) {
const socket = useSocket(); const socket = useSocket();
@@ -28,19 +29,59 @@ export default function RunnerOutputFiles({ runnerId, executeNumber }) {
setFiles([]); setFiles([]);
}, [executeNumber]); }, [executeNumber]);
const electron = getElectron();
return ( return (
<TableControl rows={files}> <TableControl rows={files}>
<TableColumn fieldName="name" header="Name" /> <TableColumn fieldName="name" header="Name" />
<TableColumn fieldName="size" header="Size" formatter={(row) => formatFileSize(row.size)} /> <TableColumn fieldName="size" header="Size" formatter={(row) => formatFileSize(row.size)} />
<TableColumn {!electron && (
fieldName="download" <TableColumn
header="Download" fieldName="download"
formatter={(row) => ( header="Download"
<a href={`${resolveApi()}/runners/data/${runnerId}/${row.name}`} target="_blank" rel="noopener noreferrer"> formatter={(row) => (
download <a href={`${resolveApi()}/runners/data/${runnerId}/${row.name}`} target="_blank" rel="noopener noreferrer">
</a> download
)} </a>
/> )}
/>
)}
{electron && (
<TableColumn
fieldName="copy"
header="Copy"
formatter={(row) => (
<a
href="#"
onClick={() => {
const file = electron.remote.dialog.showSaveDialogSync(electron.remote.getCurrentWindow(), {});
if (file) {
const fs = window.require('fs');
fs.copyFile(row.path, file, () => {});
}
}}
>
save
</a>
)}
/>
)}
{electron && (
<TableColumn
fieldName="show"
header="Show"
formatter={(row) => (
<a
href="#"
onClick={() => {
electron.remote.shell.showItemInFolder(row.path);
}}
>
show
</a>
)}
/>
)}
</TableControl> </TableControl>
); );
} }

View File

@@ -0,0 +1,7 @@
export default function getElectron() {
if (window.require) {
const electron = window.require('electron');
return electron;
}
return null;
}