Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update stuff #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SwitchRPC is a Rich Presence application for Discord that allows you to set your
If you have any issues or find any bugs you can get assistance on the [support server.](https://discord.gg/NqG6pN9)

## Installation
If you're on windows, head over to the [releases](https://github.com/NintenZone/SwitchRPC.git) tab and grab the latest release.
If you're on Windows, head over to the [releases](https://github.com/NintenZone/SwitchRPC.git) tab and grab the latest release.
Mac and Linux installers coming soon™.

### Manual Installation (Useful for Mac and Linux Installs)
Expand Down
37 changes: 15 additions & 22 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,28 +160,21 @@ <h2>Supported Titles</h2>
</div>

<script>
const electron = require('electron');
const {ipcRenderer, ipcMain} = electron;
const { ipcRenderer, ipcMain } = require('electron');

const x = document.getElementById("x");
const max = document.getElementById("max");
const min = document.getElementById("min");
const x = document.getElementById('x');
const max = document.getElementById('max');
const min = document.getElementById('min');

x.addEventListener('click', sendX);
max.addEventListener('click', sendMax);
min.addEventListener('click', sendMin);

function sendX(e) {
x.addEventListener('click', function (e) {
ipcRenderer.send('x');
}

function sendMax(e) {
});
max.addEventListener('click', function (e) {
ipcRenderer.send('max');
}

function sendMin(e) {
});
min.addEventListener('click', function (e) {
ipcRenderer.send('min');
}
});

const form = document.querySelector('form');
form.addEventListener('submit', submitForm);
Expand All @@ -194,13 +187,13 @@ <h2>Supported Titles</h2>
ipcRenderer.send('desc:value', desc);
}

document.addEventListener("DOMContentLoaded", function() {
document.addEventListener('DOMContentLoaded', function () {
ipcRenderer.send('getGameData');

ipcRenderer.on('sendingGameData', function(e, data) {
data.forEach(function(game) {
document.getElementById("title-container").innerHTML += `<h4>${game}</h4>`;
})
ipcRenderer.on('sendingGameData', function (e, data) {
data.forEach(function (game) {
document.getElementById('title-container').innerHTML += `<h4>${game}</h4>`;
});
})
})

Expand Down
38 changes: 18 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ let version = 4;

//dependencies
const rpc = require('discord-rich-presence')('387406899739623426');
const request = require('request');
const axios = require('axios');
const { app, BrowserWindow, ipcMain } = require('electron');
const url = require('url');
const path = require('path');

let mainWindow;
let data;
Expand All @@ -24,27 +22,27 @@ function createWindow() {

mainWindow.setMenu(null);

request('http://nintenbot.js.org/rpc.json', function(err, res, body) {
if (err || !body) {
axios.get('https://nintenbot.js.org/rpc.json').then((res, err) => {
if (err || !res.data) {
mainWindow.loadFile('no-server.html');
}
try {
data = JSON.parse(body);
mainWindow.loadFile('index.html')
data = res.data;
mainWindow.loadFile('index.html');
}
catch(e) {
mainWindow.loadFile('no-server.html')
mainWindow.loadFile('no-server.html');
}
});
}

app.whenReady().then(createWindow);


ipcMain.on('getGameData', function(event) {
ipcMain.on('getGameData', function (event) {
let gameArray = [];

data.gameLibrary.forEach(function(game) {
data.gameLibrary.forEach(function (game) {
gameArray.push(game.name);
});

Expand All @@ -63,7 +61,7 @@ ipcMain.on('max', function () {
else return mainWindow.maximize();
});

ipcMain.on('min', function() {
ipcMain.on('min', function () {
if (!mainWindow) return;
mainWindow.minimize();
});
Expand All @@ -80,23 +78,23 @@ ipcMain.on('desc:value', function (e, value) {
findGame();
});

let status = "online";
ipcMain.on("online", function() {
status = "online";
let status = 'online';
ipcMain.on('online', function () {
status = 'online';
findGame();
});
ipcMain.on("away", function() {
status = "away";
ipcMain.on('away', function () {
status = 'away';
findGame();
});

//RPC
function findGame() {
let gotGame = name;
let pic = "switch";
let pic = 'switch';
if (!name || !desc) return;
data.gameLibrary.forEach(function(game) {
game.aliases.forEach(function(alias) {
data.gameLibrary.forEach(function (game) {
game.aliases.forEach(function (alias) {
if (alias === name.toLowerCase()) {
gotGame = game.name;
pic = game.pic;
Expand All @@ -115,5 +113,5 @@ function setPresence(game, desc, pic, status) {
largeImageText: game,
smallImageKey: status,
smallImageText: status.charAt(0).toUpperCase() + status.slice(1)
})
});
}
27 changes: 10 additions & 17 deletions no-server.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,21 @@

<h2>Could not connect to the server. Please make sure this application is not blocked in your firewall and that you are connected to the internet.</h2>
<script>
const electron = require('electron');
const {ipcRenderer} = electron;
const { ipcRenderer } = require('electron');

const x = document.getElementById("x");
const max = document.getElementById("max");
const min = document.getElementById("min");
const x = document.getElementById('x');
const max = document.getElementById('max');
const min = document.getElementById('min');

x.addEventListener('click', sendX);
max.addEventListener('click', sendMax);
min.addEventListener('click', sendMin);

function sendX(e) {
x.addEventListener('click', function (e) {
ipcRenderer.send('x');
}

function sendMax(e) {
});
max.addEventListener('click', function (e) {
ipcRenderer.send('max');
}

function sendMin(e) {
});
min.addEventListener('click', function (e) {
ipcRenderer.send('min');
}
});
</script>
</body>
</html>
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
},
"homepage": "https://github.com/NintenZone/SwitchRPC#readme",
"dependencies": {
"axios": "^0.19.2",
"discord-rich-presence": "0.0.8",
"electron-squirrel-startup": "^1.0.0",
"request": "^2.88.2"
"electron-squirrel-startup": "^1.0.0"
},
"devDependencies": {
"asar": "^3.0.3",
Expand Down