This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
forked from tabwrangler/tabwrangler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
48 lines (38 loc) · 1.46 KB
/
background.js
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
/**
* @file: Initializes Tab Wrangler on startup.
*/
function startup() {
chrome.runtime.onInstalled.addListener(function(details) {
if (details.reason == 'install') {
TW.Updater.firstInstall();
} else if (details.reason == 'update') {
TW.Updater.runUpdates(details.previousVersion, chrome.app.getDetails().version);
}
});
TW.settings.init();
TW.TabManager.closedTabs.init();
// Move this to a function somehwere so we can restart the process.
chrome.tabs.query({ windowType: 'normal', pinned: false }, TW.TabManager.initTabs);
chrome.tabs.onCreated.addListener(TW.TabManager.registerNewTab);
// Handles pinning and unpinning a tab
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (_.has(changeInfo, 'pinned')) {
if (changeInfo.pinned) {
clearTimeout(TW.TabManager.openTabs[tabId].scheduledClose);
TW.TabManager.tabPinned(tabId);
} else {
TW.TabManager.registerNewTab(tab);
}
}
});
chrome.tabs.onRemoved.addListener(TW.TabManager.removeTab);
chrome.tabs.onActivated.addListener(function(tabInfo) {
TW.contextMenuHandler.updateContextMenus(tabInfo.tabId);
TW.TabManager.updateLastAccessed(tabInfo.tabId)
});
chrome.tabs.onReplaced.addListener(TW.TabManager.replaceTab);
chrome.storage.onChanged.addListener(TW.settings.copySyncChanges);
// Create the "lock tab" context menu:
TW.contextMenuHandler.createContextMenus();
}
window.onload = startup;