YOU HAVEN'T ADDED ANY INSTANCE YET
) : (Oops :|
@@ -138,6 +139,15 @@ const ModsList = props => {Oops :|
++ Looks like our servers are not working... Try again later +
diff --git a/app/actions/instancesManager.js b/app/actions/instancesManager.js index 719221d7f..3c88a12d4 100644 --- a/app/actions/instancesManager.js +++ b/app/actions/instancesManager.js @@ -1,15 +1,19 @@ import { message } from 'antd'; import log from 'electron-log'; import { spawn } from 'child_process'; -import path from 'path'; +import { Promise } from 'bluebird'; +import path, { join, basename } from 'path'; import { promisify } from 'util'; import _ from 'lodash'; -import fs from 'fs'; +import fss from 'fs'; import launchCommand from '../utils/MCLaunchCommand'; import { PACKS_PATH } from '../constants'; import { readConfig, updateConfig } from '../utils/instances'; import { setJavaArgs } from './settings'; +const fs = Promise.promisifyAll(fss); + +export const UPDATE_INSTANCES = 'UPDATE_INSTANCES'; export const SELECT_INSTANCE = 'SELECT_INSTANCE'; export const START_INSTANCE = 'START_INSTANCE'; export const STOP_INSTANCE = 'STOP_INSTANCE'; @@ -40,6 +44,70 @@ export function selectInstance(name) { }; } +export function initInstances() { + return async (dispatch, getState) => { + let watcher; + const isDirectory = source => fss.lstatSync(source).isDirectory(); + + const getDirectories = async source => + fs.readdirAsync(source) + .map(name => join(source, name)) + .filter(isDirectory) + .map(dir => basename(dir)); + + const getInstances = async () => { + const instances = await getDirectories(PACKS_PATH); + const instancesObj = await Promise.all(instances.map(async instance => { + let mods = (await promisify(fss.readdir)(path.join(PACKS_PATH, instance, 'mods'))).filter( + el => path.extname(el) === '.zip' || path.extname(el) === '.jar' + ); + return { + name: instance, + mods + }; + })); + return instancesObj; + }; + + const watchRoutine = async () => { + try { + await fs.accessAsync(PACKS_PATH); + } catch (e) { + await makeDir(PACKS_PATH); + } + let instances = await getInstances(); + dispatch({ + type: UPDATE_INSTANCES, + instances + }); + // Watches for any changes in the packs dir. TODO: Optimize + watcher = fss.watch(PACKS_PATH, async () => { + try { + await fs.accessAsync(PACKS_PATH); + } catch (e) { + await makeDir(PACKS_PATH); + } + + instances = await getInstances(); + dispatch({ + type: UPDATE_INSTANCES, + instances + }); + }); + watcher.on('error', async err => { + try { + await fs.accessAsync(PACKS_PATH); + } catch (e) { + await makeDir(PACKS_PATH); + watchRoutine(); + } + }); + }; + + watchRoutine(); + }; +} + export function startInstance(instanceName) { return async (dispatch, getState) => { const { auth, settings } = getState(); diff --git a/app/actions/news.js b/app/actions/news.js index a78e09fdc..446f961dc 100644 --- a/app/actions/news.js +++ b/app/actions/news.js @@ -11,7 +11,7 @@ export const UPDATE_NEWS = 'UPDATE_NEWS'; export function getNews() { return async (dispatch, getState) => { const { news } = getState(); - if (news.news.length === 0) { + if (news.news.length === 0 && !news.loadingNews) { dispatch({ type: START_LOADING_NEWS }); diff --git a/app/components/CurseModpacksBrowser/CurseModpacksBrowser.js b/app/components/CurseModpacksBrowser/CurseModpacksBrowser.js index 897ade6df..a168bf27d 100644 --- a/app/components/CurseModpacksBrowser/CurseModpacksBrowser.js +++ b/app/components/CurseModpacksBrowser/CurseModpacksBrowser.js @@ -39,7 +39,7 @@ function CurseModpacksBrowser(props) { filterType !== 'author' && filterType !== 'name' ); // We now remove the previous 15 elements and add the real 15 - const mappedData = res.map(v => ({ + const mappedData = res && res.map(v => ({ loading: false, name: v.name, id: v.id, @@ -51,7 +51,7 @@ function CurseModpacksBrowser(props) { })); const data = reset === true ? mappedData : packs.concat(mappedData); - setPacks(data); + setPacks(data || []); setLoading(false); }; @@ -92,7 +92,8 @@ function CurseModpacksBrowser(props) { textAlign: 'center', paddingTop: '20%', height: 'calc(100vh - 60px)', - background: 'var(--secondary-color-2)' + background: 'var(--secondary-color-1)', + fontSize: 18 }} > Servers are not currently available. Try again later diff --git a/app/components/DManager/DManager.js b/app/components/DManager/DManager.js index f81ae25a9..eb73ea409 100644 --- a/app/components/DManager/DManager.js +++ b/app/components/DManager/DManager.js @@ -33,7 +33,7 @@ const SortableList = SortableContainer(({ items }) => { return (