Fix remote and S3 detection
This commit is contained in:
@@ -3,19 +3,55 @@ const fs = require('fs');
|
||||
const helpers = require('../../helpers');
|
||||
const path = require('path');
|
||||
|
||||
const getDirectories = source =>
|
||||
fs.readdirSync(source, {withFileTypes: true})
|
||||
.filter(dirent => dirent.isDirectory())
|
||||
.map(dirent => dirent.name)
|
||||
|
||||
const addListeners = ipcMain => {
|
||||
ipcMain.on(Constants.IPC_Get_State, event => {
|
||||
helpers.mkDirByPathSync(helpers.getDataDirectory());
|
||||
|
||||
let data = {};
|
||||
const configFile = path.join(helpers.getDataDirectory(), 'settings.json');
|
||||
if (fs.existsSync(configFile)) {
|
||||
event.sender.send(Constants.IPC_Get_State_Reply, {
|
||||
data: JSON.parse(fs.readFileSync(configFile, 'utf8')),
|
||||
});
|
||||
data = JSON.parse(fs.readFileSync(configFile, 'utf8'));
|
||||
} else {
|
||||
event.sender.send(Constants.IPC_Get_State_Reply, {
|
||||
data: null,
|
||||
});
|
||||
data.Release = Constants.DEFAULT_RELEASE;
|
||||
data.Version = -1;
|
||||
}
|
||||
|
||||
data.RemoteMounts = data.RemoteMounts || [];
|
||||
data.S3Mounts = data.S3Mounts || [];
|
||||
|
||||
const remoteItems = getDirectories(path.join(helpers.getRepertoryDirectory(), 'remote'));
|
||||
for (const dir of remoteItems) {
|
||||
const name = 'Remote' + dir.replace('_', ':');
|
||||
if (!data.RemoteMounts || data.RemoteMounts.indexOf(name) === -1) {
|
||||
data.RemoteMounts.push(name);
|
||||
data[name] = {
|
||||
AutoMount: false,
|
||||
AutoRestart: true,
|
||||
MountLocation: '',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const s3Items = getDirectories(path.join(helpers.getRepertoryDirectory(), 's3'));
|
||||
for (const dir of s3Items) {
|
||||
const name = 'S3' + dir;
|
||||
if (!data.S3Mounts || data.S3Mounts.indexOf(name) === -1) {
|
||||
data.S3Mounts.push(name);
|
||||
data[name] = {
|
||||
AutoMount: false,
|
||||
AutoRestart: true,
|
||||
MountLocation: '',
|
||||
};
|
||||
}
|
||||
}
|
||||
event.sender.send(Constants.IPC_Get_State_Reply, {
|
||||
data,
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Save_State, (event, data) => {
|
||||
@@ -27,4 +63,4 @@ const addListeners = ipcMain => {
|
||||
|
||||
module.exports = {
|
||||
addListeners
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user