Add Options page for aria2 settings with connection test; wire into manifest
This commit is contained in:
parent
8eeb1d3b20
commit
a7966ebebe
5 changed files with 117 additions and 1 deletions
52
src/options/index.js
Normal file
52
src/options/index.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import { getVersion } from "../lib/aria2.js";
|
||||
|
||||
const els = {
|
||||
endpoint: document.getElementById('rpc-endpoint'),
|
||||
secret: document.getElementById('rpc-secret'),
|
||||
btnSave: document.getElementById('btn-save'),
|
||||
btnReset: document.getElementById('btn-reset'),
|
||||
btnTest: document.getElementById('btn-test'),
|
||||
status: document.getElementById('status'),
|
||||
};
|
||||
|
||||
async function restore() {
|
||||
const { aria2 } = await browser.storage.local.get('aria2');
|
||||
els.endpoint.value = aria2?.endpoint || 'http://localhost:6800/jsonrpc';
|
||||
els.secret.value = aria2?.secret || '';
|
||||
}
|
||||
|
||||
async function save() {
|
||||
const endpoint = els.endpoint.value.trim();
|
||||
const secret = els.secret.value.trim();
|
||||
await browser.storage.local.set({ aria2: { endpoint, secret } });
|
||||
els.status.textContent = 'Saved.';
|
||||
}
|
||||
|
||||
async function reset() {
|
||||
await browser.storage.local.remove('aria2');
|
||||
await restore();
|
||||
els.status.textContent = 'Reset to defaults.';
|
||||
}
|
||||
|
||||
async function testConnection() {
|
||||
els.status.textContent = 'Testing…';
|
||||
try {
|
||||
const res = await getVersion({ endpoint: els.endpoint.value.trim(), secret: els.secret.value.trim() });
|
||||
const version = res?.result?.version || JSON.stringify(res?.result || res);
|
||||
els.status.textContent = `OK: aria2 version ${version}`;
|
||||
} catch (e) {
|
||||
els.status.textContent = `Error: ${e?.message || e}`;
|
||||
}
|
||||
}
|
||||
|
||||
function wire() {
|
||||
els.btnSave.addEventListener('click', save);
|
||||
els.btnReset.addEventListener('click', reset);
|
||||
els.btnTest.addEventListener('click', testConnection);
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
wire();
|
||||
await restore();
|
||||
});
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue