Notifications are blocked. Allow them in your browser or device settings, then reopen Microchess.
'; return; }
el.innerHTML = `
On this device, for turns, challenges and rematch requests.
`;
}
function showNotice (title, content, kind)
{
if (!notice) return;
notice.dataset.kind = kind;
document.querySelector('#notification-dialog-content').innerHTML = `
${esc(title)}
${content}`;
if (!notice.open) notice.showModal();
}
async function intro ()
{
if (!notice || !state || document.hidden || modal?.open || notice.open || introRequest || busy) return;
const user = state.user.id;
if (pendingIntro === user) {
pendingIntro = null;
showNotice('Turn notifications', `
Do you want to be notified when it's your turn? Enable the Notification setting in the Account Settings panel at the top right of the page.
`, 'intro');
return;
}
if (state.notificationIntroSeen || introHandled.has(user)) return;
introRequest = true;
try {
// An atomic claim prevents the same account seeing this in two tabs/devices.
const result = await api({ action: 'claim_notification_intro' });
introHandled.add(user);
if (result.show) pendingIntro = user;
if (state.user.id === user) state.notificationIntroSeen = true;
} catch (_) { /* Try again on a later state refresh; game play remains available. */ }
finally { introRequest = false; }
if (pendingIntro === state?.user.id) intro();
}
async function notificationFailure (error, phase, disabling)
{
let advice;
if (phase === 'subscribe' && (error.name === 'AbortError' || /push service error/i.test(error.message || ''))) {
let brave = false;
try { brave = await navigator.brave?.isBrave() || false; } catch (_) {}
advice = `
The browser could not register with its push service. ${brave ? 'This may be due to Brave’s “Use Google services for push messaging” setting being turned off.' : 'This may be due to a disabled browser push service or a network connection blocking it.'}
${brave ? 'Open this page in Brave' : 'If you use Brave, open this page'}, turn on Use Google services for push messaging, fully restart Brave, then try enabling notifications again.
Allowing notifications for Microchess alone does not enable that browser service. If the setting is already on, try again on another network or check your VPN/firewall settings.
Notification permission was not granted. Allow notifications for this site in your browser or device settings, then try again.
';
} else if (phase === 'subscribe') {
advice = '
The browser could not set up notifications. This may be due to its push service or a connection problem. Restart your browser and try again. On iPhone or iPad, open Microchess from its home-screen icon.
';
} else {
advice = '
Microchess could not save your notification settings. This may be due to a connection problem or an expired sign-in session. Reload the page, sign in if asked, and try again.