封装electron-store

const Store = require('electron-store') const { v4: uuidv4 } = require('uuid'); const path = require('path')
class DataStore extends Store {     constructor(settings){         super(settings)         this.tracks =  this.get('tracks') || []     }
    saveTracks(){         this.set('tracks', this.tracks)         return this     }
    getTracks(){         return this.get('tracks') || []     }
    addTracks(tracks){         const trackWithProps = tracks.map((track)=>{             return {                 id: uuidv4(),                 path:track,                 fileName: path.basename(track)             }         }).filter( track => {             const currentTracksPath = this.getTracks().map(track => track.path)             return currentTracksPath.indexOf(track.path) < 0         })
        this.tracks = [...this.tracks,...trackWithProps]         return this.saveTracks()     }
    deleteTrack(deletedId){         this.tracks = this.tracks.filter(item => item.id !== deletedId)         return  this.saveTracks()     }
}
module.exports = DataStore   ---------- const DataStore = require('./renderer/MusicDataStore'); const myStore = new DataStore({   'name': 'Music Data' })      mainWindow.send('getTracks',myStore.getTracks())
上一篇:企业上云如何享受阿里云最新优惠价格(企业服务器价格查询)


下一篇:js中event对象的offsetX、 clientX、pageX、screenX、 layerX、x之间的区别