aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/spellchecker/index.js
blob: 454096e4e7d7d8718e82f4c3cb39af3fbb7e06f3 (plain) (blame)
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
import { autorun, reaction } from 'mobx';

import { DEFAULT_FEATURES_CONFIG } from '../../config';

const debug = require('debug')('Franz:feature:spellchecker');

export const config = {
  isPremiumFeature: DEFAULT_FEATURES_CONFIG.isSpellcheckerPremiumFeature,
};

export default function init(stores) {
  reaction(
    () => stores.features.features.isSpellcheckerPremiumFeature,
    (enabled, r) => {
      debug('Initializing `spellchecker` feature');

      // Dispose the reaction to run this only once
      r.dispose();

      const { isSpellcheckerPremiumFeature } = stores.features.features;

      config.isPremiumFeature = isSpellcheckerPremiumFeature !== undefined ? isSpellcheckerPremiumFeature : DEFAULT_FEATURES_CONFIG.isSpellcheckerPremiumFeature;

      autorun(() => {
        if (!stores.user.data.isPremium && config.isPremiumFeature) {
          debug('Override settings.spellcheckerEnabled flag to false');

          Object.assign(stores.settings.all.app, {
            enableSpellchecking: false,
          });
        }
      });
    },
  );
}