Skip to content

Commit

Permalink
Alert system overhaul
Browse files Browse the repository at this point in the history
- Messages won't be shown more than once
- Improved system and quality
  • Loading branch information
Ryzzzen committed Feb 2, 2019
1 parent 55660d4 commit 36a7d84
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
18 changes: 7 additions & 11 deletions objects/Mana.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class Mana {
this.gameClient = new (require('./riot/leagueoflegends/GameClient'))();
this.assetsProxy = new (require('./riot/leagueoflegends/GameAssetsProxy'))();

this.alertHandler = new (require('./handlers/AlertHandler'))();

this.championStorageHandler = new (require('./handlers/ChampionStorageHandler'))();
this.championSelectHandler = new (require('./handlers/ChampionSelectHandler'))();
this.providerHandler = new (require('./handlers/ProviderHandler'))(this.devMode);
Expand Down Expand Up @@ -78,11 +80,9 @@ class Mana {

this.assetsProxy.load();

const data = await UI.indicator(Promise.all([this.gameClient.load(), this.gameClient.queryChampionSummary(), this.gameClient.querySummonerSpells(), require('request-promise-native')('https://manaflux-server.herokuapp.com/api/alerts/v1')]), 'status-loading-resources');
const data = await UI.indicator(Promise.all([this.gameClient.load(), this.gameClient.queryChampionSummary(), this.gameClient.querySummonerSpells()]), 'status-loading-resources');

this.preseason = data[0];

this._alert(data[3]);
$('.version').text(`V${this.version} - V${this.gameClient.branch}`);

await this.championStorageHandler.load();
Expand All @@ -95,6 +95,8 @@ class Mana {
this.getStore().set('lastBranchSeen', this.gameClient.branch);
document.querySelectorAll('[data-custom-component]').forEach(x => x.dispatchEvent(new Event('clientLoaded')));

this.alertHandler.load();

ipcRenderer.send('lcu-preload-done');
}

Expand All @@ -108,10 +110,9 @@ class Mana {
document.querySelectorAll('[data-custom-component]').forEach(x => x.dispatchEvent(new Event('userConnected')));

this.championSelectHandler.loop();

require('request-promise-native')(`https://manaflux-server.herokuapp.com/api/alerts/v1?v=${this.version}&summoner=${this.user.getSummonerId()}`).then(x => this._alert(x)).catch(err => console.error(err));

UI.status('champion-select-waiting');

this.alertHandler.login();
}

onLeagueDisconnect() {
Expand All @@ -133,11 +134,6 @@ class Mana {
getStore() {
return this._store;
}

_alert(message, repeat) {
if (!repeat && this._lastMessage === message) return;
alertify.warning(this._lastMessage = message);
}
}

module.exports = Mana;
43 changes: 43 additions & 0 deletions objects/handlers/AlertHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const rp = require('request-promise-native');
class AlertHandler {
constructor() {

}

async load() {
return await this._check(Mana.version);
}

async login() {
return await this._check(Mana.version, Mana.user.getSummonerId());
}

async stop() {

}

async _check(version = Mana.version, summonerId) {
const alerts = Mana.getStore().get('alerts', []);

try {
let messages = await rp({ uri: `https://manaflux-server.herokuapp.com/api/alerts/v2?v=${this.version}${summonerId ? '&summoner=' + summonerId : ''}`, json: true });
console.dir(messages);

messages.filter(x => !alerts.includes(x._id)).forEach(x => {
this._alert(x.message);
alerts.push(x._id);
});

Mana.getStore().set('alerts', alerts);
}
catch(err) {
console.error(err);
}
}

_alert(message) {
alertify.warning(message);
}
}

module.exports = AlertHandler;

0 comments on commit 36a7d84

Please sign in to comment.