diff --git a/src/constants.js b/src/constants.js index 8c45161..8c7b70e 100644 --- a/src/constants.js +++ b/src/constants.js @@ -51,6 +51,12 @@ exports.DATA_LOCATIONS = { win32: '%LOCALAPPDATA%\\repertory\\ui' }; +exports.REPERTORY_LOCATIONS = { + linux: '~/.local/repertory', + darwin: '~/Library/Application Support/repertory', + win32: '%LOCALAPPDATA%\\repertory' +}; + exports.S3_PROVIDER_LIST = [ 'Goobox S3', ]; @@ -72,6 +78,7 @@ exports.PROVIDER_ARG = { s3: '-s3', }; +exports.DEFAULT_RELEASE = 0; exports.RELEASE_TYPES = [ 'Release', 'RC', diff --git a/src/helpers.js b/src/helpers.js index 95f658e..1152e93 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -213,6 +213,10 @@ const _getDataDirectory = () => { return _resolvePath(Constants.DATA_LOCATIONS[os.platform()]); }; +const _getRepertoryDirectory = () => { + return _resolvePath(Constants.REPERTORY_LOCATIONS[os.platform()]); +}; + const _getDefaultRepertoryArgs = (provider, remote, s3) => { const providerLower = provider.toLowerCase(); const args = []; @@ -728,6 +732,8 @@ module.exports.getConfigTemplate = (version, provider, remote, s3) => { module.exports.getDataDirectory = _getDataDirectory; +module.exports.getRepertoryDirectory = _getRepertoryDirectory; + module.exports.getMissingDependencies = dependencies => { return new Promise((resolve, reject) => { if (!dependencies) { diff --git a/src/index.js b/src/index.js index 2e275e8..00417b5 100644 --- a/src/index.js +++ b/src/index.js @@ -30,6 +30,7 @@ if (ipcRenderer) { const providerList = [ ...Constants.PROVIDER_LIST, ...store.getState().mounts.RemoteMounts, + ...store.getState().mounts.S3Mounts, ]; for (const provider of providerList) { let state = result.data[provider] || store.getState().mounts.ProviderState[provider]; diff --git a/src/redux/actions/release_version_actions.js b/src/redux/actions/release_version_actions.js index 962ebff..c12c839 100644 --- a/src/redux/actions/release_version_actions.js +++ b/src/redux/actions/release_version_actions.js @@ -71,13 +71,13 @@ export const loadReleases = () => { const state = getState().relver; let release = state.Release; if (release >= Constants.RELEASE_TYPES.length) { - release = state.ReleaseDefault; + release = Constants.DEFAULT_RELEASE; } let latestVersion = versionLookup[Constants.RELEASE_TYPES[release]].length - 1; let version = state.Version; if (versionLookup[Constants.RELEASE_TYPES[release]][0] === 'unavailable') { - release = state.ReleaseDefault; + release = Constants.DEFAULT_RELEASE; version = latestVersion = versionLookup[Constants.RELEASE_TYPES[release]].length - 1 } else if ((version === -1) || !versionLookup[Constants.RELEASE_TYPES[release]][version]) { version = latestVersion; @@ -179,7 +179,7 @@ export const setActiveRelease = (release, version) => { const relver = getState().relver; const common = getState().common; if (release >= Constants.RELEASE_TYPES.length) { - release = relver.ReleaseDefault; + release = Constants.DEFAULT_RELEASE; version = -1; } const versions = relver.VersionLookup[Constants.RELEASE_TYPES[release]]; diff --git a/src/redux/reducers/release_version_reducer.js b/src/redux/reducers/release_version_reducer.js index 5946b7e..77667ac 100644 --- a/src/redux/reducers/release_version_reducer.js +++ b/src/redux/reducers/release_version_reducer.js @@ -20,8 +20,7 @@ export const releaseVersionReducer = createReducer({ LocationsLookup: {}, NewReleasesAvailable: [], NewReleasesAvailable2: [], - Release: 0, - ReleaseDefault: 0, + Release: Constants.DEFAULT_RELEASE, ReleaseUpgradeAvailable: false, UpgradeAvailable: false, UpgradeData: null, diff --git a/src/renderer/ipc/StateIPC.js b/src/renderer/ipc/StateIPC.js index f6f1a7c..b8fcd05 100644 --- a/src/renderer/ipc/StateIPC.js +++ b/src/renderer/ipc/StateIPC.js @@ -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 -}; \ No newline at end of file +};