Add option to send browser notifications

pull/72/head
Keo Cheung 2025-10-10 00:00:42 +08:00
parent b4cbd90a7d
commit 6204dca18f
No known key found for this signature in database
GPG Key ID: F612349817DD7EA2
5 changed files with 16 additions and 3 deletions

View File

@ -125,12 +125,12 @@ async function uploadPost(data: PostUploadCommandData) {
}
}
if (browser.notifications) {
if (data.sendNotifications && 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",
title: data.selectedSite.domain,
message: `Uploaded ${data.post.contentUrl}`,
});
}

View File

@ -148,6 +148,7 @@ export class PostUploadCommandData {
constructor(
public readonly post: ScrapedPostDetails,
public readonly selectedSite: SzuruSiteConfig,
public readonly sendNotifications: boolean,
) { }
}

View File

@ -150,6 +150,17 @@ wnd.szc_set_config_version = (v = 0) => (cfg.value.version = v);
</p>
</div>
<div class="col-12 md:col-6">
<label>
<input type="checkbox" v-model="cfg.sendUploadNotifications" />
Send browser notifications after uploading
</label>
<p class="hint">
This will send a browser notification after a successful upload. Clicking the notification will open
the uploaded post in a new tab.
</p>
</div>
<span class="col-12 status-quiet">{{ versionInfo }}</span>
</div>
</TabPanel>

View File

@ -171,7 +171,7 @@ async function upload() {
await ensurePostHasContentToken(szuru.value!, post, cfg);
}
const cmdData = new PostUploadCommandData(post, <SzuruSiteConfig>cloneDeep(selectedSite.value));
const cmdData = new PostUploadCommandData(post, <SzuruSiteConfig>cloneDeep(selectedSite.value), cfg.value.sendUploadNotifications);
const cmd = new BrowserCommand("upload_post", cmdData);
await browser.runtime.sendMessage(cmd);
} catch (ex: any) {

View File

@ -15,6 +15,7 @@ export const cfg = useStorageLocal(
version: 0,
addPageUrlToSource: true,
alwaysUploadAsContent: false,
sendUploadNotifications: true,
autoSearchSimilar: false,
loadTagCounts: true,
fetchPostInfo: true,