Support website message notification display

This commit is contained in:
Tw93
2024-12-24 20:33:26 +08:00
parent 7a02d8fb71
commit c06182151e
6 changed files with 240 additions and 20 deletions

View File

@@ -187,7 +187,6 @@ document.addEventListener('DOMContentLoaded', () => {
};
const detectAnchorElementClick = e => {
const anchorElement = e.target.closest('a');
if (anchorElement && anchorElement.href) {
@@ -256,6 +255,38 @@ document.addEventListener('DOMContentLoaded', () => {
);
});
document.addEventListener('DOMContentLoaded', function () {
let permVal = 'granted';
window.Notification = function (title, options) {
const { invoke } = window.__TAURI__.core;
const body = options?.body || '';
let icon = options?.icon || '';
// If the icon is a relative path, convert to full path using URI
if (icon.startsWith('/')) {
icon = window.location.origin + icon;
}
invoke('send_notification', {
params: {
title,
body,
icon,
},
});
};
window.Notification.requestPermission = async () => 'granted';
Object.defineProperty(window.Notification, 'permission', {
enumerable: true,
get: () => permVal,
set: v => {
permVal = v;
},
});
});
function setDefaultZoom() {
const htmlZoom = window.localStorage.getItem('htmlZoom');
if (htmlZoom) {