Skip to content

Commit

Permalink
Merge branch 'pr/2' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
cwkhawand committed May 13, 2021
2 parents 2607a44 + 697ae68 commit 05f2a99
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Growtopia Discord Rich Presence by GrowStocks.


# Instructions
- Download the .exe from the "Releases" tab
- Open the .exe file (the presence will only show if Growtopia and Discord are open at the same time)
- Download the correct file for your operating system from the "Releases" tab
- Open the downloaded file (the presence will only show if Growtopia and Discord are open at the same time)
- If the Rich Presence doesn't show on Discord, try completely closing then re-opening Discord

# Instructions (if you're a skeptic)
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ data = null;
data = await Growtopia.generateRPCData();
if(Growtopia.clientIsOpen) client.setActivity(data).catch(e=>e);
}catch(e){
console.log(e);
process.exit(0);
}
}
Expand Down
6 changes: 5 additions & 1 deletion modules/Application.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
const path = require('path');
const fetch = require('node-fetch');
var os = require('os');

class Application {
constructor() {
this.clientID = "841694148758208542";
this.version = "v1.2.1";
this.version = "v1.3.1";
this.device = {
isMacOS: os.platform() === 'darwin'
};
}

checkForUpdates(){
Expand Down
23 changes: 23 additions & 0 deletions modules/DiscordHelper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const exec = require('child_process').exec;
const findProcess = require('find-process');
const EventEmitter = require('events');
const Application = require('../modules/Application.js');

class DiscordHelper extends EventEmitter {
constructor(){
Expand All @@ -8,6 +10,11 @@ class DiscordHelper extends EventEmitter {
}

async isOpen(){
if(Application.device.isMacOS) return await this.isOpenMacOS();
else return await this.isOpenWindows();
}

async isOpenWindows(){
return new Promise((resolve, reject) => {
exec('tasklist', (err, stdout, stderr) => {
if(!stdout) resolve(false);
Expand All @@ -16,6 +23,22 @@ class DiscordHelper extends EventEmitter {
});
}

async isOpenMacOs(){
return new Promise((resolve, reject) => {
let isFound = findProcess('name', 'Discord').then(list => {
for (let ver of ['', ' PTB', ' Canary']) {
for (let process of list) {
if (process.name === 'Discord' + ver) {
return true;
}
}
}
return false;
})
resolve(isFound);
});
}

checkAppStatus(){
let self = this;
(async function check(){
Expand Down
27 changes: 24 additions & 3 deletions modules/GrowtopiaHelper.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
const exec = require('child_process').exec;
const findProcess = require('find-process');
const EventEmitter = require('events');
const fs = require('fs');
const Application = require('../modules/Application.js');

class GrowtopiaHelper extends EventEmitter {
constructor(){
super();
this.clientIsOpen = false;
this.startedPlaying = new Date();
this.appData = `${process.env.APPDATA}\\..\\Local\\Growtopia`;
this.appData = Application.device.isMacOS ? `${process.env.HOME}/Library/Application Support/growtopia` : `${process.env.APPDATA}\\..\\Local\\Growtopia`;
this.splitter = Application.device.isMacOS ? '/' : `\\`

fs.watchFile(`${this.appData}\\save.dat`, (curr, prev) => {
fs.watchFile(`${this.appData}${this.splitter}save.dat`, (curr, prev) => {
this.emit("saveDatUpdate");
});
}

async isOpen(){
if(Application.device.isMacOS) return await this.isOpenMacOS();
else return await this.isOpenWindows();
}

async isOpenWindows(){
return new Promise((resolve, reject) => {
exec('tasklist', (err, stdout, stderr) => {
if(!stdout) resolve(false);
Expand All @@ -23,6 +31,19 @@ class GrowtopiaHelper extends EventEmitter {
});
}

async isOpenMacOS(){
return new Promise((resolve, reject) => {
let isFound = findProcess('name', 'Growtopia').then(list => {
for (let process of list) {
if (process.name === 'Growtopia') {
resolve(true);
}
}
resolve(false);
})
});
}

checkAppStatus(){
let self = this;
(async function check(){
Expand All @@ -43,7 +64,7 @@ class GrowtopiaHelper extends EventEmitter {

async readSaveDat(){
return new Promise((resolve, reject) => {
fs.readFile(`${this.appData}\\save.dat`, 'utf8' , (err, data) => {
fs.readFile(`${this.appData}${this.splitter}save.dat`, 'utf8' , (err, data) => {
if(err){
return reject(err);
}
Expand Down
78 changes: 77 additions & 1 deletion package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "growtopia-discord-presence",
"version": "1.1.1",
"version": "1.3.1",
"description": "Growtopia Discord Rich Presence by GrowStocks",
"main": "index.js",
"scripts": {
Expand All @@ -17,7 +17,9 @@
"license": "GPL-3.0",
"dependencies": {
"discord-rpc": "^3.2.0",
"node-fetch": "^2.6.1"
"find-process": "^1.4.4",
"node-fetch": "^2.6.1",
"os": "^0.1.1"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 05f2a99

Please sign in to comment.