Send notifications after uploading

pull/72/head
Keo Cheung 2025-10-09 23:02:31 +08:00
parent 1a6fe13512
commit b4cbd90a7d
No known key found for this signature in database
GPG Key ID: F612349817DD7EA2
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 {
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") {

View File

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