mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-18 06:07:48 +00:00
refactor: player
This commit is contained in:
parent
0482e6a1ed
commit
f6c36fbcac
22 changed files with 659 additions and 500 deletions
|
|
@ -3,23 +3,13 @@ import Vuex from "vuex";
|
|||
import state from "./state";
|
||||
import mutations from "./mutations";
|
||||
import actions from "./actions";
|
||||
import initLocalStorage from "./initLocalStorage";
|
||||
import { Howler } from "howler";
|
||||
import { changeAppearance } from "@/utils/common";
|
||||
import updateApp from "@/utils/updateApp";
|
||||
import pkg from "../../package.json";
|
||||
import Player from "@/utils/Player";
|
||||
// vuex 自定义插件
|
||||
import { getBroadcastPlugin } from "./plugins/broadcast";
|
||||
import saveToLocalStorage from "./plugins/localStorage";
|
||||
|
||||
if (localStorage.getItem("appVersion") === null) {
|
||||
localStorage.setItem("player", JSON.stringify(initLocalStorage.player));
|
||||
localStorage.setItem("settings", JSON.stringify(initLocalStorage.settings));
|
||||
localStorage.setItem("data", JSON.stringify(initLocalStorage.data));
|
||||
localStorage.setItem("appVersion", pkg.version);
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
updateApp();
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
|
@ -39,19 +29,6 @@ const options = {
|
|||
|
||||
const store = new Vuex.Store(options);
|
||||
|
||||
Howler.volume(store.state.player.volume);
|
||||
// 防止软件第一次打开资源加载2次
|
||||
Howler.autoUnlock = false;
|
||||
|
||||
const currentTrack = store.state?.player?.currentTrack;
|
||||
if (currentTrack?.id) {
|
||||
store.dispatch("switchTrack", {
|
||||
id: currentTrack.id,
|
||||
sort: currentTrack.sort,
|
||||
autoplay: false,
|
||||
});
|
||||
}
|
||||
|
||||
if ([undefined, null].includes(store.state.settings.lang)) {
|
||||
let lang = "en";
|
||||
if (navigator.language.slice(0, 2) === "zh") lang = "zh-CN";
|
||||
|
|
@ -69,4 +46,17 @@ window
|
|||
}
|
||||
});
|
||||
|
||||
let player = new Player();
|
||||
player = new Proxy(player, {
|
||||
set(target, prop, val) {
|
||||
// console.log({ prop, val });
|
||||
target[prop] = val;
|
||||
if (prop === "_howler") return true;
|
||||
target.saveSelfToLocalStorage();
|
||||
target.sendSelfToIpcMain();
|
||||
return true;
|
||||
},
|
||||
});
|
||||
store.state.player = player;
|
||||
|
||||
export default store;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue