Send notifications after uploading

pull/57/merge
Keo Cheung 2025-10-09 23:02:31 +08:00 committed by Neo
parent e2bf28a29b
commit 5101c79c59
2 changed files with 19 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import { encodeTagName, getErrorMessage } from "~/utils"; import { encodeTagName, getErrorMessage, getUrl } from "~/utils";
import { import {
BrowserCommand, BrowserCommand,
PostUploadCommandData, PostUploadCommandData,
@ -19,6 +19,13 @@ if (import.meta.hot) {
import("./contentScriptHMR"); import("./contentScriptHMR");
} }
browser.notifications.onClicked.addListener((url) => {
if (url) {
browser.tabs.create({ url });
browser.notifications.clear(url);
}
});
async function uploadPost(data: PostUploadCommandData) { async function uploadPost(data: PostUploadCommandData) {
const info: PostUploadInfo = { const info: PostUploadInfo = {
state: "uploading", state: "uploading",
@ -117,6 +124,16 @@ async function uploadPost(data: PostUploadCommandData) {
await szuru.updatePool(existingPool.id, updateRequest); 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) { } catch (ex: any) {
console.error(ex); console.error(ex);
if (ex.name && ex.name == "PostAlreadyUploadedError") { if (ex.name && ex.name == "PostAlreadyUploadedError") {

View File

@ -31,7 +31,7 @@ export async function getManifest() {
page: "./dist/background/index.html", page: "./dist/background/index.html",
// persistent: false, // persistent: false,
}, },
permissions: ["storage", "activeTab", "webRequest", "webRequestBlocking", "<all_urls>"], permissions: ["storage", "activeTab", "webRequest", "webRequestBlocking", "notifications", "<all_urls>"],
content_scripts: [ content_scripts: [
{ {
matches: ["http://*/*", "https://*/*"], matches: ["http://*/*", "https://*/*"],