Skip to content

Commit

Permalink
- Added Discord Rich Presence (disabled by default, can be toggled fr…
Browse files Browse the repository at this point in the history
…om the settings).

- Now uses winston for logging.
- Now kills Stremio Service when the app is closed.
  • Loading branch information
REVENGE977 committed Jan 26, 2024
1 parent d0e5499 commit f8fd70d
Show file tree
Hide file tree
Showing 11 changed files with 980 additions and 429 deletions.
932 changes: 621 additions & 311 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "tsc",
"watch": "tsc -w",
"lint": "eslint -c .eslintrc --ext .ts ./src",
"dev": "cls && npm run build && nodemon --exec electron --log-level=3 ./dist/main.js --devtools",
"dev": "cls && npm run build && npx electron --log-level=3 ./dist/main.js --devtools",
"package-all": "npm run build && npx electron-packager ./ stremio-enhanced --overwrite --asar --platform=all --arch=x64 --prune=true --out=release-builds --icon=./images/icon.ico",
"package-win32": "npm run build && npx electron-packager ./ stremio-enhanced --overwrite --asar --platform=win32 --arch=x64 --prune=true --out=release-builds --icon=./images/icon.ico",
"package-macos": "npm run build && npx electron-packager ./ stremio-enhanced --overwrite --asar --platform=darwin --arch=x64 --prune=true --out=release-builds --icon=./images/icon.ico",
Expand All @@ -23,6 +23,7 @@
"license": "MIT",
"devDependencies": {
"@types/angular": "^1.8.9",
"@types/discord-rpc": "^4.0.8",
"@types/electron": "^1.6.10",
"@types/express": "^4.17.21",
"@typescript-eslint/eslint-plugin": "^4.33.0",
Expand All @@ -31,14 +32,16 @@
"electron-builder": "^23.6.0",
"electron-packager": "^17.1.1",
"eslint": "^7.32.0",
"nodemon": "^2.0.19",
"typescript": "^4.7.2"
},
"dependencies": {
"@types/winston": "^2.4.4",
"angular": "^1.8.3",
"discord-rpc": "^4.0.1",
"electron-prompt": "^1.7.0",
"electron-updater": "^5.3.0",
"express": "^4.18.2"
"express": "^4.18.2",
"winston": "^3.11.0"
},
"files": [
"static/**/*",
Expand Down
58 changes: 58 additions & 0 deletions src/discordpresence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import DiscordRPC from 'discord-rpc';
import logger from './logger';

class DiscordPresence {
public rpc:any;
constructor() {
try {
const clientId = '1200186750727893164';
DiscordRPC.register(clientId);

this.rpc = new DiscordRPC.Client({ transport: 'ipc' });
this.rpc.on('ready', () => {
logger.info('Connected to DiscordRPC.');
this.updateActivity({
details: "Main Menu",
largeImageKey: '1024stremio',
largeImageText: 'Stremio Enhanced',
smallImageKey: "menuburger",
smallImageText: "Main Menu",
instance: false,
})
});

this.rpc.login({ clientId }).catch(logger.error);
}catch(e) {
logger.error(e);
}
}

public updateActivity(newActivity: Activity) {
try {
this.rpc.setActivity(newActivity);
}catch(e) {
logger.error(e)
}
}

public stopActivity() {
logger.info('Clearing DiscordRPC.');
this.rpc.clearActivity();
}
}

interface Activity {
details: string,
state?: string,
startTimestamp?: Date,
endTimestamp?: Date,
largeImageKey: string,
largeImageText?: string,
smallImageKey?: string,
smallImageText?: string,
partySize?: number,
partyMax?: number,
instance: boolean
}

export default DiscordPresence;
Loading

0 comments on commit f8fd70d

Please sign in to comment.