Skip to content

Commit

Permalink
Merge branch 'develop' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
blarfoon committed May 23, 2019
2 parents 3f04432 + 8cae6a7 commit 7ed32da
Show file tree
Hide file tree
Showing 14 changed files with 1,392 additions and 1,328 deletions.
72 changes: 70 additions & 2 deletions app/actions/instancesManager.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion app/actions/news.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down
7 changes: 4 additions & 3 deletions app/components/CurseModpacksBrowser/CurseModpacksBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -51,7 +51,7 @@ function CurseModpacksBrowser(props) {
}));

const data = reset === true ? mappedData : packs.concat(mappedData);
setPacks(data);
setPacks(data || []);

setLoading(false);
};
Expand Down Expand Up @@ -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
Expand Down
98 changes: 6 additions & 92 deletions app/components/DManager/DManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const SortableList = SortableContainer(({ items }) => {
return (
<div style={{ height: '100%', overflowY: 'auto' }}>
{items.map((value, index) => (
<SortableItem key={`item-${index}`} index={index} value={value} />
<SortableItem key={`item-${index}`} index={index} value={value.name} />
))}
</div>
);
Expand All @@ -44,82 +44,6 @@ const fs = Promise.promisifyAll(fss);
export default class DManager extends Component<Props> {
props: Props;

constructor(props) {
super(props);
this.state = {
instances: [],
checkingInstances: true
};
}

componentDidMount = async () => {
this.watchRoutine();
};

componentWillUnmount() {
// Stop watching for changes when this component is unmounted
try {
watcher.close();
} catch (err) {
log.error(err);
}
}

watchRoutine = async () => {
try {
await fs.accessAsync(PACKS_PATH);
} catch (e) {
await makeDir(PACKS_PATH);
}
this.setState({
instances: await this.getDirectories(PACKS_PATH)
});
// Watches for any changes in the packs dir. TODO: Optimize
try {
watcher = fss.watch(PACKS_PATH, async () => {
try {
await fs.accessAsync(PACKS_PATH);
} catch (e) {
await makeDir(PACKS_PATH);
}
this.setState({
instances: await this.getDirectories(PACKS_PATH)
});
});
watcher.on('error', async err => {
try {
await fs.accessAsync(PACKS_PATH);
} catch (e) {
await makeDir(PACKS_PATH);
this.watchRoutine();
}
});
} catch (error) {
log.error(error);
if (error.message === `watch ${PACKS_PATH} ENOSPC`) {
message.error(
<span>
There was an error with inotify limit. see
<a
target="_blank"
rel="noopener noreferrer"
href="https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers"
>
{' '}
here
</a>
</span>
);
} else {
message.error('Cannot update instances in real time');
}
} finally {
this.setState({
checkingInstances: false
});
}
};

handleScroll = () => {
hideMenu();
};
Expand All @@ -132,24 +56,15 @@ export default class DManager extends Component<Props> {
/* eslint-enable */

onSortEnd = ({ oldIndex, newIndex }) => {
this.setState({
instances: arrayMove(this.state.instances, oldIndex, newIndex)
});
// this.setState({
// instances: arrayMove(this.state.instances, oldIndex, newIndex)
// });
};

onSortStart = ({ node, index, collection }) => {
hideMenu();
};

isDirectory = source => fss.lstatSync(source).isDirectory();

getDirectories = async source =>
fs
.readdirAsync(source)
.map(name => join(source, name))
.filter(this.isDirectory)
.map(dir => basename(dir));

render() {
return (
<main
Expand Down Expand Up @@ -192,14 +107,13 @@ export default class DManager extends Component<Props> {
</div>
<ContextMenuTrigger id="contextMenu-dmanager">
<div className={styles.content} onScroll={this.handleScroll}>
{this.state.instances.length === 0 &&
!this.state.checkingInstances ? (
{this.props.instances.length === 0 ? (
<h1 className={styles.NoServerCreated}>
YOU HAVEN'T ADDED ANY INSTANCE YET
</h1>
) : (
<SortableList
items={this.state.instances}
items={this.props.instances}
onSortEnd={this.onSortEnd}
onSortStart={this.onSortStart}
lockToContainerEdges
Expand Down
3 changes: 2 additions & 1 deletion app/components/DManager/containers/DManagerPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import * as instancesManagerActions from '../../../actions/instancesManager';

function mapStateToProps(state) {
return {
userData: state.auth
userData: state.auth,
instances: state.instancesManager.instances
};
}

Expand Down
1 change: 0 additions & 1 deletion app/components/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export default class Home extends Component<Props> {
}

componentDidMount = async () => {
this.props.getNews();
try {
await promisify(fs.access)(path.join(PACKS_PATH, '1.13.2'));
this.setState({ latestInstalled: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ModsList = props => {
useEffect(() => {
try {
loadInstalledMods();
} catch {}
} catch { }
}, [props.localMods]);

const loadInstalledMods = async () => {
Expand All @@ -64,8 +64,9 @@ const ModsList = props => {
filterType !== 'Author' && filterType !== 'Name',
props.match.params.version
);
setMods(reset ? data : mods.concat(data));
setHasNextPage(data.length === 21);
const newMods = reset ? data : mods.concat(data);
setMods(newMods || []);
setHasNextPage((newMods || []).length === 21);
setAreModsLoading(false);
};

Expand Down Expand Up @@ -127,7 +128,7 @@ const ModsList = props => {
version={props.match.params.version}
instance={props.match.params.instance}
/>
{mods.length === 0 && !areModsLoading && (
{mods.length === 0 && !areModsLoading && searchQuery !== "" && (
<div className={styles.modsNotFound}>
<div>
<h1>Oops :|</h1>
Expand All @@ -138,6 +139,15 @@ const ModsList = props => {
</div>
</div>
)}
{mods.length === 0 && !areModsLoading && searchQuery === "" && (
<div className={styles.modsNotFound}>
<div>
<h1>Oops :|</h1>
<br />
Looks like our servers are not working... Try again later
</div>
</div>
)}
<AutoSizer>
{({ height, width }) => (
<ModsListWrapper
Expand Down
10 changes: 8 additions & 2 deletions app/components/Settings/components/Instances/Instances.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Button, message, Input, Icon } from 'antd';
import fsa from 'fs-extra';
import path from 'path';
import styles from './Instances.scss';
import { INSTANCES_PATH, META_PATH } from '../../../../constants';
import { INSTANCES_PATH, META_PATH, DATAPATH, INSTANCES_FOLDER } from '../../../../constants';
import SettingCard from '../SettingCard/SettingCard';
import Title from '../Title/Title';
import SwitchSetting from '../SwitchSetting/SwitchSetting';
Expand Down Expand Up @@ -81,7 +81,13 @@ function Instances(props) {
{props.instancesPath && (
<div>
<div>
<span style={{ fontSize: 18 }}>Instances Custom Path</span>
<span style={{ fontSize: 18 }}>Instances Custom Path{' '}</span>
<a
onClick={() => props.setInstancesPath(path.join(DATAPATH, INSTANCES_FOLDER))}
style={{ fontSize: 13 }}
>
Reset Path
</a>
<Input
value={props.instancesPath}
size="large"
Expand Down
2 changes: 1 addition & 1 deletion app/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const META_PATH = path.join(DATAPATH, 'meta');
export const GAME_VERSIONS_URL =
'https://launchermeta.mojang.com/mc/game/version_manifest.json';
export const FORGE_PROMOS =
'https://staging_cursemeta.dries007.net/api/v3/direct/minecraft/modloader';
'https://addons-ecs.forgesvc.net/api/v2/minecraft/modloader';
export const ACCESS_TOKEN_VALIDATION_URL =
'https://authserver.mojang.com/validate';

Expand Down
Loading

0 comments on commit 7ed32da

Please sign in to comment.