From d6a69a4eabfcb9b808ccc4c039c038b8929ba92f Mon Sep 17 00:00:00 2001
From: Tustin <Tustin@users.noreply.github.com>
Date: Sat, 21 Nov 2020 16:00:53 -0600
Subject: [PATCH] add ps5 supported games

---
 package-lock.json     |  5 +++++
 package.json          |  5 +++--
 src/SupportedGames.ts | 17 +++++++++++++++--
 src/app.ts            |  7 ++-----
 src/renderer.ts       |  2 --
 5 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index 47accc7..20dd020 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4726,6 +4726,11 @@
       "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==",
       "dev": true
     },
+    "unorm": {
+      "version": "1.6.0",
+      "resolved": "https://registry.npmjs.org/unorm/-/unorm-1.6.0.tgz",
+      "integrity": "sha512-b2/KCUlYZUeA7JFUuRJZPUtr4gZvBh7tavtv4fvk4+KV9pfGiR6CQAQAWl49ZpR3ts2dk4FYkP7EIgDJoiOLDA=="
+    },
     "update-notifier": {
       "version": "4.1.3",
       "resolved": "https://registry.npmjs.org/update-notifier/-/update-notifier-4.1.3.tgz",
diff --git a/package.json b/package.json
index f4997a9..bea8b4b 100644
--- a/package.json
+++ b/package.json
@@ -46,7 +46,7 @@
     "lint": "tslint --project .",
     "compile": "npm run lint && tsc && sass ./assets/app.scss ./dist/app.css --style=compressed --no-source-map",
     "watch": "tsc -w",
-    "start": "npm run compile && cross-env NODE_ENV=prod electron .",
+    "start": "npm run compile && cross-env NODE_ENV=dev electron .",
     "build:icons": "electron-icon-maker -i ./assets/images/logo.png -o ./build/",
     "build:win": "npm run compile && npm run build:icons && electron-builder build --windows",
     "build:mac": "npm run compile && npm run build:icons && electron-builder build --mac",
@@ -87,7 +87,8 @@
     "lodash": "^4.17.20",
     "normalize.css": "^8.0.1",
     "progress-stream": "^2.0.0",
-    "query-string": "^6.13.7"
+    "query-string": "^6.13.7",
+    "unorm": "^1.6.0"
   },
   "devDependencies": {
     "@types/electron-store": "^1.3.0",
diff --git a/src/SupportedGames.ts b/src/SupportedGames.ts
index e64718f..859f53f 100644
--- a/src/SupportedGames.ts
+++ b/src/SupportedGames.ts
@@ -2,6 +2,7 @@ import _store = require('electron-store');
 import log = require('electron-log');
 import axios from 'axios';
 import { IBasicPresence } from './Model/PresenceModel';
+const unorm = require('unorm');
 
 interface IGame
 {
@@ -69,10 +70,22 @@ class SupportedGames
 
 	public get(presence: IBasicPresence) : IGame
 	{
-		return this.store.get('consoles.ps4').find((game: IGame) => {
+		const console = presence.primaryPlatformInfo.platform.toLowerCase();
+		const consoleStore = `consoles.${console}`;
+		if (!this.store.has(consoleStore))
+		{
+			log.debug('no console found in supported games list.');
+
+			return undefined;
+		}
+
+		return this.store.get(consoleStore).find((game: IGame) => {
 			const titleInfo = presence.gameTitleInfoList[0];
+			if (game.titleId.toLowerCase() === titleInfo.npTitleId.toLowerCase()) {
+				return true;
+			}
 
-			return (game.titleId.toLowerCase() === titleInfo.npTitleId.toLowerCase()) || (game.name.toLowerCase() === titleInfo.titleName.toLowerCase());
+			return unorm.nfc(game.name.toLowerCase()).indexOf(unorm.nfc(titleInfo.titleName.toLowerCase())) !== -1;
 		});
 	}
 }
diff --git a/src/app.ts b/src/app.ts
index fcb35d9..661c1ff 100644
--- a/src/app.ts
+++ b/src/app.ts
@@ -217,14 +217,12 @@ function spawnMainWindow() : void
 
 		playstationAccount.profile()
 		.then((profile) => {
-			log.info('Got PSN profile info', profile);
+			log.debug('Got PSN profile info', profile);
 			mainWindow.webContents.send('profile-data', profile);
 		}).catch((err) => {
 			log.error('Failed fetching PSN profile', err);
 		});
 
-		mainWindow.webContents.openDevTools();
-
 		appEvent.emit('start-rich-presence');
 	});
 
@@ -291,7 +289,6 @@ function updateRichPresence() : void
 {
 	playstationAccount.presences()
 	.then((presence) => {
-		console.log(presence);
 		if (presence.primaryPlatformInfo.onlineStatus !== 'online')
 		{
 			if (discordController && discordController.running())
@@ -358,7 +355,7 @@ function updateRichPresence() : void
 			if (previousPresence === undefined || _.get(previousPresenceTitleInfo, ['npTitleId']) !== _.get(titleInfo, ['npTitleId']))
 			{
 				// See if we're actually playing a title.
-				if (titleInfo.npTitleId === undefined)
+				if (!_.get(titleInfo, ['npTitleId']))
 				{
 					discordRichPresenceData = {
 						details: 'Online',
diff --git a/src/renderer.ts b/src/renderer.ts
index 9c56da6..4bfa083 100644
--- a/src/renderer.ts
+++ b/src/renderer.ts
@@ -66,8 +66,6 @@ ipcRenderer.on('presence-data', (event: any, data: any) => {
 	const details = document.getElementById('details');
 	const state = document.getElementById('state');
 
-	console.log(data);
-
 	state.innerHTML = '';
 	details.innerHTML = data.details;