mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 06:56:18 -05:00
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:
parent
46ba804a1b
commit
db7603012e
4 changed files with 54 additions and 12 deletions
23
app/src/components/admin/browserDetect.js
Normal file
23
app/src/components/admin/browserDetect.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// Shared UA sniffing for the WROLPi browser extension UI.
|
||||
// The extension only ships for Chromium (Chrome/Brave/Edge/Opera) and Firefox;
|
||||
// Safari and other browsers should not be nudged to install it.
|
||||
|
||||
/**
|
||||
* @returns {'firefox' | 'chromium' | 'unknown'}
|
||||
*/
|
||||
export function detectBrowser() {
|
||||
if (typeof navigator === 'undefined') return 'unknown';
|
||||
const ua = navigator.userAgent || '';
|
||||
// Order matters: Edge / Brave / Opera all include 'Chrome' in their UA.
|
||||
if (ua.includes('Firefox')) return 'firefox';
|
||||
if (ua.includes('Edg/')) return 'chromium';
|
||||
if (ua.includes('OPR/') || ua.includes('Opera')) return 'chromium';
|
||||
if (ua.includes('Chrome')) return 'chromium';
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
/** True when the current browser can run the WROLPi extension. */
|
||||
export function isExtensionSupportedBrowser() {
|
||||
const browser = detectBrowser();
|
||||
return browser === 'firefox' || browser === 'chromium';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue