aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/spellchecker/index.js
blob: 8b3fb7e00f434e4360ca8969dc1431950a4bd14c (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
37
38
import { autorun, reaction } from 'mobx';

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

const DEFAULT_IS_PREMIUM_FEATURE = true;

export const config = {
  isPremiumFeature: DEFAULT_IS_PREMIUM_FEATURE,
};

export default function init(stores) {
  reaction(
    () => stores.features.features.isSpellcheckerPremiumFeature,
    (enabled, r) => {
      if (enabled) {
        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_IS_PREMIUM_FEATURE;

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

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