-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
28 lines (24 loc) · 932 Bytes
/
background.js
File metadata and controls
28 lines (24 loc) · 932 Bytes
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
chrome.action.onClicked.addListener(() => {
if (chrome.sidePanel) {
chrome.sidePanel.setOptions({ path: 'index.html' });
} else {
console.error('Side panel API is not available.');
}
});
chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: true }).catch(error => console.error(error));
chrome.runtime.onInstalled.addListener(() => {
chrome.storage.local.set({ isAuthenticated: false, lastActiveTime: null });
});
chrome.runtime.onSuspend.addListener(() => {
chrome.storage.local.set({ lastActiveTime: Date.now() });
});
// Listener for messages from the web UI (e.g., button clicks)
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "OPEN_MAIN_UI") {
chrome.windows.getCurrent((window) => {
// Open the side panel for the current window
chrome.sidePanel.open({ windowId: window.id });
});
sendResponse({ success: true });
}
});