-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
58 lines (48 loc) · 1.08 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
49
50
51
52
53
54
55
56
57
window.mainWindow = null;
chrome.runtime.onStartup.addListener(function()
{
console.log("onStartup");
openMainWindow("minimized");
});
chrome.browserAction.onClicked.addListener(function()
{
openMainWindow();
});
chrome.windows.onCreated.addListener(function(window)
{
console.debug("opening window ", window);
})
chrome.windows.onRemoved.addListener(function(win)
{
if (mainWindow && win == mainWindow.id)
{
mainWindow = null;
}
});
function closeMainWindow()
{
if (mainWindow)
{
chrome.windows.remove(mainWindow.id);
mainWindow = null;
}
}
function openMainWindow(state)
{
if (!mainWindow)
{
var data = {url: chrome.runtime.getURL("index.html"), type: "popup", focused: true};
if (state)
{
delete data.focused;
data.state = state;
}
chrome.windows.create(data, function (win)
{
mainWindow = win;
chrome.windows.update(mainWindow.id, {width: 900, height: 800});
});
} else {
chrome.windows.update(mainWindow.id, {focused: true});
}
}