Skip to content

Commit

Permalink
profile icons can be updated now.
Browse files Browse the repository at this point in the history
  • Loading branch information
mworzala committed Jul 13, 2019
1 parent 13795a9 commit 5ecb76b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "proton",
"version": "0.2.9",
"version": "0.2.11",
"description": "A custom minecraft launcher",
"private": false,
"author": "Matt Worzala <bhop.me>",
Expand Down
11 changes: 5 additions & 6 deletions src/main/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,14 @@ exports.loadConfig = async () => {
while (maxMem % 128 !== 0)
maxMem++;

if (this.getValue('app/instanceDir').length === 0) {
this.setValue('app/instanceDir', path.join(baseDir, 'Instances'));
await this.saveConfig();
}

if (!created) {
this.setValue('defaults/maxMemory', maxMem / 2);
this.setValue('clientKey', Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15));
await this.saveConfig();
}

if (this.getValue('app/instanceDir').length === 0) {
this.setValue('app/instanceDir', path.join(baseDir, 'Instances'));
this.saveConfig();
}
};

Expand Down
12 changes: 11 additions & 1 deletion src/main/needsHome/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const files = require('../util/files');
const StreamZip = require('node-stream-zip');
const fetch = require('node-fetch');
const taskmaster = require('../task/taskmaster');
const sendSnack = require('../main').sendSnack;

// Useful paths
const baseDir = app.getPath('userData');
Expand All @@ -48,12 +49,21 @@ const profileDb = new Database(path.join(baseDir, 'profiles.db'));
profileDb.index({ fieldName: 'name', unique: true });

// IPC listeners
// CRUD operations
// Base profile
ipcMain.on('profile:create', (event, payload) => this.createProfile(payload));
ipcMain.on('profile:list', () => this.renderProfiles());
ipcMain.on('profile:update', () => {}); //todo
ipcMain.on('profile:update:icon', async (event, data) => {
if (!await fs.pathExists(data.icon))
return sendSnack({ body: 'Failed to change profile icon!' });
const icon = await files.loadImage(data.icon);
await this.updateProfile(data.name, { icon: icon.src });
sendSnack({ body: 'Successfully changed profile icon!' });
await this.renderProfiles()
});
ipcMain.on('profile:delete', (event, payload) => this.deleteProfile(payload));


// Screenshots
ipcMain.on('profile:screenshot:list', async (event, payload) => mainWindow.send('profile:screenshot:render', await this.getScreenshots(payload)));
ipcMain.on('profile:screenshot:delete', async (event, payload) => {
Expand Down
2 changes: 1 addition & 1 deletion src/render/core/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class App extends React.Component {
<SidebarHeader />
<SidebarGroup index={0} title="library">
<Page id="profiles" icon="list" display="Profiles">
<Profiles onProfileOptions={profile => this.setState({ profile: profile })} />
<Profiles getActiveProfileOptions={() => this.state.profile.name} onProfileOptions={profile => this.setState({ profile: profile })} />
</Page>
<Page id="accounts" icon="user" display="Accounts">
<AccountManager />
Expand Down
6 changes: 2 additions & 4 deletions src/render/profiles/ProfileOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ class ProfileOptions extends React.Component {
}
}

handleChangeIcon = target => {
alert('changing profile background to ' + target);
};
handleChangeIcon = (name, target) => window.ipc.send('profile:update:icon', { name, icon: target });

render() {
return (
Expand All @@ -52,7 +50,7 @@ class ProfileOptions extends React.Component {
<div className="po-o-hidden" onClick={() => this.imageSelect.current.click()}>
<p>Change Icon</p>
</div>
<input type="file" ref={this.imageSelect} accept="image/png" onChange={e => this.handleChangeIcon(e.target.files[0].path)} hidden />
<input type="file" ref={this.imageSelect} accept="image/png" onChange={e => this.handleChangeIcon(this.props.profile.name, e.target.files[0].path)} hidden />
<img src={this.props.profile.icon} alt="Profile Icon" />
</div>
</ModalPage>
Expand Down
5 changes: 4 additions & 1 deletion src/render/profiles/Profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class Profiles extends React.Component {
handleRender = (event, payload) => {
this.setState({
profiles: payload,
});
}, () => this.state.profiles.forEach(profile => {
if (profile.name === this.props.getActiveProfileOptions())
this.props.onProfileOptions(profile)
}));
};

handleLaunch(profile) {
Expand Down

0 comments on commit 5ecb76b

Please sign in to comment.