mirror of
https://github.com/NoCrypt/migu.git
synced 2026-04-19 07:32:05 +00:00
feat: discord RPC toggle
This commit is contained in:
parent
c3383db585
commit
f262e35960
4 changed files with 35 additions and 7 deletions
|
|
@ -171,6 +171,7 @@ export const defaults = {
|
|||
enableDoH: false,
|
||||
doHURL: 'https://cloudflare-dns.com/dns-query',
|
||||
disableSubtitleBlur: SUPPORTS.isAndroid,
|
||||
enableRPC: true,
|
||||
showDetailsInRPC: true,
|
||||
smoothScroll: !SUPPORTS.isAndroid,
|
||||
cards: 'small',
|
||||
|
|
|
|||
|
|
@ -15,13 +15,21 @@
|
|||
</script>
|
||||
|
||||
{#if SUPPORTS.discord}
|
||||
<h4 class='mb-10 font-weight-bold'>Rich Pressence Settings</h4>
|
||||
<SettingCard title='Show Details in Discord Rich Presence' description='Shows currently played anime and episode in Discord rich presence.'>
|
||||
<h4 class='mb-10 font-weight-bold'>Rich Presence Settings</h4>
|
||||
<SettingCard title='Discord Rich Presence' description='Enables the use of Discord rich presence to display app activity.'>
|
||||
<div class='custom-switch'>
|
||||
<input type='checkbox' id='rpc-details' bind:checked={settings.showDetailsInRPC} />
|
||||
<label for='rpc-details'>{settings.showDetailsInRPC ? 'On' : 'Off'}</label>
|
||||
<input type='checkbox' id='rpc-enabled' bind:checked={settings.enableRPC} />
|
||||
<label for='rpc-enabled'>{settings.enableRPC ? 'On' : 'Off'}</label>
|
||||
</div>
|
||||
</SettingCard>
|
||||
{#if settings.enableRPC}
|
||||
<SettingCard title='Show Details in Discord Rich Presence' description='Shows currently played anime and episode in Discord rich presence.'>
|
||||
<div class='custom-switch'>
|
||||
<input type='checkbox' id='rpc-details' bind:checked={settings.showDetailsInRPC} />
|
||||
<label for='rpc-details'>{settings.showDetailsInRPC ? 'On' : 'Off'}</label>
|
||||
</div>
|
||||
</SettingCard>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<h4 class='mb-10 font-weight-bold'>Interface Settings</h4>
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
return json.map(({ body, tag_name: version, published_at: date, assets }) => ({ body, version, date, assets }))
|
||||
})()
|
||||
IPC.emit('show-discord-status', settings.value.showDetailsInRPC)
|
||||
IPC.emit('discord-rpc', settings.value.enableRPC)
|
||||
</script>
|
||||
|
||||
<script>
|
||||
|
|
@ -76,6 +77,7 @@
|
|||
IPC.off('path', pathListener)
|
||||
IPC.off('player', playerListener)
|
||||
})
|
||||
$: IPC.emit('discord-rpc', $settings.enableRPC)
|
||||
$: IPC.emit('show-discord-status', $settings.showDetailsInRPC)
|
||||
IPC.on('path', pathListener)
|
||||
IPC.on('player', playerListener)
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ export default class Discord {
|
|||
|
||||
discord = new Client({ transport: 'ipc' })
|
||||
|
||||
/** @type {Discord['defaultStatus'] | undefined} */
|
||||
enableRPC
|
||||
/** @type {Discord['defaultStatus'] | undefined} */
|
||||
allowDiscordDetails
|
||||
/** @type {Discord['defaultStatus'] | undefined} */
|
||||
|
|
@ -42,6 +44,17 @@ export default class Discord {
|
|||
this.debouncedDiscordRPC(this.allowDiscordDetails ? this.cachedPresence : undefined)
|
||||
})
|
||||
|
||||
ipcMain.on('discord-rpc', (event, data) => {
|
||||
if (this.enableRPC !== data) {
|
||||
this.enableRPC = data
|
||||
if (data && !this.discord?.user) {
|
||||
this.loginRPC()
|
||||
} else {
|
||||
this.logoutRPC()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.discord.on('ready', async () => {
|
||||
this.setDiscordRPC(this.cachedPresence || this.defaultStatus)
|
||||
this.discord.subscribe('ACTIVITY_JOIN_REQUEST')
|
||||
|
|
@ -53,8 +66,6 @@ export default class Discord {
|
|||
window.webContents.send('w2glink', secret)
|
||||
})
|
||||
|
||||
this.loginRPC()
|
||||
|
||||
this.debouncedDiscordRPC = debounce(status => this.setDiscordRPC(status), 4500)
|
||||
}
|
||||
|
||||
|
|
@ -64,8 +75,14 @@ export default class Discord {
|
|||
})
|
||||
}
|
||||
|
||||
logoutRPC () {
|
||||
if (this.discord?.user) {
|
||||
this.discord.clearActivity(process.pid)
|
||||
}
|
||||
}
|
||||
|
||||
setDiscordRPC (data = this.defaultStatus) {
|
||||
if (this.discord.user && data) {
|
||||
if (this.discord.user && data && this.enableRPC) {
|
||||
data.pid = process.pid
|
||||
this.discord.request('SET_ACTIVITY', data)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue