Import Skylinks from json file
This commit is contained in:
@@ -109,9 +109,10 @@ exports.INSTALL_TYPES = {
|
||||
};
|
||||
|
||||
exports.IPC_Browse_Directory = 'browse_directory';
|
||||
|
||||
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_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_Reply = 'mount_drive_reply';
|
||||
|
||||
exports.IPC_Read_File = 'read_file';
|
||||
|
||||
exports.IPC_Remove_Mount = 'remove_mount';
|
||||
exports.IPC_Remove_Mount_Reply = 'remove_mount_reply';
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import ImportList from './ImportList/ImportList';
|
||||
import IPCContainer from '../IPCContainer/IPCContainer';
|
||||
import { notifyApplicationBusy } from '../../redux/actions/common_actions';
|
||||
import { notifyError, notifyInfo } from '../../redux/actions/error_actions';
|
||||
import { promptLocationAndReadFile } from '../../utils';
|
||||
|
||||
const Constants = require('../../constants');
|
||||
|
||||
@@ -79,6 +80,13 @@ export default connect(
|
||||
this.props.notifyInfo('Import Syntax', msg);
|
||||
};
|
||||
|
||||
handleLoadFile = () => {
|
||||
const data = promptLocationAndReadFile(this.props.notifyError);
|
||||
if (data) {
|
||||
this.setState({ import_text: data });
|
||||
}
|
||||
};
|
||||
|
||||
handleNavigation = () => {
|
||||
if (this.state.second_stage) {
|
||||
try {
|
||||
@@ -253,6 +261,18 @@ export default connect(
|
||||
{'Back'}
|
||||
</Button>
|
||||
) : 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
|
||||
buttonStyles={{
|
||||
height: 'auto',
|
||||
|
||||
@@ -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) => {
|
||||
try {
|
||||
if (fs.existsSync(data.FilePath)) {
|
||||
@@ -28,7 +46,7 @@ const addListeners = (ipcMain, { getMainWindow, dialog }) => {
|
||||
} catch (e) {}
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Browse_File + '_sync', (event, data) => {
|
||||
ipcMain.on(Constants.IPC_Select_File + '_sync', (event, data) => {
|
||||
dialog.showSaveDialog(
|
||||
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) => {
|
||||
try {
|
||||
fs.writeFileSync(data.Location, data.Data, 'utf8');
|
||||
|
||||
@@ -134,9 +134,9 @@ export const getSelectedVersionFromState = (state) => {
|
||||
};
|
||||
|
||||
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) {
|
||||
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) {
|
||||
return true;
|
||||
}
|
||||
@@ -146,3 +146,17 @@ export const promptLocationAndSaveFile = (fileName, data, notifyError) => {
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user