-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
34 lines (30 loc) · 1.05 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
console.log("Background script loaded");
chrome.runtime.onInstalled.addListener(() => {
chrome.storage.local.set({ projects: {} });
console.log("Project storage initialized.");
});
chrome.runtime.onInstalled.addListener(() => {
console.log("Extension installed");
// Initialize projects storage if not present
chrome.storage.local.get("projects", (data) => {
if (!data.projects) {
chrome.storage.local.set({ projects: {} }, () => {
console.log("Initialized empty projects storage.");
});
}
});
});
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "getUserInfo") {
chrome.identity.getProfileUserInfo({ accountStatus: "ANY" }, (userInfo) => {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError);
sendResponse({ error: chrome.runtime.lastError.message });
} else {
sendResponse({ userInfo: userInfo });
}
});
return true; // Will respond asynchronously
}
});
console.log("Background script setup complete");