UNPKG

cody-music

Version:

mac osx spotify and itunes music player controller, spotify audio features, itunes and spotify genre, and playlist control

175 lines 5.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MusicStore = void 0; const util_1 = require("./util"); const musicUtil = new util_1.MusicUtil(); class MusicStore { constructor() { this._spotifyAccessToken = ""; this._spotifyRefreshToken = ""; this._apiHeaders = {}; this._connectServerAuth = ""; this._spotifyClientSecret = ""; this._spotifyClientId = ""; this._spotifyUserId = ""; this._itunesDesktopEnabled = true; this._itunesDesktopTrackingEnabled = true; this._spotifyDesktopEnabled = true; this._spotifyApiEnabled = true; this._itunesAccessGranted = true; this._debug = false; this._prev_volume_percent = 0; // } static getInstance() { if (!MusicStore.instance) { MusicStore.instance = new MusicStore(); } return MusicStore.instance; } setConfig(config) { this.spotifyAccessToken = config.spotifyAccessToken; this.spotifyClientId = config.spotifyClientId; this.spotifyClientSecret = config.spotifyClientSecret; this.spotifyRefreshToken = config.spotifyRefreshToken; this.itunesDesktopEnabled = config.enableItunesDesktop; this.itunesDesktopTrackingEnabled = config.enableItunesDesktopSongTracking; this.spotifyDesktopEnabled = config.enableSpotifyDesktop; this.spotifyApiEnabled = config.enableSpotifyApi; } setCredentials(creds) { Object.keys(creds).forEach((key) => { if (key === "clientId") { this.spotifyClientId = creds[key]; } else if (key === "clientSecret") { this.spotifyClientSecret = creds[key]; } else if (key === "refreshToken") { this.spotifyRefreshToken = creds[key]; } else if (key === "accessToken") { this.spotifyAccessToken = creds[key]; } else if (key === "debug") { this.debug = creds[key]; } }); } credentialByKey(key) { if (key === "spotifyClientId") { return this.spotifyClientId; } else if (key === "spotifyClientSecret") { return this.spotifyClientSecret; } else if (key === "spotifyRefreshToken") { return this.spotifyRefreshToken; } else if (key === "spotifyAccessToken") { return this.spotifyAccessToken; } else if (key === "debug") { return this.debug; } return null; } hasSpotifyAccessToken() { return this._spotifyAccessToken && this._spotifyAccessToken !== "" ? true : false; } get spotifyAccessToken() { return this._spotifyAccessToken; } set spotifyAccessToken(newAccessToken) { this._spotifyAccessToken = newAccessToken; } get prevVolumePercent() { return this._prev_volume_percent; } set prevVolumePercent(percent) { this._prev_volume_percent = percent; } get itunesAccessGranted() { return this._itunesAccessGranted; } set itunesAccessGranted(granted) { this._itunesAccessGranted = granted; } get spotifyClientSecret() { return this._spotifyClientSecret; } set spotifyClientSecret(newSpotifyClientSecret) { this._spotifyClientSecret = newSpotifyClientSecret; } get spotifyClientId() { return this._spotifyClientId; } set spotifyClientId(newSpotifyCliendId) { this._spotifyClientId = newSpotifyCliendId; } get connectServerAuth() { return this._connectServerAuth; } set connectServerAuth(newConnectServerAuth) { this._connectServerAuth = newConnectServerAuth; } get spotifyRefreshToken() { return this._spotifyRefreshToken; } set spotifyRefreshToken(newRefreshToken) { this._spotifyRefreshToken = newRefreshToken; } get apiHeaders() { return this._apiHeaders; } set apiHeaders(newApiHeaders) { this._apiHeaders = newApiHeaders; } get spotifyUserId() { return this._spotifyUserId; } set spotifyUserId(newSpotifyUserId) { this._spotifyUserId = newSpotifyUserId; } get itunesDesktopEnabled() { if (this._itunesDesktopEnabled && !musicUtil.isMac()) { this._itunesDesktopEnabled = false; } return this._itunesDesktopEnabled; } get itunesDesktopTrackingEnabled() { if (this._itunesDesktopTrackingEnabled && !musicUtil.isMac()) { this._itunesDesktopTrackingEnabled = false; } return this._itunesDesktopTrackingEnabled; } set itunesDesktopTrackingEnabled(newItunesDesktopTrackingEnabled) { this._itunesDesktopTrackingEnabled = newItunesDesktopTrackingEnabled; } set itunesDesktopEnabled(newitunesDesktopEnabled) { this._itunesDesktopEnabled = newitunesDesktopEnabled; } get spotifyDesktopEnabled() { return this._spotifyDesktopEnabled; } set spotifyDesktopEnabled(newspotifyDesktopEnabled) { this._spotifyDesktopEnabled = newspotifyDesktopEnabled; } get spotifyApiEnabled() { return this._spotifyApiEnabled; } set spotifyApiEnabled(newspotifyApiEnabled) { this._spotifyApiEnabled = newspotifyApiEnabled; } get debug() { return this._debug; } set debug(isDebug) { this._debug = isDebug; } } exports.MusicStore = MusicStore; //# sourceMappingURL=store.js.map