From 5ecb76b23c7c5cbcd51448bead3ee8b906ed56d5 Mon Sep 17 00:00:00 2001 From: Matt Worzala Date: Sat, 13 Jul 2019 16:03:55 -0400 Subject: [PATCH] profile icons can be updated now. --- package.json | 2 +- src/main/config/config.js | 11 +++++------ src/main/needsHome/profile.js | 12 +++++++++++- src/render/core/App.js | 2 +- src/render/profiles/ProfileOptions.js | 6 ++---- src/render/profiles/Profiles.js | 5 ++++- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 48c401f..38727cf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "proton", - "version": "0.2.9", + "version": "0.2.11", "description": "A custom minecraft launcher", "private": false, "author": "Matt Worzala ", diff --git a/src/main/config/config.js b/src/main/config/config.js index c8bd42e..73f97e9 100644 --- a/src/main/config/config.js +++ b/src/main/config/config.js @@ -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(); } }; diff --git a/src/main/needsHome/profile.js b/src/main/needsHome/profile.js index 0ed7a91..4671c49 100644 --- a/src/main/needsHome/profile.js +++ b/src/main/needsHome/profile.js @@ -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'); @@ -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) => { diff --git a/src/render/core/App.js b/src/render/core/App.js index 563d49a..897b731 100644 --- a/src/render/core/App.js +++ b/src/render/core/App.js @@ -141,7 +141,7 @@ class App extends React.Component { - this.setState({ profile: profile })} /> + this.state.profile.name} onProfileOptions={profile => this.setState({ profile: profile })} /> diff --git a/src/render/profiles/ProfileOptions.js b/src/render/profiles/ProfileOptions.js index fd28f08..a1d450a 100644 --- a/src/render/profiles/ProfileOptions.js +++ b/src/render/profiles/ProfileOptions.js @@ -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 ( @@ -52,7 +50,7 @@ class ProfileOptions extends React.Component {
this.imageSelect.current.click()}>

Change Icon

- this.handleChangeIcon(e.target.files[0].path)} hidden /> + this.handleChangeIcon(this.props.profile.name, e.target.files[0].path)} hidden /> Profile Icon diff --git a/src/render/profiles/Profiles.js b/src/render/profiles/Profiles.js index 9300020..0554bd9 100644 --- a/src/render/profiles/Profiles.js +++ b/src/render/profiles/Profiles.js @@ -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) {