Import Skylinks from json file

This commit is contained in:
2021-03-18 23:57:03 -05:00
parent e8fb5bd53d
commit 59ad33b381
5 changed files with 69 additions and 4 deletions

View File

@@ -4,6 +4,7 @@
- \#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 - Ability to export Skylink's to json file
- Ability to import Skylink's from json file
## 1.3.3 ## 1.3.3

View File

@@ -109,9 +109,10 @@ exports.INSTALL_TYPES = {
}; };
exports.IPC_Browse_Directory = 'browse_directory'; exports.IPC_Browse_Directory = 'browse_directory';
exports.IPC_Browse_File = 'browse_file'; exports.IPC_Browse_File = 'browse_file';
exports.IPC_Select_File = 'select_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';
@@ -176,6 +177,8 @@ exports.IPC_Install_Upgrade_Reply = 'install_upgrade_reply';
exports.IPC_Mount_Drive = 'mount_drive'; exports.IPC_Mount_Drive = 'mount_drive';
exports.IPC_Mount_Drive_Reply = 'mount_drive_reply'; exports.IPC_Mount_Drive_Reply = 'mount_drive_reply';
exports.IPC_Read_File = 'read_file';
exports.IPC_Remove_Mount = 'remove_mount'; exports.IPC_Remove_Mount = 'remove_mount';
exports.IPC_Remove_Mount_Reply = 'remove_mount_reply'; exports.IPC_Remove_Mount_Reply = 'remove_mount_reply';

View File

@@ -8,6 +8,7 @@ import ImportList from './ImportList/ImportList';
import IPCContainer from '../IPCContainer/IPCContainer'; import IPCContainer from '../IPCContainer/IPCContainer';
import { notifyApplicationBusy } from '../../redux/actions/common_actions'; import { notifyApplicationBusy } from '../../redux/actions/common_actions';
import { notifyError, notifyInfo } from '../../redux/actions/error_actions'; import { notifyError, notifyInfo } from '../../redux/actions/error_actions';
import { promptLocationAndReadFile } from '../../utils';
const Constants = require('../../constants'); const Constants = require('../../constants');
@@ -79,6 +80,13 @@ export default connect(
this.props.notifyInfo('Import Syntax', msg); this.props.notifyInfo('Import Syntax', msg);
}; };
handleLoadFile = () => {
const data = promptLocationAndReadFile(this.props.notifyError);
if (data) {
this.setState({ import_text: data });
}
};
handleNavigation = () => { handleNavigation = () => {
if (this.state.second_stage) { if (this.state.second_stage) {
try { try {
@@ -253,6 +261,18 @@ export default connect(
{'Back'} {'Back'}
</Button> </Button>
) : null} ) : null}
{!this.state.second_stage ? (
<Button
buttonStyles={{
height: 'auto',
marginLeft: 'var(--default_spacing)',
marginTop: 'var(--default_spacing)',
width: 'auto',
}}
clicked={this.handleLoadFile}>
{'Import File...'}
</Button>
) : null}
<Button <Button
buttonStyles={{ buttonStyles={{
height: 'auto', height: 'auto',

View File

@@ -20,6 +20,24 @@ const addListeners = (ipcMain, { getMainWindow, dialog }) => {
); );
}); });
ipcMain.on(Constants.IPC_Browse_File + '_sync', (event, data) => {
dialog.showOpenDialog(
getMainWindow(),
{
defaultPath: data.Location,
properties: ['openFile'],
title: data.Title,
},
(filePaths) => {
if (filePaths && filePaths.length > 0) {
event.returnValue = filePaths[0];
} else {
event.returnValue = '';
}
}
);
});
ipcMain.on(Constants.IPC_Delete_File, (_, data) => { ipcMain.on(Constants.IPC_Delete_File, (_, data) => {
try { try {
if (fs.existsSync(data.FilePath)) { if (fs.existsSync(data.FilePath)) {
@@ -28,7 +46,7 @@ const addListeners = (ipcMain, { getMainWindow, dialog }) => {
} catch (e) {} } catch (e) {}
}); });
ipcMain.on(Constants.IPC_Browse_File + '_sync', (event, data) => { ipcMain.on(Constants.IPC_Select_File + '_sync', (event, data) => {
dialog.showSaveDialog( dialog.showSaveDialog(
getMainWindow(), getMainWindow(),
{ {
@@ -46,6 +64,15 @@ const addListeners = (ipcMain, { getMainWindow, dialog }) => {
); );
}); });
ipcMain.on(Constants.IPC_Read_File + '_sync', (event, data) => {
try {
const contents = fs.readFileSync(data.Location, 'utf8').toString();
event.returnValue = { success: true, contents };
} catch (err) {
event.returnValue = { success: false, error: err.toString() };
}
});
ipcMain.on(Constants.IPC_Save_File + '_sync', (event, data) => { ipcMain.on(Constants.IPC_Save_File + '_sync', (event, data) => {
try { try {
fs.writeFileSync(data.Location, data.Data, 'utf8'); fs.writeFileSync(data.Location, data.Data, 'utf8');

View File

@@ -134,9 +134,9 @@ export const getSelectedVersionFromState = (state) => {
}; };
export const promptLocationAndSaveFile = (fileName, data, notifyError) => { export const promptLocationAndSaveFile = (fileName, data, notifyError) => {
const location = ipcRenderer.sendSync(Constants.IPC_Browse_File + '_sync', {Location: fileName, Title: 'Save File'}); const location = ipcRenderer.sendSync(Constants.IPC_Select_File + '_sync', {Location: fileName, Title: 'Save File'});
if (location && location.length > 0) { if (location && location.length > 0) {
const ret = ipcRenderer.sendSync(Constants.IPC_Save_File + '_sync', {Location: location, Title: 'Save File', Data: data}); const ret = ipcRenderer.sendSync(Constants.IPC_Save_File + '_sync', {Location: location, Data: data});
if (ret.success) { if (ret.success) {
return true; return true;
} }
@@ -146,3 +146,17 @@ export const promptLocationAndSaveFile = (fileName, data, notifyError) => {
return false; return false;
}; };
export const promptLocationAndReadFile = (notifyError) => {
const location = ipcRenderer.sendSync(Constants.IPC_Browse_File + '_sync', {Title: 'Open File'});
if (location && location.length > 0) {
const ret = ipcRenderer.sendSync(Constants.IPC_Read_File + '_sync', {Location: location});
if (ret.success) {
return ret.contents;
}
notifyError(ret.error);
}
return false;
};