-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathextensions.ts
60 lines (52 loc) · 1.56 KB
/
extensions.ts
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
import { management } from 'webextension-polyfill';
import { isRecommended } from '@/composables/useRecommendations/defaultRecommendations';
import useRecommendations from '@/composables/useRecommendations/useRecommendations';
const { updateRecommendation } = useRecommendations();
type ExtensionInfo = browser.management.ExtensionInfo;
export const addExtensionsListeners = () => {
management.onInstalled.addListener(onInstall);
management.onUninstalled.addListener(onUninstall);
management.onEnabled.addListener(onEnable);
management.onDisabled.addListener(onDisable);
};
// Listeners
const onInstall = (extensionInfo: ExtensionInfo) => {
if (isRecommended(extensionInfo.id)) {
updateRecommendation(extensionInfo.id, {
activated: true,
ctaLabel: undefined,
enabled: true,
ignored: false,
installed: true,
});
}
};
const onUninstall = (extensionInfo: ExtensionInfo) => {
if (isRecommended(extensionInfo.id)) {
updateRecommendation(extensionInfo.id, {
activated: false,
ctaLabel: 'install',
enabled: false,
installed: false,
});
}
};
const onEnable = (extensionInfo: ExtensionInfo) => {
if (isRecommended(extensionInfo.id)) {
updateRecommendation(extensionInfo.id, {
activated: true,
ctaLabel: undefined,
enabled: true,
ignored: false,
});
}
};
const onDisable = (extensionInfo: ExtensionInfo) => {
if (isRecommended(extensionInfo.id)) {
updateRecommendation(extensionInfo.id, {
activated: false,
ctaLabel: 'enable',
enabled: false,
});
}
};