// The welcome page's address and the one question it exists to ask. // // Chrome offers no manifest field and no API to request a pin — only // `chrome.action.getUserSettings()` to read whether the icon is on the // toolbar, which needs no extra permission. So the page asks the user in // words, and polls the read to notice when they have done it. /** The bundled page, opened on first install and from the dev debug menu. */ export const WELCOME_PAGE = 'welcome.html' export function welcomeUrl(): string { return chrome.runtime.getURL(WELCOME_PAGE) } /** How often the open welcome page re-asks whether the icon is pinned. */ export const PIN_POLL_MS = 1_000 /** * `unknown` is a real answer, not an error case: the read is advisory, and a * page that cannot get one says nothing rather than telling somebody who has * already pinned the icon to pin it. */ export type PinState = 'pinned' | 'unpinned' | 'unknown' export async function pinState(): Promise { // Chrome 91+, so every browser above this extension's floor of 110 has it — // but a missing API here should cost the page nothing. if (typeof chrome.action?.getUserSettings !== 'function') return 'unknown' try { const settings = await chrome.action.getUserSettings() return settings.isOnToolbar ? 'pinned' : 'unpinned' } catch (err) { console.debug('[substandard] could not read the toolbar pin state', err) return 'unknown' } }