Skip to content

Commit

Permalink
🐞 fix: 修复 UID 登录模式部分功能异常
Browse files Browse the repository at this point in the history
  • Loading branch information
imsyy committed Oct 16, 2024
1 parent a8f01d5 commit 18113d9
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 26 deletions.
6 changes: 5 additions & 1 deletion electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MainProcess {
constructor() {
log.info("🚀 Main process startup");
// 禁用 Windows 7 的 GPU 加速功能
if (release().startsWith("6.1") && type() == 'Windows_NT') app.disableHardwareAcceleration();
if (release().startsWith("6.1") && type() == "Windows_NT") app.disableHardwareAcceleration();
// 单例锁
if (!app.requestSingleInstanceLock()) {
log.error("❌ There is already a program running and this process is terminated");
Expand Down Expand Up @@ -236,6 +236,10 @@ class MainProcess {
}
// 窗口事件
handleWindowEvents() {
this.mainWindow?.on("ready-to-show", () => {
if (!this.mainWindow) return;
this.thumbar = initThumbar(this.mainWindow);
});
this.mainWindow?.on("show", () => {
// this.mainWindow?.webContents.send("lyricsScroll");
});
Expand Down
4 changes: 4 additions & 0 deletions electron/main/ipcMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,10 @@ const initTrayIpcMain = (
// thumbar
const initThumbarIpcMain = (thumbar: Thumbar | null): void => {
if (!thumbar) return;
// 更新工具栏
ipcMain.on("play-status-change", (_, playStatus: boolean) => {
thumbar?.updateThumbar(playStatus);
});
};

// store
Expand Down
9 changes: 5 additions & 4 deletions electron/main/thumbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type ThumbarMap = Map<ThumbarKeys, ThumbarButton>;

export interface Thumbar {
clearThumbar(): void;
updateThumbar(playing: boolean, clean?: boolean): void;
}

// 工具栏图标
Expand All @@ -32,12 +33,12 @@ const createThumbarButtons = (win: BrowserWindow): ThumbarMap => {
.set(ThumbarKeys.Prev, {
tooltip: "上一曲",
icon: thumbarIcon("prev"),
click: () => win.webContents.send("play-prev"),
click: () => win.webContents.send("playPrev"),
})
.set(ThumbarKeys.Next, {
tooltip: "下一曲",
icon: thumbarIcon("next"),
click: () => win.webContents.send("play-next"),
click: () => win.webContents.send("playNext"),
})
.set(ThumbarKeys.Play, {
tooltip: "播放",
Expand All @@ -47,7 +48,7 @@ const createThumbarButtons = (win: BrowserWindow): ThumbarMap => {
.set(ThumbarKeys.Pause, {
tooltip: "暂停",
icon: thumbarIcon("pause"),
click: () => win.webContents.send("play-pause"),
click: () => win.webContents.send("pause"),
});
};

Expand Down Expand Up @@ -75,7 +76,7 @@ class createThumbar implements Thumbar {
this.updateThumbar();
}
// 更新工具栏
private updateThumbar(playing: boolean = false, clean: boolean = false) {
updateThumbar(playing: boolean = false, clean: boolean = false) {
if (clean) return this.clearThumbar();
this._win.setThumbarButtons([this._prev, playing ? this._pause : this._play, this._next]);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "splayer",
"productName": "SPlayer",
"version": "3.0.0-alpha.4",
"version": "3.0.0-beta.1",
"description": "A minimalist music player",
"main": "./out/main/index.js",
"author": "imsyy",
Expand Down
7 changes: 4 additions & 3 deletions src/components/Menu/SongListMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
openPlaylistAdd,
openSongInfoEditor,
} from "@/utils/modal";
import { deleteSongs } from "@/utils/auth";
import { deleteSongs, isLogin } from "@/utils/auth";
import { songUrl } from "@/api/song";
import player from "@/utils/player";

Expand Down Expand Up @@ -64,6 +64,7 @@ const openDropdown = (
const isHasMv = !!song?.mv && song.mv !== 0;
const isCloud = router.currentRoute.value.name === "cloud";
const isLocal = !!song?.path;
const isLoginNormal = isLogin() === 1;
// 是否当前播放
const isCurrent = statusStore.playIndex === index;
// 是否为用户歌单
Expand Down Expand Up @@ -169,7 +170,7 @@ const openDropdown = (
{
key: "cloud-import",
label: "导入至云盘",
show: !isCloud && type === "song" && !isLocal,
show: !isCloud && isLoginNormal && type === "song" && !isLocal,
props: {
onClick: () => importSongToCloud(song),
},
Expand All @@ -178,7 +179,7 @@ const openDropdown = (
{
key: "delete",
label: "从歌单中删除",
show: isUserPlaylist && !isCloud,
show: isUserPlaylist && isLoginNormal && !isCloud,
props: {
onClick: () => deleteSongs(playListId!, [song.id], () => emit("removeSong", [song.id])),
},
Expand Down
6 changes: 3 additions & 3 deletions src/components/Modal/CreatePlaylist.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="create-playlist">
<n-tabs v-model:value="playlistType" type="segment" animated>
<n-tab-pane name="online" tab="在线歌单">
<n-tab-pane :disabled="isLogin() !== 1" name="online" tab="在线歌单">
<n-form ref="onlineFormRef" :model="onlineFormData" :rules="onlineFormRules">
<n-form-item label="歌单名称" path="name">
<n-input v-model:value="onlineFormData.name" placeholder="请输入歌单名称" />
Expand All @@ -28,7 +28,7 @@ import { useDataStore } from "@/stores";
import { textRule } from "@/utils/rules";
import { debounce } from "lodash-es";
import { createPlaylist } from "@/api/playlist";
import { updateUserLikePlaylist } from "@/utils/auth";
import { isLogin, updateUserLikePlaylist } from "@/utils/auth";
const emit = defineEmits<{ close: [] }>();
Expand All @@ -42,7 +42,7 @@ interface OnlineFormType {
const dataStore = useDataStore();
// 歌单类别
const playlistType = ref<"online" | "local">("online");
const playlistType = ref<"online" | "local">(isLogin() === 1 ? "online" : "local");
// 在线歌单数据
const onlineFormRef = ref<FormInst | null>(null);
Expand Down
6 changes: 5 additions & 1 deletion src/components/Modal/PlaylistAdd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import { useDataStore } from "@/stores";
import { coverLoaded } from "@/utils/helper";
import { playlistTracks } from "@/api/playlist";
import { debounce } from "lodash-es";
import { updateUserLikePlaylist, updateUserLikeSongs } from "@/utils/auth";
import { isLogin, updateUserLikePlaylist, updateUserLikeSongs } from "@/utils/auth";
import { openCreatePlaylist } from "@/utils/modal";

const props = defineProps<{
Expand Down Expand Up @@ -86,6 +86,10 @@ const onlinePlaylists = computed(() => {
// 添加到歌单
const addPlaylist = debounce(
async (id: number, index: number) => {
if (isLogin() === 2) {
window.$message.warning("该登录模式暂不支持该操作");
return;
}
loadingMsg.value = window.$message.loading("正在添加歌曲至歌单", { duration: 0 });
const ids = props.data.map((item) => item.id).filter((item) => item !== 0);
const result = await playlistTracks(id, ids);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Player/PlayerCover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const { start: dynamicCoverStart, stop: dynamicCoverStop } = useTimeoutFn(
// 获取动态封面
const getDynamicCover = async () => {
if (
!isLogin() ||
isLogin() !== 1 ||
!musicStore.playSong.id ||
!settingStore.dynamicCover ||
settingStore.playerType !== "cover"
Expand Down
44 changes: 36 additions & 8 deletions src/components/Player/PlayerData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
<div v-if="musicStore.playSong.type !== 'radio'" class="artists">
<SvgIcon :depth="3" name="Artist" size="20" />
<div v-if="Array.isArray(musicStore.playSong.artists)" class="ar-list">
<span v-for="ar in musicStore.playSong.artists" :key="ar.id" class="ar">
<span
v-for="ar in musicStore.playSong.artists"
:key="ar.id"
class="ar"
@click="jumpPage({ name: 'artist', query: { id: ar.id } })"
>
{{ ar.name }}
</span>
</div>
Expand All @@ -44,33 +49,56 @@
<!-- 专辑 -->
<div v-if="musicStore.playSong.type !== 'radio'" class="album">
<SvgIcon :depth="3" name="Album" size="20" />
<span class="name-text text-hidden">
{{
typeof musicStore.playSong.album === "string"
? musicStore.playSong.album || "未知专辑"
: musicStore.playSong.album?.name || "未知专辑"
}}
<span
v-if="isObject(musicStore.playSong.album)"
class="name-text text-hidden"
@click="jumpPage({ name: 'album', query: { id: musicStore.playSong.album.id } })"
>
{{ musicStore.playSong.album?.name || "未知专辑" }}
</span>
<span v-else class="name-text text-hidden">
{{ musicStore.playSong.album || "未知专辑" }}
</span>
</div>
<!-- 电台 -->
<div v-if="musicStore.playSong.type === 'radio'" class="dj">
<div
v-if="musicStore.playSong.type === 'radio'"
class="dj"
@click="jumpPage({ name: 'dj', query: { id: musicStore.playSong.dj?.id } })"
>
<SvgIcon :depth="3" name="Podcast" size="20" />
<span class="name-text text-hidden">{{ musicStore.playSong.dj?.name || "播客电台" }}</span>
</div>
</div>
</template>

<script setup lang="ts">
import type { RouteLocationRaw } from "vue-router";
import { useMusicStore, useStatusStore, useSettingStore } from "@/stores";
import { debounce, isObject } from "lodash-es";
defineProps<{
center?: boolean;
theme?: string;
}>();
const router = useRouter();
const musicStore = useMusicStore();
const statusStore = useStatusStore();
const settingStore = useSettingStore();
const jumpPage = debounce(
(go: RouteLocationRaw) => {
if (!go) return;
statusStore.showFullPlayer = false;
router.push(go);
},
300,
{
leading: true,
trailing: false,
},
);
</script>

<style lang="scss" scoped>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Setting/PlaySetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
</div>
<n-switch
v-model:value="settingStore.dynamicCover"
:disabled="!isLogin()"
:disabled="isLogin() !== 1"
:round="false"
class="set"
/>
Expand Down
5 changes: 4 additions & 1 deletion src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import { likePlaylist, playlistTracks } from "@/api/playlist";
import { likeArtist } from "@/api/artist";
import { radioSub } from "@/api/radio";

// 是否登录
/**
* 用户是否登录
* @returns 0 - 未登录 / 1 - 正常登录 / 2 - UID 登录
*/
export const isLogin = (): 0 | 1 | 2 => {
const dataStore = useDataStore();
if (dataStore.loginType === "uid") return 2;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const openSongInfoEditor = (song: SongType) => {
// 添加到歌单
export const openPlaylistAdd = (data: SongType[], isLocal: boolean) => {
if (!data.length) return window.$message.warning("请正确选择歌曲");
if (!isLogin()) return openUserLogin();
if (!isLogin() && !isLocal) return openUserLogin();
const modal = window.$modal.create({
preset: "card",
transformOrigin: "center",
Expand Down
2 changes: 1 addition & 1 deletion src/utils/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class Player {
});
// 暂停
this.player.on("pause", () => {
window.document.title = "SPlayer";
if (!isElectron) window.document.title = "SPlayer";
// ipc
if (isElectron) window.electron.ipcRenderer.send("play-status-change", false);
console.log("⏸️ song pause:", playSongData);
Expand Down

0 comments on commit 18113d9

Please sign in to comment.