Skip to content

Commit

Permalink
Merge pull request #4 from TickLabVN/feature/improve-type-name-of-bro…
Browse files Browse the repository at this point in the history
…wser-message

Refactor: Rename Browser Message Type from NEW_VIDEO to TAB_UPDATE fo…
  • Loading branch information
quannhg authored Jan 13, 2024
2 parents 9df521e + 5a18a18 commit e4ca9f2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ const APP_NAME = "com.ticklab.tpulse";
const port = browser.runtime.connectNative(APP_NAME);

function isUserTab(tab: BrowserTab) {
return tab.url && (
tab.url.startsWith("http://")
|| tab.url.startsWith("https://")
return (
tab.url && (tab.url.startsWith("http://") || tab.url.startsWith("https://"))
);
}

Expand Down Expand Up @@ -38,7 +37,6 @@ function watch() {
getTabDetails(tabId)
.then((tab) => {
if (!isUserTab(tab)) return;
console.log("tab", tab);
const message: BinaryMessage = { type: "BrowserTab", ...tab };
port.postMessage(message);
})
Expand Down Expand Up @@ -70,7 +68,7 @@ function watch() {
tab.url.startsWith("http")
) {
const newMessage: BrowserMessage = {
type: "ticklabvn.tpulse.NEW_VIDEO",
type: "ticklabvn.tpulse.TAB_UPDATE",
};
browser.tabs.sendMessage(tabId, newMessage);
}
Expand Down
2 changes: 1 addition & 1 deletion src/contentScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const setupPlayerEventListeners = () => {
browser.runtime.onMessage.addListener((obj) => {
const { type } = obj;

if (type === "ticklabvn.tpulse.NEW_VIDEO") {
if (type === "ticklabvn.tpulse.TAB_UPDATE") {
setupPlayerEventListeners();
}
});
2 changes: 1 addition & 1 deletion src/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type MessageTypePrefix = "ticklabvn.tpulse.";
type VideoStatusPayload = Record<string, string | number | boolean>;

type BrowserMessage = {
type: `${MessageTypePrefix}${"NEW_VIDEO" | "UPDATE_VIDEO_STATUS"}`;
type: `${MessageTypePrefix}${"TAB_UPDATE" | "UPDATE_VIDEO_STATUS"}`;
payload?: VideoStatusPayload;
};

Expand Down

0 comments on commit e4ca9f2

Please sign in to comment.