Skip to content

Commit 33fbaa8

Browse files
committed
fix: broken communication with background
1 parent 1957472 commit 33fbaa8

File tree

5 files changed

+73
-68
lines changed

5 files changed

+73
-68
lines changed

options/index.tsx

Whitespace-only changes.

src/background/index.ts

+69-65
Original file line numberDiff line numberDiff line change
@@ -18,81 +18,85 @@ import {
1818
// API calls that can be made from content scripts transit trough the background script
1919
// This is done to prevent CORS errors
2020
// Functions here aren't decoupled from the background script because of odd behavior with sendResponse
21-
chrome.runtime.onMessageExternal.addListener(
22-
(message, sender, sendResponse) => {
23-
switch (message.type) {
24-
case "chatgpt-to-notion_search":
25-
searchNotion(message.body.query)
26-
.then((res) => {
27-
sendResponse(res)
28-
})
29-
.catch((err) => {
30-
console.error(err)
31-
sendResponse({ err })
32-
})
33-
break
34-
case "chatgpt-to-notion_checkSaveConflict":
35-
checkSaveConflict(message.body)
36-
.then((res) => {
37-
sendResponse(res)
38-
})
39-
.catch((err) => {
40-
console.error(err)
41-
sendResponse({ err })
42-
})
43-
break
44-
case "chatgpt-to-notion_saveChat":
45-
saveChat(message.body)
46-
.then((res) => {
47-
sendResponse(res)
48-
})
49-
.catch((err) => {
50-
console.error(err)
51-
sendResponse({ err })
52-
})
53-
break
54-
case "chatgpt-to-notion_autoSave":
55-
const storage = new Storage()
56-
saveChat(message.body)
57-
.then((res) => {
58-
sendResponse(res)
59-
storage.set("autosaveStatus", "saved" as AutosaveStatus)
60-
})
61-
.catch((err) => {
62-
storage.set("autosaveStatus", "error" as AutosaveStatus)
63-
console.error(err)
64-
sendResponse({ err })
65-
})
66-
break
67-
case "chatgpt-to-notion_generateToken":
68-
// using two means of checking if user is logged in just to be sure
69-
const session = new Storage({
70-
area: "session",
71-
secretKeyList: ["token"]
21+
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
22+
switch (message.type) {
23+
case "chatgpt-to-notion_search":
24+
searchNotion(message.body.query)
25+
.then((res) => {
26+
sendResponse(res)
7227
})
73-
session.get("token").then((token) => {
74-
if (token) return
75-
generateToken(message.body.code).then((res) => {
76-
sendResponse(res)
77-
})
28+
.catch((err) => {
29+
console.error(err)
30+
sendResponse({ err })
7831
})
79-
break
80-
case "chatgpt-to-notion_getDB":
81-
getDatabase(message.body.id)
32+
break
33+
case "chatgpt-to-notion_checkSaveConflict":
34+
checkSaveConflict(message.body)
35+
.then((res) => {
36+
sendResponse(res)
37+
})
38+
.catch((err) => {
39+
console.error(err)
40+
sendResponse({ err })
41+
})
42+
break
43+
case "chatgpt-to-notion_saveChat":
44+
saveChat(message.body)
45+
.then((res) => {
46+
sendResponse(res)
47+
})
48+
.catch((err) => {
49+
console.error(err)
50+
sendResponse({ err })
51+
})
52+
break
53+
case "chatgpt-to-notion_autoSave":
54+
const storage = new Storage()
55+
saveChat(message.body)
56+
.then((res) => {
57+
sendResponse(res)
58+
storage.set("autosaveStatus", "saved" as AutosaveStatus)
59+
})
60+
.catch((err) => {
61+
storage.set("autosaveStatus", "error" as AutosaveStatus)
62+
console.error(err)
63+
sendResponse({ err })
64+
})
65+
break
66+
case "chatgpt-to-notion_generateToken":
67+
// using two means of checking if user is logged in just to be sure
68+
const session = new Storage({
69+
area: "session",
70+
secretKeyList: ["token"]
71+
})
72+
session.get("token").then((token) => {
73+
if (token) return
74+
generateToken(message.body.code)
8275
.then((res) => {
76+
console.log(res)
8377
sendResponse(res)
8478
})
8579
.catch((err) => {
8680
console.error(err)
8781
sendResponse({ err })
8882
})
89-
break
90-
default:
91-
return true
92-
}
93-
return true
83+
})
84+
break
85+
case "chatgpt-to-notion_getDB":
86+
getDatabase(message.body.id)
87+
.then((res) => {
88+
sendResponse(res)
89+
})
90+
.catch((err) => {
91+
console.error(err)
92+
sendResponse({ err })
93+
})
94+
break
95+
default:
96+
return true
9497
}
95-
)
98+
return true
99+
})
96100

97101
chrome.runtime.onInstalled.addListener(() => {
98102
refreshContentScripts()

src/contents/fetchFullPage.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ export const config: PlasmoContentScript = {
55
}
66

77
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
8-
if (message.type === "fetchFullChat") sendResponse(fetchFullChat())
8+
if (message.type === "chatgpt-to-notion_fetchFullChat")
9+
sendResponse(fetchFullChat())
910
})
1011

1112
const fetchFullChat = () => {

src/popup/ErrorPopup.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function ErrorPopup() {
4747
if (!config) return
4848
setLoading(true)
4949
await chrome.runtime.sendMessage({
50-
type: "triggerAutosave",
50+
type: "chatgpt-to-notion_triggerAutosave",
5151
body: {
5252
chatID,
5353
config

src/popup/IndexPopup.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function IndexPopup() {
134134
answers: string[]
135135
url: string
136136
} = await chrome.tabs.sendMessage(currentTab.id, {
137-
type: "fetchFullChat"
137+
type: "chatgpt-to-notion_fetchFullChat"
138138
})
139139
const req = {
140140
...chat,

0 commit comments

Comments
 (0)