forked from WorldBrain/Memex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.ts
127 lines (107 loc) · 3.77 KB
/
background.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import 'babel-polyfill'
import 'core-js/es7/symbol'
import { browser } from 'webextension-polyfill-ts'
import initStorex from './search/memex-storex'
import getDb, { setStorexBackend } from './search/get-db'
import internalAnalytics from './analytics/internal'
import initSentry from './util/raven'
// Features that require manual instantiation to setup
import DirectLinkingBackground from './direct-linking/background'
import EventLogBackground from './analytics/internal/background'
import CustomListBackground from './custom-lists/background'
import NotificationBackground from './notifications/background'
import SearchBackground from './search/background'
import * as backup from './backup/background'
import * as backupStorage from './backup/background/storage'
import BackgroundScript from './background-script'
import alarms from './background-script/alarms'
import TagsBackground from './tags/background'
import ActivityLoggerBackground from './activity-logger/background'
import SocialBackground from './social-integration/background'
import BookmarksBackground from './bookmarks/background'
// Features that auto-setup
import './analytics/background'
import './imports/background'
import './omnibar'
import analytics from './analytics'
initSentry()
const storageManager = initStorex()
const notifications = new NotificationBackground({ storageManager })
notifications.setupRemoteFunctions()
export const directLinking = new DirectLinkingBackground({
storageManager,
getDb,
})
directLinking.setupRemoteFunctions()
directLinking.setupRequestInterceptor()
const activityLogger = new ActivityLoggerBackground({
storageManager,
notifsBackground: notifications,
})
activityLogger.setupRemoteFunctions()
activityLogger.setupWebExtAPIHandlers()
const search = new SearchBackground({
storageManager,
getDb,
tabMan: activityLogger.tabManager,
})
search.setupRemoteFunctions()
const eventLog = new EventLogBackground({ storageManager })
eventLog.setupRemoteFunctions()
export const customList = new CustomListBackground({
storageManager,
getDb,
tabMan: activityLogger.tabManager,
windows: browser.windows,
})
customList.setupRemoteFunctions()
export const tags = new TagsBackground({
storageManager,
getDb,
tabMan: activityLogger.tabManager,
windows: browser.windows,
})
tags.setupRemoteFunctions()
export const bookmarks = new BookmarksBackground({
storageManager,
})
bookmarks.setupRemoteFunctions()
const social = new SocialBackground({ storageManager })
social.setupRemoteFunctions()
const backupModule = new backup.BackupBackgroundModule({
storageManager,
lastBackupStorage: new backupStorage.LocalLastBackupStorage({
key: 'lastBackup',
}),
notifications,
})
backupModule.setBackendFromStorage()
backupModule.setupRemoteFunctions()
backupModule.startRecordingChangesIfNeeded()
let bgScript: BackgroundScript
storageManager.finishInitialization().then(() => {
setStorexBackend(storageManager.backend)
internalAnalytics.registerOperations(eventLog)
backupModule.storage.setupChangeTracking()
bgScript = new BackgroundScript({
storageManager,
notifsBackground: notifications,
loggerBackground: activityLogger,
})
bgScript.setupRemoteFunctions()
bgScript.setupWebExtAPIHandlers()
bgScript.setupAlarms(alarms)
})
// Attach interesting features onto global window scope for interested users
window['backup'] = backupModule
window['getDb'] = getDb
window['storageMan'] = storageManager
window['bgScript'] = bgScript
window['eventLog'] = eventLog
window['directLinking'] = directLinking
window['search'] = search
window['customList'] = customList
window['notifications'] = notifications
window['analytics'] = analytics
window['logger'] = activityLogger
window['tabMan'] = activityLogger.tabManager