diff --git a/src/background/main.ts b/src/background/main.ts index 2a36065..52db4c1 100644 --- a/src/background/main.ts +++ b/src/background/main.ts @@ -1,4 +1,4 @@ -import { encodeTagName, getErrorMessage } from "~/utils"; +import { encodeTagName, getErrorMessage, getUrl } from "~/utils"; import { BrowserCommand, PostUploadCommandData, @@ -19,6 +19,13 @@ if (import.meta.hot) { import("./contentScriptHMR"); } +browser.notifications.onClicked.addListener((url) => { + if (url) { + browser.tabs.create({ url }); + browser.notifications.clear(url); + } +}); + async function uploadPost(data: PostUploadCommandData) { const info: PostUploadInfo = { state: "uploading", @@ -117,6 +124,16 @@ async function uploadPost(data: PostUploadCommandData) { await szuru.updatePool(existingPool.id, updateRequest); } } + + if (browser.notifications) { + const createdPostUrl = getUrl(data.selectedSite.domain, "post", createdPost.id.toString()); + browser.notifications.create(createdPostUrl, { + type: "basic", + iconUrl: browser.runtime.getURL("assets/icon-128.png"), + title: "SzuruChrome", + message: `Uploaded ${data.post.contentUrl}`, + }); + } } catch (ex: any) { console.error(ex); if (ex.name && ex.name == "PostAlreadyUploadedError") { diff --git a/src/manifest.ts b/src/manifest.ts index 38d11b7..61b8b72 100644 --- a/src/manifest.ts +++ b/src/manifest.ts @@ -31,7 +31,7 @@ export async function getManifest() { page: "./dist/background/index.html", // persistent: false, }, - permissions: ["storage", "activeTab", "webRequest", "webRequestBlocking", ""], + permissions: ["storage", "activeTab", "webRequest", "webRequestBlocking", "notifications", ""], content_scripts: [ { matches: ["http://*/*", "https://*/*"],