mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-05 06:09:57 -05:00
Creating browser extension to facilitate starting downloads. Chrome/Brave and Firefox supported.
The extension is hosted in a sibling repo and
is distributed off-store. Each WROLPi release ships the prebuilt artifacts
under wrolpi/static/extensions/ and serves them at /api/extensions/<file>:
- wrolpi-chrome.zip Load-Unpacked sideload for Chrome / Brave / Edge
- wrolpi-firefox.xpi Mozilla-signed (unlisted self-distribution),
one-click install in any Firefox
- versions.json Per-browser version metadata for the install page
Backend (modules/archive/api.py, wrolpi/root_api.py):
- POST /api/archive/upload accepts an optional repeated `tagNames`
multipart form field; the upload switch handler applies tags to the
new FileGroup via FileGroup.set_tags(). Unknown tag names are auto-
created inside a per-name SAVEPOINT so concurrent inserts on the same
novel name don't abort the transaction (Tag.name has unique=True).
- GET /api/extensions returns metadata (per-file availability + size +
versions.json contents) for the install page.
- GET /api/extensions/<filename> serves the binary, whitelisted by
filename. Firefox .xpi is served as application/x-xpinstall WITHOUT a
Content-Disposition: attachment header, so Firefox triggers its
add-on install handler instead of saving the file.
Frontend (app/src/):
- New /admin/extension page (linked from AdminRoute) detects the user's
browser via navigator.userAgent and renders an install card per
Firefox / Chromium / Other. Pulls metadata from /api/extensions to
show file size and version, and gracefully reports 'Not yet
available' when binaries are missing.
- Dashboard's Getters component supports a deep link from the
extension's 'Configure Download' button:
/?downloader=<archive|video|...>&download_url=<u1>&download_url=<u2>
On mount, the matching downloader form auto-opens with URLs pre-
filled. Query params are cleared on close so a refresh doesn't
re-open the modal.
- DownloadMenu and the per-downloader forms accept an `initialUrls`
seed via the existing `download` prop pattern, joined with newlines
for the `urls` textarea (and first URL for single-URL forms).
Behavior is fully backwards compatible: pre-existing API callers can
still POST to /api/archive/upload without `tagNames`, and the
DashboardPage modal continues to open via the existing button click
when no deep-link query params are present.
This commit is contained in:
parent
ae460af8d6
commit
a9a460c54c
21 changed files with 865 additions and 21 deletions
|
|
@ -1850,3 +1850,54 @@ export const useSearchChannels = (defaultTagNames) => {
|
|||
loading,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detect whether the WROLPi browser extension is installed AND has this
|
||||
* destination configured. The extension's background worker dynamically
|
||||
* registers a content script on each configured destination origin; that
|
||||
* script appends `<meta name="wrolpi-extension" content="<version>">` to the
|
||||
* head. We read for that marker.
|
||||
*
|
||||
* Three-state result so callers can avoid flashing UI during the race
|
||||
* between React's first render and the content script's document_idle:
|
||||
* null — checking; render nothing
|
||||
* false — confirmed absent (after recheck); show "install me" UI
|
||||
* <string> — installed; the version string the extension reported
|
||||
*
|
||||
* Observes <head> for a late-arriving marker (e.g., the user installs the
|
||||
* extension while the page is open, or grants the destination permission
|
||||
* after page load) so the banner clears without requiring a manual reload.
|
||||
*/
|
||||
export function useExtensionInstalled() {
|
||||
const detect = () => {
|
||||
const meta = document.querySelector('meta[name="wrolpi-extension"]');
|
||||
if (!meta) return null;
|
||||
return meta.getAttribute('content') || true;
|
||||
};
|
||||
const [state, setState] = useState(detect);
|
||||
|
||||
useEffect(() => {
|
||||
// Observe <head> for the marker meta tag appearing at any time.
|
||||
// Once we see it we clean up — there's no need to keep watching.
|
||||
const observer = new MutationObserver(() => {
|
||||
const result = detect();
|
||||
if (result) setState(result);
|
||||
});
|
||||
if (document.head) {
|
||||
observer.observe(document.head, {childList: true, subtree: true});
|
||||
}
|
||||
return () => observer.disconnect();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (state !== null) return;
|
||||
// Recheck once after the document_idle window closes; only then
|
||||
// commit to "false". Avoids flashing the banner on every dashboard
|
||||
// load while we're just waiting for the content script to run.
|
||||
const t = setTimeout(() => setState(detect() ?? false), 500);
|
||||
return () => clearTimeout(t);
|
||||
}, [state]);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue