Skip to content

Commit

Permalink
Merge pull request #7 from taterboom/fix/show-new
Browse files Browse the repository at this point in the history
Fix/show new
  • Loading branch information
taterboom authored Sep 20, 2023
2 parents 503af3c + b052df8 commit 9f67c59
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/tricky-kids-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"promptsnippets": patch
---

fix NEW not show
13 changes: 8 additions & 5 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ async function init() {
}
})

let showNew = false
chrome.runtime.onInstalled.addListener(async (reason) => {
if (reason.reason === chrome.runtime.OnInstalledReason.UPDATE) {
if (!reason.previousVersion) return
Expand All @@ -121,14 +120,13 @@ async function init() {
const [major2, minor2] = reason.previousVersion.split(".")
if (major === major2 && minor === minor2) return
// big version change should show NEW
showNew = true
chrome.action.setBadgeBackgroundColor({ color: "#ff4d4f" })
chrome.action.setBadgeText({ text: " " })
const tabs = await chrome.tabs.query({ active: true })
if (tabs[0]?.id) {
chrome.tabs.sendMessage(tabs[0].id, {
type: "prompt-snippets/init-show-new",
payload: showNew,
payload: true,
})
}
} catch (err) {
Expand Down Expand Up @@ -165,10 +163,15 @@ async function init() {
syncDisabledUrls()
}
if (message.type === "prompt-snippets/get-show-new") {
sendResponse(showNew)
if (!sender.tab?.id) return
chrome.action.getBadgeText({ tabId: sender.tab.id }).then((badgeText) => {
const showNew = badgeText === " "
console.log("showNew", showNew)
sendResponse(showNew)
})
return true
}
if (message.type === "prompt-snippets/close-new") {
showNew = false
chrome.action.setBadgeText({ text: "" })
}
})
Expand Down

0 comments on commit 9f67c59

Please sign in to comment.