-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Giulia Ye
committed
May 31, 2024
1 parent
7ffdddc
commit 35e19b6
Showing
21 changed files
with
223 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +0,0 @@ | ||
import browser from "webextension-polyfill"; | ||
import OptionsSyncStorage from "../../lib/services/storage"; | ||
import TabsService from "../../lib/services/tabsService"; | ||
|
||
const storage = OptionsSyncStorage.getInstance(); | ||
const tabs = new TabsService(storage); | ||
|
||
browser.tabs.onUpdated.addListener(async function (tabId, changeInfo, tab) { | ||
if ( | ||
changeInfo.status == "complete" && | ||
(tab.title?.toLowerCase().includes("vitesicure") || | ||
tab.title?.toLowerCase().includes("bridge insurance services")) | ||
) { | ||
await tabs.addTab(tabId.toString()); | ||
} | ||
}); | ||
|
||
browser.tabs.onRemoved.addListener(async function (tabId, _removeInfo) { | ||
await tabs.removeTab(tabId.toString()); | ||
}); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import browser from "webextension-polyfill"; | ||
|
||
export const getCurrentTab = async () => { | ||
const [tab] = await browser.tabs.query({ active: true, currentWindow: true }); | ||
return tab; | ||
}; | ||
|
||
export const sendMessage = async ( | ||
message: string, | ||
content: any, | ||
tabId: number, | ||
) => { | ||
await browser.tabs.sendMessage(tabId, { message, content }); | ||
}; | ||
|
||
export const listenForMessage = ( | ||
message: string, | ||
callback: (content: any) => void, | ||
) => { | ||
browser.runtime.onMessage.addListener((listenerMessage) => { | ||
if (listenerMessage.message === message) { | ||
callback(listenerMessage.content); | ||
} | ||
}); | ||
}; |
22 changes: 22 additions & 0 deletions
22
src/lib/services/messagingService/messagingService.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import MessagingService from "./messagingService"; | ||
import * as browser from "../browser"; | ||
|
||
describe("MessagingService", () => { | ||
const browserSendMessage = vi.spyOn(browser, "sendMessage"); | ||
|
||
it("sendMessage should send message to current tab", async () => { | ||
MessagingService.send("messageTest", { | ||
myContent: "test", | ||
}); | ||
|
||
await vi.waitFor(() => { | ||
expect(browserSendMessage).toHaveBeenCalledWith( | ||
"messageTest", | ||
{ | ||
myContent: "test", | ||
}, | ||
1, | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { getCurrentTab, listenForMessage, sendMessage } from "../browser"; | ||
|
||
class MessagingService { | ||
public static async send(message: string, content: any = {}) { | ||
const tab = await getCurrentTab(); | ||
await sendMessage(message, content, tab.id); | ||
} | ||
|
||
public static async listen( | ||
message: string, | ||
callback: (content: any) => void, | ||
) { | ||
listenForMessage(message, callback); | ||
} | ||
} | ||
|
||
export default MessagingService; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.