Skip to content

Commit

Permalink
Disable rich presence option in MAS and Snap, and add docs link
Browse files Browse the repository at this point in the history
If it won't work let's not waste the user's time.
#1006
#1005
  • Loading branch information
GarboMuffin committed May 31, 2024
1 parent 9cbcf2e commit 5f53a75
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
10 changes: 9 additions & 1 deletion src-main/l10n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,15 @@
},
"desktop-settings.rich-presence": {
"string": "Enable Rich Presence",
"developer_comment": "Option to enable Discord rich presence support, which shows the name of the project someone is editing on their Discord profile. For compliance with Scratch policies don't use the word \"Discord\" in the translation."
"developer_comment": "Option to enable Discord Rich Presence support, which shows the name of the project someone is editing on their Discord profile. For compliance with Scratch policies don't use the word \"Discord\" in the translation."
},
"desktop-settings.rich-presence-unavailable": {
"string": "Rich Presence is not available in this version of the app",
"developer_comment": "Appears in desktop settings after a disabled checkbox (grayed out and unchangeable) if Discord Rich Presence can't be enabled."
},
"desktop-settings.more-information": {
"string": "(more information)",
"developer_comment": "Appears in desktop settings after options as a link to a webpage with more information about the option."
},
"desktop-settings.open-user-data": {
"string": "Open User Data",
Expand Down
12 changes: 11 additions & 1 deletion src-main/rich-presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const pathUtil = require('path');
const nodeCrypto = require('crypto');
const {APP_NAME} = require('./brand');
const {translate} = require('./l10n');
const {getPlatform} = require('./platform');
const settings = require('./settings');

// Ask GarboMuffin for changes
Expand Down Expand Up @@ -185,12 +186,21 @@ class RichPresence {
this.handleSocketError = this.handleSocketError.bind(this);
}

isAvailable () {
// In the Mac App Store, our tmpdir is ~/Library/Containers/org.turbowarp.desktop/Data/tmp/
// while the IPC file is /var/folders/.../.../T/discord-ipc-#
// In the Linux Snap Store, our tmpdir is /run/user/.../snap.turbowarp-desktop/
// while the IPC file is /run/user/.../snap.discord/discord-ipc-#
// In both cases the platform sandbox should stop us from accessing the IPC file.
return !(process.mas || getPlatform() === 'linux-snap');
}

checkAutomaticEnable () {
if (this.checkedAutomaticEnable) {
return;
}
this.checkedAutomaticEnable = true;
if (settings.richPresence) {
if (settings.richPresence && this.isAvailable()) {
this.enable();
}
}
Expand Down
1 change: 1 addition & 0 deletions src-main/windows/desktop-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class DesktopSettingsWindow extends AbstractWindow {
bypassCORS: settings.bypassCORS,
spellchecker: settings.spellchecker,
exitFullscreenOnEscape: settings.exitFullscreenOnEscape,
richPresenceAvailable: RichPresence.isAvailable(),
richPresence: settings.richPresence
};
});
Expand Down
21 changes: 16 additions & 5 deletions src-renderer/desktop-settings/desktop-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,25 @@ <h1 class="title"></h1>
<label>
<input type="checkbox" class="rich-presence-checkbox" autocomplete="off">
<span class="rich-presence-label"></span>
<a class="rich-presence-more-information" href="https://docs.turbowarp.org/desktop/rich-presence" target="_blank" rel="noreferrer"></a>
</label>
<script>
const richPresence = document.querySelector('.rich-presence-checkbox');
richPresence.onchange = () => {
DesktopSettingsPreload.setRichPresence(richPresence.checked);
};
richPresence.checked = settings.richPresence;
document.querySelector('.rich-presence-label').textContent = strings['desktop-settings.rich-presence'];
const richPresenceLabel = document.querySelector('.rich-presence-label');
const richPresenceMoreInformation = document.querySelector('.rich-presence-more-information');
if (settings.richPresenceAvailable) {
richPresence.onchange = () => {
DesktopSettingsPreload.setRichPresence(richPresence.checked);
};
richPresence.checked = settings.richPresence;
richPresenceLabel.textContent = strings['desktop-settings.rich-presence'];
} else {
richPresence.disabled = true;
richPresence.checked = false;
richPresenceLabel.textContent = strings['desktop-settings.rich-presence-unavailable'];
richPresenceMoreInformation.href += '#supported-platforms';
}
richPresenceMoreInformation.textContent = strings['desktop-settings.more-information'];
</script>

<button class="open-user-data"></button>
Expand Down

0 comments on commit 5f53a75

Please sign in to comment.