app: only show extension install banner on Chromium/Firefox

The dashboard nudge is useless on Safari and other browsers that cannot
run the WROLPi extension. Share detectBrowser and gate the banner with
isExtensionSupportedBrowser.
This commit is contained in:
Roland 2026-07-18 13:47:43 -06:00 • committed by lrnselfreliance
parent 46ba804a1b
commit db7603012e
4 changed files with 54 additions and 12 deletions

View file

@ -2,6 +2,14 @@ import React from 'react';
import {render, screen, waitFor} from '../../test-utils';
import {ExtensionInstallSuggestion} from './ExtensionInstallSuggestion';
const CHROME_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36';
const FIREFOX_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:128.0) Gecko/20100101 Firefox/128.0';
const SAFARI_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15';
const setUserAgent = (ua) => {
Object.defineProperty(window.navigator, 'userAgent', {value: ua, configurable: true});
};
const setMeta = (version) => {
const existing = document.querySelector('meta[name="wrolpi-extension"]');
if (existing) existing.remove();
@ -15,6 +23,7 @@ const setMeta = (version) => {
describe('ExtensionInstallSuggestion', () => {
beforeEach(() => {
setMeta(undefined);
setUserAgent(CHROME_UA);
window.localStorage.removeItem('wrolpi-extension-banner-dismissed');
});
@ -39,6 +48,22 @@ describe('ExtensionInstallSuggestion', () => {
expect(screen.getByText(/Open install page/i)).toBeInTheDocument();
});
it('renders the install message on Firefox when the marker is absent', async () => {
setUserAgent(FIREFOX_UA);
render(<ExtensionInstallSuggestion/>);
await waitFor(
() => expect(screen.getByText(/Install the WROLPi browser extension/i)).toBeInTheDocument(),
{timeout: 1500},
);
});
it('renders nothing on Safari even when the marker is absent', async () => {
setUserAgent(SAFARI_UA);
render(<ExtensionInstallSuggestion/>);
await new Promise(r => setTimeout(r, 600));
expect(screen.queryByText(/Install the WROLPi browser extension/i)).toBeNull();
});
it('renders nothing when the user has dismissed the banner', async () => {
window.localStorage.setItem('wrolpi-extension-banner-dismissed', 'true');
render(<ExtensionInstallSuggestion/>);