Skip to content

Commit

Permalink
Add Discord rich presence integration. Fixes #2915
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Dec 17, 2017
1 parent 3405b71 commit 125c233
Show file tree
Hide file tree
Showing 22 changed files with 63 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -60,7 +60,8 @@
"dependencies": {
"archiver": "^1.0.1",
"auto-launch": "^4.0.0",
"electron": "1.6.1",
"discord-rich-presence": "^0.0.5",
"electron": "1.7.9",
"electron-chromecast": "^1.1.0",
"gmusic-mini-player.js": "^2.0.10",
"gmusic-theme.js": "^2.1.16",
Expand Down
1 change: 1 addition & 0 deletions src/_locales/cs.json
Expand Up @@ -97,6 +97,7 @@
"settings-option-enable-taskbar-progress": "Ukázat průběh skladby na hlavním panelu",
"settings-option-enable-win10-media-service": "",
"settings-option-enable-win10-media-service-details": "",
"settings-option-discord-rich-presence": "",
"settings-option-enable-win10-media-service-track-info": "",
"settings-option-change-locale": "Vybrat jazyk (Language)",

Expand Down
1 change: 1 addition & 0 deletions src/_locales/da.json
Expand Up @@ -97,6 +97,7 @@
"settings-option-enable-taskbar-progress": "Vis sangens forløb i proceslinjen.",
"settings-option-enable-win10-media-service": "",
"settings-option-enable-win10-media-service-details": "",
"settings-option-discord-rich-presence": "",
"settings-option-enable-win10-media-service-track-info": "",
"settings-option-change-locale": "Vælg sprog",

Expand Down
1 change: 1 addition & 0 deletions src/_locales/de.json
Expand Up @@ -97,6 +97,7 @@
"settings-option-enable-taskbar-progress": "Zeige den Fortschritt des Titels in der Taskleiste",
"settings-option-enable-win10-media-service": "Aktiviere den Windows 10-System Media Service",
"settings-option-enable-win10-media-service-details": "Dies zeigt den aktuellen Titel auf dem Sperrbildschirm",
"settings-option-discord-rich-presence": "",
"settings-option-enable-win10-media-service-track-info": "Zeige Liedinformationen in der Windows 10-Lautstärkeanzeige an",
"settings-option-change-locale": "Wähle eine andere Sprache",

Expand Down
1 change: 1 addition & 0 deletions src/_locales/en-US.json
Expand Up @@ -98,6 +98,7 @@
"settings-option-enable-win10-media-service": "Enable the Windows 10 System Media Service",
"settings-option-enable-win10-media-service-details": "This will show the current track on the lock screen",
"settings-option-enable-win10-media-service-track-info": "Show track information in Windows 10 volume overlay",
"settings-option-discord-rich-presence": "Enable Discord Rich Presence integration",
"settings-option-change-locale": "Choose language",

"settings-option-hotkey-explanation": "Default media keys will continue to work regardless of these settings. These settings are in addition to the defaults.",
Expand Down
1 change: 1 addition & 0 deletions src/_locales/es-ES.json
Expand Up @@ -97,6 +97,7 @@
"settings-option-enable-taskbar-progress": "Mostrar el progreso de la pista en la barra de tareas",
"settings-option-enable-win10-media-service": "Habilitar Servicio Multimedia Windows 10",
"settings-option-enable-win10-media-service-details": "Mostrar la pista actual en la pantalla de bloqueo",
"settings-option-discord-rich-presence": "",
"settings-option-enable-win10-media-service-track-info": "Mostrar información de la pista en la superposición de volumen de Windows 10",
"settings-option-change-locale": "Escoger Idioma",

Expand Down
1 change: 1 addition & 0 deletions src/_locales/fr-FR.json
Expand Up @@ -97,6 +97,7 @@
"settings-option-enable-taskbar-progress": "Afficher la progression du morceau dans la barre des tâches",
"settings-option-enable-win10-media-service": "Activer le Service Multimedia de Windows 10",
"settings-option-enable-win10-media-service-details": "Cela montrera la piste courante sur l'écran de verrouillage",
"settings-option-discord-rich-presence": "",
"settings-option-enable-win10-media-service-track-info": "",
"settings-option-change-locale": "Choisir un langage",

Expand Down
1 change: 1 addition & 0 deletions src/_locales/hu.json
Expand Up @@ -97,6 +97,7 @@
"settings-option-enable-taskbar-progress": "Zeneszám nyomon követése a tálcán",
"settings-option-enable-win10-media-service": "Engedélyezze a Windows 10-es rendszer médiaszolgáltatását",
"settings-option-enable-win10-media-service-details": "Aktuális zeneszám megjelenítése lezárt képernyőn",
"settings-option-discord-rich-presence": "",
"settings-option-enable-win10-media-service-track-info": "Mutassa a zeneszám részleteit a Windows 10 hangerő ablakában",
"settings-option-change-locale": "Válasszon nyelvet",

Expand Down
1 change: 1 addition & 0 deletions src/_locales/it.json
Expand Up @@ -97,6 +97,7 @@
"settings-option-enable-taskbar-progress": "Mostra il progresso del brano nella barra delle applicazioni",
"settings-option-enable-win10-media-service": "Abilita il System Media Service di Windows 10",
"settings-option-enable-win10-media-service-details": "Mostra il brano corrente nella schermata di blocco",
"settings-option-discord-rich-presence": "",
"settings-option-enable-win10-media-service-track-info": "Mostra le informazioni del brano nell'indicatore del volume di Windows 10",
"settings-option-change-locale": "Seleziona lingua",

Expand Down
1 change: 1 addition & 0 deletions src/_locales/ja.json
Expand Up @@ -97,6 +97,7 @@
"settings-option-enable-taskbar-progress": "曲の進行状況をタスクバーに表示する",
"settings-option-enable-win10-media-service": "Windows 10のSystem Media Serviceを有効にする",
"settings-option-enable-win10-media-service-details": "これによりロック画面に現在の曲が表示されるようになります",
"settings-option-discord-rich-presence": "",
"settings-option-enable-win10-media-service-track-info": "",
"settings-option-change-locale": "言語",

Expand Down
1 change: 1 addition & 0 deletions src/_locales/nl-NL.json
Expand Up @@ -97,6 +97,7 @@
"settings-option-enable-taskbar-progress": "",
"settings-option-enable-win10-media-service": "",
"settings-option-enable-win10-media-service-details": "",
"settings-option-discord-rich-presence": "",
"settings-option-enable-win10-media-service-track-info": "",
"settings-option-change-locale": "",

Expand Down
1 change: 1 addition & 0 deletions src/_locales/pirate.json
Expand Up @@ -97,6 +97,7 @@
"settings-option-enable-taskbar-progress": "Show track progress in th' taskbar",
"settings-option-enable-win10-media-service": "Tell ye' OS what track be playin'",
"settings-option-enable-win10-media-service-details": "",
"settings-option-discord-rich-presence": "",
"settings-option-enable-win10-media-service-track-info": "",
"settings-option-change-locale": "Choose how ye speak",

Expand Down
1 change: 1 addition & 0 deletions src/_locales/pl-PL.json
Expand Up @@ -97,6 +97,7 @@
"settings-option-enable-taskbar-progress": "Pokazuj postęp utworu na pasku systemowym",
"settings-option-enable-win10-media-service": "Włącz System Media Service (Windows 10)",
"settings-option-enable-win10-media-service-details": "Pokazuj informacje o aktualnym utworze na ekranie blokady",
"settings-option-discord-rich-presence": "",
"settings-option-enable-win10-media-service-track-info": "Pokazuj informacje o aktualnym utworze razem z informacją o ustawieniach głośności (Windows 10)",
"settings-option-change-locale": "Wybierz język aplikacji",

Expand Down
1 change: 1 addition & 0 deletions src/_locales/pt-BR.json
Expand Up @@ -97,6 +97,7 @@
"settings-option-enable-taskbar-progress": "Mostrar o progresso da musica na barra de tarefas",
"settings-option-enable-win10-media-service": "",
"settings-option-enable-win10-media-service-details": "",
"settings-option-discord-rich-presence": "",
"settings-option-enable-win10-media-service-track-info": "",
"settings-option-change-locale": "Escolher linguagem",

Expand Down
1 change: 1 addition & 0 deletions src/_locales/ro.json
Expand Up @@ -97,6 +97,7 @@
"settings-option-enable-taskbar-progress": "Arată progresul melodiei în bara de sistem",
"settings-option-enable-win10-media-service": "Activează Windows 10 System Media Service",
"settings-option-enable-win10-media-service-details": "Afișează melodia curentă pe ecranul de blocare",
"settings-option-discord-rich-presence": "",
"settings-option-enable-win10-media-service-track-info": "Afișează informații despre melodie în Window 10 volum overlay",
"settings-option-change-locale": "Alege limba",

Expand Down
1 change: 1 addition & 0 deletions src/_locales/ru.json
Expand Up @@ -97,6 +97,7 @@
"settings-option-enable-taskbar-progress": "Показывать позицию воспроизведения в панели задач",
"settings-option-enable-win10-media-service": "Включить поддержку медиасервиса Windows 10",
"settings-option-enable-win10-media-service-details": "Информация о текущем треке будет выводиться на экране блокировки",
"settings-option-discord-rich-presence": "",
"settings-option-enable-win10-media-service-track-info": "Показывать информацию о текущем треке рядом со всплывающим индикатором громкости Windows 10",
"settings-option-change-locale": "Язык программы",

Expand Down
1 change: 1 addition & 0 deletions src/_locales/sk.json
Expand Up @@ -97,6 +97,7 @@
"settings-option-enable-taskbar-progress": "Zobraziť priebeh skladby na panely úloh",
"settings-option-enable-win10-media-service": "Povoliť Windows 10 System Media Service",
"settings-option-enable-win10-media-service-details": "Zobrazí aktuálnu skladbu na uzamknutej obrazovke",
"settings-option-discord-rich-presence": "",
"settings-option-enable-win10-media-service-track-info": "Zobraziť informácie o skladbe na prekrytí hlasitosti vo Windows 10",
"settings-option-change-locale": "Vybrať jazyk",

Expand Down
1 change: 1 addition & 0 deletions src/_locales/sv.json
Expand Up @@ -97,6 +97,7 @@
"settings-option-enable-taskbar-progress": "Visa låtens förlopp i processraden.",
"settings-option-enable-win10-media-service": "Aktivera Windows 10-mediatjänsten",
"settings-option-enable-win10-media-service-details": "Detta kommer att visa nuvarande låten på låsskärmen",
"settings-option-discord-rich-presence": "",
"settings-option-enable-win10-media-service-track-info": "",
"settings-option-change-locale": "Välj språk",

Expand Down
1 change: 1 addition & 0 deletions src/_locales/ua.json
Expand Up @@ -97,6 +97,7 @@
"settings-option-enable-taskbar-progress": "Відобразити прогрес відтворення в панелі",
"settings-option-enable-win10-media-service": "Увімкнути медіа сервіс Windows 10",
"settings-option-enable-win10-media-service-details": "Буде показувати активний трек на екрані блокування",
"settings-option-discord-rich-presence": "",
"settings-option-enable-win10-media-service-track-info": "",
"settings-option-change-locale": "Обрати мову",

Expand Down
41 changes: 41 additions & 0 deletions src/main/features/core/discordRickPresence.js
@@ -0,0 +1,41 @@
import { app } from 'electron';
import createDiscordClient from 'discord-rich-presence';

let client;

let lastTrack = null;
let lastStart = new Date(0);

const setPresence = () => {
if (!Settings.get('discordRichPresence', false)) return;

client = client || createDiscordClient('391934620418965504');
const time = PlaybackAPI.currentTime();
const currentTrack = PlaybackAPI.currentSong();
const track = currentTrack || lastTrack;
const start = new Date(Date.now() - time.current);
if (JSON.stringify(track) !== JSON.stringify(lastTrack) || Math.round(start.getTime() / 1000) !== Math.round(lastStart.getTime() / 1000)) {
const end = new Date(start.getTime() + time.total);
lastTrack = track;
lastStart = start;

if (!track) return;

client.updatePresence({
state: `👤 ${track.artist}`,
details: `🎵 ${track.title}`,
startTimestamp: start,
endTimestamp: end,
instance: false,
largeImageKey: 'playing',
largeImageText: 'Google Play Music',
});
}
};

app.on('before-quit', () => {
client.updatePresence();
});

PlaybackAPI.on('change:track', setPresence);
PlaybackAPI.on('change:time', setPresence);
1 change: 1 addition & 0 deletions src/main/features/core/index.js
Expand Up @@ -16,3 +16,4 @@ import './customStyle';
import './alarm.js';
import './sleepPreventor';
import './mediaService';
import './discordRickPresence';
1 change: 1 addition & 0 deletions src/renderer/ui/components/settings/tabs/GeneralTab.js
Expand Up @@ -70,6 +70,7 @@ class GeneralTab extends Component {
dependsOnSettingsKey={"enableWin10MediaService"}
/>
</PlatformSpecific>
<ToggleableOption label={TranslationProvider.query('settings-option-discord-rich-presence')} settingsKey="discordRichPresence" />

<LocaleSelector />
</SettingsTabWrapper>
Expand Down

3 comments on commit 125c233

@jostrander
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discord Rick presence 🤔

@MarshallOfSound
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Urgh, typos :rip:

I'm going to sleep, will fix in the morning if no one does the easy PR first ;)

@Turbotailz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it.
Sorry about the 2 pull requests, I've never done one before 🤣

Please sign in to comment.