blob: 9124188025cc80d83cecfbc2d471ed3230cfc297 (
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
|
import { injectable } from 'tsyringe';
import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase';
import SettingUseCase from '../usecases/SettingUseCase';
import * as messages from '../../shared/messages';
@injectable()
export default class SettingController {
constructor(
private addonEnabledUseCase: AddonEnabledUseCase,
private settingUseCase: SettingUseCase,
) {
}
async initSettings(): Promise<void> {
try {
const current = await this.settingUseCase.reload();
const url = new URL(window.location.href);
const disabled = current.blacklist.includesEntireBlacklist(url);
if (disabled) {
this.addonEnabledUseCase.disable();
} else {
this.addonEnabledUseCase.enable();
}
} catch (e) {
// Sometime sendMessage fails when background script is not ready.
console.warn(e);
setTimeout(() => this.initSettings(), 500);
}
}
async reloadSettings(_message: messages.Message): Promise<void> {
await this.settingUseCase.reload();
}
}
|