feat: support Last.fm scrobble

This commit is contained in:
qier222 2021-03-23 23:43:29 +08:00
parent cc50faeb09
commit 55585a921f
No known key found for this signature in database
GPG key ID: 9C85007ED905F14D
12 changed files with 300 additions and 25 deletions

View file

@ -197,6 +197,25 @@
</div>
</div>
</div>
<div class="item">
<div class="left">
<div class="title">
{{
isLastfmConnected
? `已连接到 Last.fm (${lastfm.name})`
: "连接 Last.fm "
}}</div
>
</div>
<div class="right">
<button @click="lastfmDisconnect()" v-if="isLastfmConnected"
>断开连接
</button>
<button @click="lastfmConnect()" v-else> 授权连接 </button>
</div>
</div>
<div class="item">
<div class="left">
<div class="title">
@ -282,6 +301,7 @@
<script>
import { mapState } from "vuex";
import { doLogout } from "@/utils/auth";
import { auth as lastfmAuth } from "@/api/lastfm";
import { changeAppearance, bytesToSize } from "@/utils/common";
import { countDBSize, clearDB } from "@/utils/db";
import pkg from "../../package.json";
@ -304,7 +324,7 @@ export default {
};
},
computed: {
...mapState(["player", "settings", "data"]),
...mapState(["player", "settings", "data", "lastfm"]),
isElectron() {
return process.env.IS_ELECTRON;
},
@ -470,6 +490,9 @@ export default {
});
},
},
isLastfmConnected() {
return this.lastfm.key !== undefined;
},
},
methods: {
getAllOutputDevices() {
@ -515,6 +538,20 @@ export default {
this.countDBSize("tracks");
});
},
lastfmConnect() {
lastfmAuth();
let lastfmChecker = setInterval(() => {
const session = localStorage.getItem("lastfm");
if (session) {
this.$store.commit("updateLastfm", JSON.parse(session));
clearInterval(lastfmChecker);
}
}, 1000);
},
lastfmDisconnect() {
localStorage.removeItem("lastfm");
this.$store.commit("updateLastfm", {});
},
},
created() {
this.countDBSize("tracks");