Export Skylinks to json file

This commit is contained in:
2021-03-18 23:26:31 -05:00
parent 41af3c4670
commit e8fb5bd53d
10 changed files with 96 additions and 10 deletions

View File

@@ -3,6 +3,7 @@
## 1.3.4 ## 1.3.4
- \#55: Enable 'Activate' release instead of 'Install' in notification pop-up - \#55: Enable 'Activate' release instead of 'Install' in notification pop-up
- Ability to export Skylink's to json file
## 1.3.3 ## 1.3.3

View File

@@ -17,3 +17,9 @@
white-space: pre; white-space: pre;
hyphens: none; hyphens: none;
} }
.InfoButtonOwner {
display: flex;
flex-direction: row;
justify-content: flex-end;
}

View File

@@ -1,9 +1,10 @@
import React from 'react'; import React from 'react';
import { dismissInfo } from '../../redux/actions/error_actions'; import { dismissInfo, notifyError } from '../../redux/actions/error_actions';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import Box from '../UI/Box/Box'; import Box from '../UI/Box/Box';
import Button from '../UI/Button/Button'; import Button from '../UI/Button/Button';
import './InfoDetails.css'; import './InfoDetails.css';
import { promptLocationAndSaveFile } from '../../utils';
const mapStateToProps = (state) => { const mapStateToProps = (state) => {
return { return {
@@ -14,6 +15,7 @@ const mapStateToProps = (state) => {
const mapDispatchToProps = (dispatch) => { const mapDispatchToProps = (dispatch) => {
return { return {
notifyError: (msg) => dispatch(notifyError(msg)),
dismissInfo: () => dispatch(dismissInfo()), dismissInfo: () => dispatch(dismissInfo()),
}; };
}; };
@@ -65,7 +67,30 @@ export default connect(
<p style={{ textAlign: 'left' }}>{msg}</p> <p style={{ textAlign: 'left' }}>{msg}</p>
)} )}
</div> </div>
{props.InfoMessage.saveToFile ? (
<div className={'InfoButtonOwner'}>
<Button clicked={props.dismissInfo}>Dismiss</Button> <Button clicked={props.dismissInfo}>Dismiss</Button>
<Button
buttonStyles={{ marginLeft: 'var(--default_spacing)' }}
clicked={() => {
if (
promptLocationAndSaveFile(
props.InfoMessage.fileName +
'.' +
props.InfoMessage.extension,
msg,
props.notifyError
)
) {
props.dismissInfo();
}
}}>
Save...
</Button>
</div>
) : (
<Button clicked={props.dismissInfo}>Dismiss</Button>
)}
</Box> </Box>
); );
}); });

View File

@@ -110,6 +110,8 @@ exports.INSTALL_TYPES = {
exports.IPC_Browse_Directory = 'browse_directory'; exports.IPC_Browse_Directory = 'browse_directory';
exports.IPC_Browse_File = 'browse_file';
exports.IPC_Check_Daemon_Version = 'check_daemon_version'; exports.IPC_Check_Daemon_Version = 'check_daemon_version';
exports.IPC_Check_Daemon_Version_Reply = 'check_daemon_version_reply'; exports.IPC_Check_Daemon_Version_Reply = 'check_daemon_version_reply';
@@ -179,6 +181,7 @@ exports.IPC_Remove_Mount_Reply = 'remove_mount_reply';
exports.IPC_Reboot_System = 'reboot_system'; exports.IPC_Reboot_System = 'reboot_system';
exports.IPC_Save_File = 'save_file';
exports.IPC_Save_State = 'save_state'; exports.IPC_Save_State = 'save_state';
exports.IPC_Set_Pinned = 'set_pinned'; exports.IPC_Set_Pinned = 'set_pinned';

View File

@@ -36,7 +36,8 @@ const mapDispatchToProps = (dispatch) => {
notifyApplicationBusy: (busy) => notifyApplicationBusy: (busy) =>
dispatch(notifyApplicationBusy(busy, true)), dispatch(notifyApplicationBusy(busy, true)),
notifyError: (msg) => dispatch(notifyError(msg)), notifyError: (msg) => dispatch(notifyError(msg)),
notifyInfo: (title, msg) => dispatch(notifyInfo(title, msg)), notifyInfo: (title, msg) =>
dispatch(notifyInfo(title, msg, true, 'skynet_export', 'json')),
}; };
}; };

View File

@@ -47,11 +47,11 @@ export const notifyError = (msg, critical, callback) => {
}; };
}; };
export const notifyInfo = (title, msg) => { export const notifyInfo = (title, msg, saveToFile, fileName, extension) => {
return (dispatch) => { return (dispatch) => {
title = title ? title.toString() : 'Information'; title = title ? title.toString() : 'Information';
msg = msg ? msg.toString() : ''; msg = msg ? msg.toString() : '';
dispatch(setInfo(title, msg)); dispatch(setInfo(title, msg, saveToFile, fileName, extension));
}; };
}; };
@@ -61,6 +61,9 @@ export const setErrorInfo = (msg, critical) => {
}; };
export const SET_INFO = 'error/setInfo'; export const SET_INFO = 'error/setInfo';
export const setInfo = (title, msg) => { export const setInfo = (title, msg, saveToFile, fileName, extension) => {
return { type: SET_INFO, payload: { title, msg } }; return {
type: SET_INFO,
payload: { title, msg, saveToFile, fileName, extension },
};
}; };

View File

@@ -44,7 +44,13 @@ export const errorReducer = createReducer(
}, },
[SET_INFO]: (state, action) => { [SET_INFO]: (state, action) => {
const infoStack = [ const infoStack = [
{ title: action.payload.title, message: action.payload.msg }, {
title: action.payload.title,
message: action.payload.msg,
saveToFile: action.payload.saveToFile,
fileName: action.payload.fileName,
extension: action.payload.extension,
},
...state.InfoStack, ...state.InfoStack,
]; ];
return { ...state, DisplayInfo: true, InfoStack: infoStack }; return { ...state, DisplayInfo: true, InfoStack: infoStack };

View File

@@ -20,13 +20,40 @@ const addListeners = (ipcMain, { getMainWindow, dialog }) => {
); );
}); });
ipcMain.on(Constants.IPC_Delete_File, (event, data) => { ipcMain.on(Constants.IPC_Delete_File, (_, data) => {
try { try {
if (fs.existsSync(data.FilePath)) { if (fs.existsSync(data.FilePath)) {
fs.unlinkSync(data.FilePath); fs.unlinkSync(data.FilePath);
} }
} catch (e) {} } catch (e) {}
}); });
ipcMain.on(Constants.IPC_Browse_File + '_sync', (event, data) => {
dialog.showSaveDialog(
getMainWindow(),
{
defaultPath: data.Location,
properties: ['createDirectory', 'showOverwriteConfirmation'],
title: data.Title,
},
(filePath) => {
if (filePath && filePath.length > 0) {
event.returnValue = filePath;
} else {
event.returnValue = '';
}
}
);
});
ipcMain.on(Constants.IPC_Save_File + '_sync', (event, data) => {
try {
fs.writeFileSync(data.Location, data.Data, 'utf8');
event.returnValue = { success: true };
} catch (err) {
event.returnValue = { success: false, error: err.toString() };
}
});
}; };
module.exports = { addListeners }; module.exports = { addListeners };

View File

@@ -74,7 +74,7 @@ const addListeners = (ipcMain) => {
}); });
}); });
ipcMain.on(Constants.IPC_Save_State, (event, data) => { ipcMain.on(Constants.IPC_Save_State, (_, data) => {
helpers.mkDirByPathSync(helpers.getDataDirectory()); helpers.mkDirByPathSync(helpers.getDataDirectory());
const configFile = path.join(helpers.getDataDirectory(), 'settings.json'); const configFile = path.join(helpers.getDataDirectory(), 'settings.json');
fs.writeFileSync(configFile, JSON.stringify(data.State), 'utf8'); fs.writeFileSync(configFile, JSON.stringify(data.State), 'utf8');

View File

@@ -132,3 +132,17 @@ export const getSelectedVersionFromState = (state) => {
state.relver.Version state.relver.Version
]; ];
}; };
export const promptLocationAndSaveFile = (fileName, data, notifyError) => {
const location = ipcRenderer.sendSync(Constants.IPC_Browse_File + '_sync', {Location: fileName, Title: 'Save File'});
if (location && location.length > 0) {
const ret = ipcRenderer.sendSync(Constants.IPC_Save_File + '_sync', {Location: location, Title: 'Save File', Data: data});
if (ret.success) {
return true;
}
notifyError(ret.error);
}
return false;
};