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 5, 2019
2 parents 035f906 + 9288bc3 commit 3f04432
Show file tree
Hide file tree
Showing 17 changed files with 692 additions and 575 deletions.
63 changes: 34 additions & 29 deletions app/actions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,11 @@ export function login(username, password, remember) {
username,
password,
requestUser: true,
...(store.get('clientToken') && { clientToken: getClientToken() })
clientToken: getClientToken()
},
{ headers: { 'Content-Type': 'application/json' } }
);
if (
status === 200 &&
data !== undefined &&
data !== null &&
Object.prototype.hasOwnProperty.call(data, 'accessToken')
) {
if (status === 200 && data && data.accessToken) {
const payload = {
email: data.user.email,
username: data.user.username,
Expand All @@ -62,15 +57,14 @@ export function login(username, password, remember) {
user: {
...payload
},
clientToken: data.clientToken,
lastUsername: data.user.username
});
}
dispatch({
type: AUTH_SUCCESS,
payload: {
...payload,
clientToken: data.clientToken
clientToken: getClientToken()
}
});

Expand All @@ -89,7 +83,6 @@ export function login(username, password, remember) {
});
}
} catch (err) {
console.error(err);
message.error('Wrong username or password');
} finally {
dispatch({
Expand Down Expand Up @@ -121,9 +114,10 @@ export function checkAccessToken() {
const res = await axios.post(
ACCESS_TOKEN_VALIDATION_URL,
{
accessToken: userData.accessToken
accessToken: userData.accessToken,
clientToken: getClientToken()
},
{ 'Content-Type': 'application/json;charset=UTF-8' }
{ headers: { 'Content-Type': 'application/json' } }
);
if (res.status === 204) {
dispatch({
Expand All @@ -141,13 +135,28 @@ export function checkAccessToken() {
// Trying refreshing the stored access token
const newUserData = await refreshAccessToken(
userData.accessToken,
getClientToken(),
true
);
if (newUserData) {
const payload = {
email: newUserData.user.email,
username: newUserData.user.username,
displayName: newUserData.selectedProfile.name,
accessToken: newUserData.accessToken,
legacy: newUserData.selectedProfile.legacyProfile,
uuid: newUserData.selectedProfile.id,
userID: newUserData.selectedProfile.userId
};
store.set({
user: {
...payload
}
});
dispatch({
type: AUTH_SUCCESS,
payload: {
...userData,
...payload,
clientToken: getClientToken()
}
});
Expand Down Expand Up @@ -197,9 +206,10 @@ export function tryNativeLauncherProfiles() {
const vnlJson = await fsa.readJson(
path.join(vanillaMCPath, 'launcher_profiles.json')
);
const { clientToken } = vnlJson;
const { account } = vnlJson.selectedUser;
const { accessToken } = vnlJson.authenticationDatabase[account];
const newUserData = await refreshAccessToken(accessToken, true);
const newUserData = await refreshAccessToken(accessToken, clientToken, true);
if (newUserData) {
const payload = {
email: newUserData.user.email,
Expand Down Expand Up @@ -227,12 +237,12 @@ export function tryNativeLauncherProfiles() {
type: AUTH_SUCCESS,
payload: {
...payload,
clientToken: newUserData.clientToken
clientToken: getClientToken()
}
});
const { newUser } = store.get('settings');

if (newUser === false) {
if (!newUser) {
dispatch(push('/home'));
} else {
store.set('settings.newUser', false);
Expand Down Expand Up @@ -263,37 +273,32 @@ const uuidv4 = () => {

const getClientToken = () => {
const clientToken = store.get('clientToken');
if (
clientToken &&
clientToken !== undefined &&
typeof clientToken === 'string'
) {
if (clientToken) {
return clientToken;
}
return uuidv4().replace('-', '');
const newToken = uuidv4().replace('-', '');
store.set('clientToken', newToken);
return newToken;
};

// Returns the user data if successful, otherwise returns false
const refreshAccessToken = async (
accessToken: string,
clientToken: string,
requestUser: boolean = false
): boolean | {} => {
try {
const response = await axios.post(
ACCESS_TOKEN_REFRESH_URL,
{
accessToken,
clientToken,
requestUser
},
{ 'Content-Type': 'application/json' }
{ headers: { 'Content-Type': 'application/json' } }
);

if (
response.status === 200 &&
response.data !== undefined &&
response.data !== null &&
Object.prototype.hasOwnProperty.call(response.data, 'accessToken')
) {
if (response.status === 200 && response.data && response.data.accessToken) {
return response.data;
}
} catch (err) {
Expand Down
5 changes: 2 additions & 3 deletions app/actions/downloadManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ export function downloadPack(pack, isRepair = false) {
const updatePercentage = downloaded => {
const actPercentage = (
(downloaded * totalPercentage) / totalFiles +
(100 - totalPercentage)
((installProfileJson ? 88 : 100) - totalPercentage)
).toFixed(0);
return dispatch({
type: UPDATE_PROGRESS,
Expand Down Expand Up @@ -532,9 +532,8 @@ export function downloadPack(pack, isRepair = false) {
{ maxBuffer: 10000000000 }
);

console.log(stderr, stdout);
log.error(stderr);
const actPercentage = ((i * 12) / processors.length).toFixed(0);
console.log(actPercentage);
dispatch({
type: UPDATE_PROGRESS,
payload: {
Expand Down
2 changes: 1 addition & 1 deletion app/actions/instancesManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function startInstance(instanceName) {
// Checks for legacy java memory
const legacyString = [' -Xmx{_RAM_}m', '-Xmx{_RAM_}m'];
const config = await readConfig(instanceName);
if (_.has(config, 'overrideArgs') && config.overrideArgs.includes(legacyString[0]) || config.overrideArgs.includes(legacyString[1])) {
if (config.overrideArgs && (config.overrideArgs.includes(legacyString[0]) || config.overrideArgs.includes(legacyString[1]))) {
await updateConfig(instanceName, {
overrideArgs: config.overrideArgs.replace(legacyString, '')
});
Expand Down
11 changes: 11 additions & 0 deletions app/actions/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const SET_JAVA_MEMORY = 'SET_JAVA_MEMORY';
export const SET_THEME = 'SET_THEME';
export const RESET_THEME = 'RESET_THEME';
export const SET_GLOBAL_JAVA_ARGUMENTS = 'SET_GLOBAL_JAVA_ARGUMENTS';
export const SET_INSTANCES_PATH = 'SET_INSTANCES_PATH';

export function loadSettings() {
return dispatch => {
Expand Down Expand Up @@ -160,3 +161,13 @@ export function setJavaArgs(args) {
dispatch(saveSettings());
};
}

export function setInstancesPath(path) {
return dispatch => {
dispatch({
type: SET_INSTANCES_PATH,
path
});
dispatch(saveSettings());
};
}
36 changes: 29 additions & 7 deletions app/components/ChangelogModal/ChangelogModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ export default props => {
<Modal
history={props.history}
unMount={unMount}
title="WHAT'S NEW"
title={`WHAT'S NEW IN v${require('../../../package.json').version}`}
style={{ height: '70vh', width: 540 }}
>
<div className={styles.container}>

<h2 className={styles.hrTextYellow}>WARNING!</h2>
<span className={styles.summary}>
This update contains <span style={{ color: '#f39c12' }}>breaking changes</span>. If your instances don't run, try right-clicking on them and select "Repair"
</span>
<div style={{ margin: 15 }} />
<h2 className={styles.hrTextGreen}>SOME COOL NEW STUFF</h2>
<div className={styles.subHrList}>
<ul>
Expand All @@ -42,15 +48,19 @@ export default props => {
main="Added support for Minecraft Forge 1.13"
secondary=". Don't tilt if it looks like it's frozen, it may take a while"
/>
<ChangelogRow
main="Added support for custom path for instances"
secondary=". After changing it, you'll need to restart the launcher"
/>
<ChangelogRow
main="When importing a zip, a default name is suggested"
secondary=". You'll have more time to play now!!"
/>
</ul>
</div>
<h2 className={styles.hrTextRed}>SOME BUGFIXES</h2>
<div className={styles.subHrList}>
<ul>
<ChangelogRow
main="Fixed continuous login reset"
secondary=" (hopefully)"
/>
<ChangelogRow
main="Fixed download progress bar zindex"
secondary=" lel"
Expand All @@ -59,9 +69,21 @@ export default props => {
main="Some improvements in the mods manager"
secondary=", we're still working on it though"
/>
<ChangelogRow
main="The mods counter now shows the correct number of installed mods"
secondary=", ouga buga"
/>
<ChangelogRow
main="Finally fixed the login token!!"
secondary=", you won't need to login every time ever again :)"
/>
<ChangelogRow
main="Even though you don't see them"
secondary=", we fixed and improved a lot of under-the-hood stuff. Enjoyy!"
/>
</ul>
</div>
<h2 className={styles.hrTextYellow}>WE LOVE YOU</h2>
<h2 className={styles.hdTextBlue}>WE LOVE YOU</h2>
<span className={styles.summary}>
We love our users, that's why we have a dedicated discord server just
to talk with all of them :)
Expand All @@ -73,6 +95,6 @@ export default props => {
onClick={openDiscord}
/>
</div>
</Modal>
</Modal >
);
};
9 changes: 9 additions & 0 deletions app/components/ChangelogModal/ChangelogModal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@
}
}

.hdTextBlue {
@include hrText;
color: #3498db;
&:before,
&:after {
background-color: #3498db;
}
}

.subHrList {
text-align: left;
li {
Expand Down
3 changes: 1 addition & 2 deletions app/components/Common/JavaArgumentInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ const JavaArgumentInput = ({
marginRight: '10px',
marginBottom: 4,
marginTop: 4,
marginLeft: '1%',
background: 'var(--secondary-color-1)'
marginLeft: '1%'
}}
onChange={onInputChange}
/>
Expand Down
8 changes: 6 additions & 2 deletions app/components/Common/SideBar/SideBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faSignOutAlt } from '@fortawesome/free-solid-svg-icons';
import {faDiscord, faFacebook} from '@fortawesome/free-brands-svg-icons';
import { faDiscord, faFacebook } from '@fortawesome/free-brands-svg-icons';
import { promisify } from 'util';
import CIcon from '../Icon/Icon';
import SocialIcon from './SocialIcon';
Expand Down Expand Up @@ -41,7 +41,11 @@ const SideBar = props => {
try {
mods = (await fs.readdirAsync(
path.join(PACKS_PATH, props.selectedInstance, 'mods')
)).filter(el => el !== 'GDLCompanion.jar' && el !== 'LJF.jar').length;
))
.filter(el => el !== 'GDLCompanion.jar' && el !== 'LJF.jar')
.filter(
el => path.extname(el) === '.zip' || path.extname(el) === '.jar'
).length;
} catch {}

try {
Expand Down
16 changes: 11 additions & 5 deletions app/components/ImportPack/ImportPack.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ const ImportPack = props => {
e.preventDefault();
form.validateFields(async (err, values) => {
if (!err) {
if (filePath === null) {
if (!filePath) {
message.warning('Please select a zip file.');
return;
}
const name = values.packName || path.parse(path.basename(filePath)).name;

try {
await promisify(fs.access)(path.join(PACKS_PATH, values.packName));
await promisify(fs.access)(path.join(PACKS_PATH, name));
message.warning('An instance with this name already exists.');
} catch (error) {
setLoading(true);
await props.importTwitchProfile(values.packName, filePath);
await props.importTwitchProfile(name, filePath);
setUnMount(true);
}
}
Expand Down Expand Up @@ -75,7 +77,7 @@ const ImportPack = props => {
{getFieldDecorator('packName', {
rules: [
{
required: true,
required: false,
message:
'Please input a valid name with just numbers and letters',
pattern: new RegExp('^[a-zA-Z0-9_.-]+( [a-zA-Z0-9_.-]+)*$')
Expand All @@ -97,7 +99,11 @@ const ImportPack = props => {
style={{ color: 'rgba(255,255,255,.8)' }}
/>
}
placeholder="Instance Name"
placeholder={
filePath
? path.parse(path.basename(filePath)).name
: 'Instance Name'
}
/>
)}
</FormItem>
Expand Down
Loading

0 comments on commit 3f04432

Please sign in to comment.