|
16 | 16 | <n-text class="name">API Key</n-text> |
17 | 17 | <n-text class="tip" :depth="3"> |
18 | 18 | 在 |
19 | | - <n-a href="https://www.last.fm/zh/api/account/create" target="_blank">Last.fm 创建应用</n-a> |
| 19 | + <n-a href="https://www.last.fm/zh/api/account/create" target="_blank"> |
| 20 | + Last.fm 创建应用 |
| 21 | + </n-a> |
20 | 22 | 获取,只有「程序名称」是必要的 |
21 | 23 | </n-text> |
22 | 24 | <n-text class="tip" :depth="3"> |
23 | 25 | 如果已经创建过,则可以在 |
24 | | - <n-a href="https://www.last.fm/zh/api/accounts" target="_blank">Last.fm API 应用程序</n-a> |
| 26 | + <n-a href="https://www.last.fm/zh/api/accounts" target="_blank"> |
| 27 | + Last.fm API 应用程序 |
| 28 | + </n-a> |
25 | 29 | 处查看 |
26 | 30 | </n-text> |
27 | 31 | </div> |
|
92 | 96 | </n-card> |
93 | 97 | </n-collapse-transition> |
94 | 98 | </div> |
95 | | - |
| 99 | + <div v-if="isElectron && isWin" class="set-list"> |
| 100 | + <n-h3 prefix="bar"> Discord RPC </n-h3> |
| 101 | + <n-card class="set-item"> |
| 102 | + <div class="label"> |
| 103 | + <n-text class="name">启用 Discord RPC</n-text> |
| 104 | + <n-text class="tip" :depth="3"> 在 Discord 状态中显示正在播放的歌曲 </n-text> |
| 105 | + </div> |
| 106 | + <n-switch |
| 107 | + class="set" |
| 108 | + v-model:value="settingStore.discordRpc.enabled" |
| 109 | + :round="false" |
| 110 | + @update:value="handleDiscordEnabledUpdate" |
| 111 | + /> |
| 112 | + </n-card> |
| 113 | + <n-collapse-transition :show="settingStore.discordRpc.enabled"> |
| 114 | + <n-card class="set-item"> |
| 115 | + <div class="label"> |
| 116 | + <n-text class="name">暂停时显示</n-text> |
| 117 | + <n-text class="tip" :depth="3">暂停播放时是否保留 Discord 状态</n-text> |
| 118 | + </div> |
| 119 | + <n-switch |
| 120 | + class="set" |
| 121 | + v-model:value="settingStore.discordRpc.showWhenPaused" |
| 122 | + :round="false" |
| 123 | + @update:value="handleDiscordConfigUpdate" |
| 124 | + /> |
| 125 | + </n-card> |
| 126 | + <n-card class="set-item"> |
| 127 | + <div class="label"> |
| 128 | + <n-text class="name">显示模式</n-text> |
| 129 | + <n-text class="tip" :depth="3">选择在 Discord 状态中展示的内容层级</n-text> |
| 130 | + </div> |
| 131 | + <n-select |
| 132 | + class="set" |
| 133 | + v-model:value="settingStore.discordRpc.displayMode" |
| 134 | + :options="[ |
| 135 | + { label: '完整信息 (歌曲名/歌手)', value: 'details' }, |
| 136 | + { label: '仅歌曲名', value: 'name' }, |
| 137 | + { label: '仅播放状态', value: 'state' }, |
| 138 | + ]" |
| 139 | + @update:value="handleDiscordConfigUpdate" |
| 140 | + /> |
| 141 | + </n-card> |
| 142 | + </n-collapse-transition> |
| 143 | + </div> |
96 | 144 | <div v-if="isElectron" class="set-list"> |
97 | 145 | <n-h3 prefix="bar"> WebSocket 配置 </n-h3> |
98 | 146 | <n-card class="set-item"> |
|
143 | 191 | <script setup lang="ts"> |
144 | 192 | import { useSettingStore } from "@/stores"; |
145 | 193 | import { getAuthToken, getAuthUrl, getSession } from "@/api/lastfm"; |
146 | | -import { isElectron } from "@/utils/env"; |
| 194 | +import { isElectron, isWin } from "@/utils/env"; |
| 195 | +import { enableDiscordRpc, disableDiscordRpc, updateDiscordConfig } from "@/core/player/PlayerIpc"; |
147 | 196 |
|
148 | 197 | const settingStore = useSettingStore(); |
149 | 198 |
|
@@ -238,6 +287,25 @@ const disconnectLastfm = () => { |
238 | 287 | }); |
239 | 288 | }; |
240 | 289 |
|
| 290 | +// Discord RPC |
| 291 | +const handleDiscordEnabledUpdate = (val: boolean) => { |
| 292 | + if (val) { |
| 293 | + enableDiscordRpc(); |
| 294 | + // 启用时同步一次配置 |
| 295 | + handleDiscordConfigUpdate(); |
| 296 | + } else { |
| 297 | + disableDiscordRpc(); |
| 298 | + } |
| 299 | +}; |
| 300 | +
|
| 301 | +const handleDiscordConfigUpdate = () => { |
| 302 | + if (!settingStore.discordRpc.enabled) return; |
| 303 | + updateDiscordConfig({ |
| 304 | + showWhenPaused: settingStore.discordRpc.showWhenPaused, |
| 305 | + displayMode: settingStore.discordRpc.displayMode, |
| 306 | + }); |
| 307 | +}; |
| 308 | +
|
241 | 309 | // 初始化 socket 配置 |
242 | 310 | const initSocketConfig = async () => { |
243 | 311 | if (!isElectron) return; |
|
0 commit comments