Skip to content

Commit a4bdc53

Browse files
committed
rename: user -> storage; new option: storageName
1 parent 7afe441 commit a4bdc53

4 files changed

Lines changed: 30 additions & 38 deletions

File tree

src/js/options.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export default (options) => {
1414
volume: 0.7,
1515
listFolded: false,
1616
listMaxHeight: options.listmaxheight,
17-
audio: options.music
17+
audio: options.music,
18+
storageName: 'aplayer-setting'
1819
};
1920
for (const defaultKey in defaultOption) {
2021
if (defaultOption.hasOwnProperty(defaultKey) && !options.hasOwnProperty(defaultKey)) {

src/js/player.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Icons from './icons';
55
import handleOption from './options';
66
import Template from './template';
77
import Bar from './bar';
8-
import User from './user';
8+
import Storage from './storage';
99
import Lrc from './lrc';
1010
import Controller from './controller';
1111
import Timer from './timer';
@@ -79,7 +79,7 @@ class APlayer {
7979
});
8080
}
8181
this.events = new Events();
82-
this.user = new User(this);
82+
this.storage = new Storage(this);
8383
this.bar = new Bar(this.template);
8484
this.controller = new Controller(this);
8585
this.timer = new Timer(this);
@@ -191,7 +191,7 @@ class APlayer {
191191
}
192192
});
193193

194-
this.volume(this.user.get('volume'), true);
194+
this.volume(this.storage.get('volume'), true);
195195
}
196196

197197
setAudio (audio) {
@@ -349,7 +349,7 @@ class APlayer {
349349
percentage = Math.min(percentage, 1);
350350
this.bar.set('volume', percentage, 'height');
351351
if (!nostorage) {
352-
this.user.set('volume', percentage);
352+
this.storage.set('volume', percentage);
353353
}
354354

355355
this.audio.volume = percentage;

src/js/storage.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import utils from './utils';
2+
3+
class Storage {
4+
constructor (player) {
5+
this.storageName = player.options.storageName;
6+
7+
this.data = JSON.parse(utils.storage.get(this.storageName));
8+
if (!this.data) {
9+
this.data = {};
10+
}
11+
this.data.volume = this.data.volume || player.options.volume;
12+
}
13+
14+
get (key) {
15+
return this.data[key];
16+
}
17+
18+
set (key, value) {
19+
this.data[key] = value;
20+
utils.storage.set(this.storageName, JSON.stringify(this.data));
21+
}
22+
}
23+
24+
export default Storage;

src/js/user.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)