Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/apps/system/js/storage.js
blob: ff7b10e2d98440fa91de0a40b86e2ed5c55513aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var Storage = {

  automounterDisable: 0,
  automounterEnable: 1,
  automounterDisableWhenUnplugged: 2,

  umsEnabled: 'ums.enabled',
  umsMode: 'ums.mode',

  init: function storageInit() {
    this.setMode(this.automounterDisable, 'init');
    window.addEventListener('lock', this);
    window.addEventListener('unlock', this);

    SettingsListener.observe(this.umsEnabled, false, function umsChanged(val) {
      if (LockScreen.locked) {
        // covers startup
        Storage.setMode(Storage.automounterDisable, 'screen locked');
      } else {
        Storage.setMode(Storage.modeFromBool(val), 'change in ums.enabled');
      }
    });
  },

  modeFromBool: function storageModeFromBool(val) {
     return val ? this.automounterEnable : this.automounterDisable;
  },

  setMode: function storageSetMode(val, reason) {
    if (!window.navigator.mozSettings)
      return;

    //console.info('Setting', this.umsMode, 'to', val, 'due to', reason);
    var param = {};
    param[this.umsMode] = val;
    SettingsListener.getSettingsLock().set(param);
  },

  handleEvent: function storageHandleEvent(e) {
    switch (e.type) {
      case 'lock':
        this.setMode(this.automounterDisableWhenUnplugged, 'screen locked');
        break;
      case 'unlock':
        if (!window.navigator.mozSettings)
          return;

        var req = SettingsListener.getSettingsLock().get(this.umsEnabled);
        req.onsuccess = function umsEnabledFetched() {
          var mode = Storage.modeFromBool(req.result[Storage.umsEnabled]);
          Storage.setMode(mode, 'screen unlocked');
        };
        break;
      default:
        return;
    }
  }
};

Storage.init();