Send notifications after uploading
parent
e2bf28a29b
commit
5101c79c59
|
|
@ -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") {
|
||||
|
|
|
|||
|
|
@ -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://*/*"],
|
||||
|
|
|
|||
Loading…
Reference in New Issue