Skip to content

Commit

Permalink
Save new skips to db
Browse files Browse the repository at this point in the history
  • Loading branch information
probablykasper committed Dec 30, 2020
1 parent 6dc5224 commit c2f4f72
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ const db = {
getTrack: function(id) {
return library.tracks[id]
},
addSkip: function(id) {
const track = db.getTrack(id)
if (!track.skipCount) track.skipCount = 0
if (!track.skips) track.skips = []
track.skipCount++
track.skips.push(new Date().getTime())
db.save()
},
getTrackPath: function(id, fileUrl) {
const trackPath = path.join(tracksPath, db.getTrack(id).file)
if (fileUrl) return pathToFileURL(trackPath)
Expand Down
3 changes: 3 additions & 0 deletions src/stores/player.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Gapless from 'gapless.js'
import { writable } from 'svelte/store'
let library = db.get()

export const currentTime = writable(0)
export const duration = writable(0)
Expand All @@ -21,6 +22,8 @@ export function previous() {
gPlayer.playPrevious()
}
export function next() {
const currentId = gPlayer.currentTrack.metadata.id
db.addSkip(currentId)
gPlayer.playNext()
}
export function playTrack(id) {
Expand Down

0 comments on commit c2f4f72

Please sign in to comment.