rename: user -> storage; new option: storageName
This commit is contained in:
parent
7afe441da1
commit
a4bdc5345b
|
|
@ -14,7 +14,8 @@ export default (options) => {
|
|||
volume: 0.7,
|
||||
listFolded: false,
|
||||
listMaxHeight: options.listmaxheight,
|
||||
audio: options.music
|
||||
audio: options.music,
|
||||
storageName: 'aplayer-setting'
|
||||
};
|
||||
for (const defaultKey in defaultOption) {
|
||||
if (defaultOption.hasOwnProperty(defaultKey) && !options.hasOwnProperty(defaultKey)) {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import Icons from './icons';
|
|||
import handleOption from './options';
|
||||
import Template from './template';
|
||||
import Bar from './bar';
|
||||
import User from './user';
|
||||
import Storage from './storage';
|
||||
import Lrc from './lrc';
|
||||
import Controller from './controller';
|
||||
import Timer from './timer';
|
||||
|
|
@ -79,7 +79,7 @@ class APlayer {
|
|||
});
|
||||
}
|
||||
this.events = new Events();
|
||||
this.user = new User(this);
|
||||
this.storage = new Storage(this);
|
||||
this.bar = new Bar(this.template);
|
||||
this.controller = new Controller(this);
|
||||
this.timer = new Timer(this);
|
||||
|
|
@ -191,7 +191,7 @@ class APlayer {
|
|||
}
|
||||
});
|
||||
|
||||
this.volume(this.user.get('volume'), true);
|
||||
this.volume(this.storage.get('volume'), true);
|
||||
}
|
||||
|
||||
setAudio (audio) {
|
||||
|
|
@ -349,7 +349,7 @@ class APlayer {
|
|||
percentage = Math.min(percentage, 1);
|
||||
this.bar.set('volume', percentage, 'height');
|
||||
if (!nostorage) {
|
||||
this.user.set('volume', percentage);
|
||||
this.storage.set('volume', percentage);
|
||||
}
|
||||
|
||||
this.audio.volume = percentage;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
import utils from './utils';
|
||||
|
||||
class Storage {
|
||||
constructor (player) {
|
||||
this.storageName = player.options.storageName;
|
||||
|
||||
this.data = JSON.parse(utils.storage.get(this.storageName));
|
||||
if (!this.data) {
|
||||
this.data = {};
|
||||
}
|
||||
this.data.volume = this.data.volume || player.options.volume;
|
||||
}
|
||||
|
||||
get (key) {
|
||||
return this.data[key];
|
||||
}
|
||||
|
||||
set (key, value) {
|
||||
this.data[key] = value;
|
||||
utils.storage.set(this.storageName, JSON.stringify(this.data));
|
||||
}
|
||||
}
|
||||
|
||||
export default Storage;
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
import utils from './utils';
|
||||
|
||||
class User {
|
||||
constructor (player) {
|
||||
this.storageName = {
|
||||
volume: 'aplayer-volume',
|
||||
};
|
||||
this.default = {
|
||||
volume: player.options.volume || 0.7,
|
||||
};
|
||||
this.data = {};
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
init () {
|
||||
for (const item in this.storageName) {
|
||||
const name = this.storageName[item];
|
||||
this.data[item] = parseFloat(utils.storage.get(name) || this.default[item]);
|
||||
}
|
||||
}
|
||||
|
||||
get (key) {
|
||||
return this.data[key];
|
||||
}
|
||||
|
||||
set (key, value) {
|
||||
this.data[key] = value;
|
||||
utils.storage.set(this.storageName[key], value);
|
||||
}
|
||||
}
|
||||
|
||||
export default User;
|
||||
Loading…
Reference in New Issue