import adapter from "./adapter"; window.adapters = []; function $(id) { return document.getElementById(id); } function main() { window.settings = JSON.parse(localStorage.getItem("settings"));; if (window.settings != null) { for (let s of window.settings.adapters) { switch (s.protocol) { case "nostr": let a = adapter.toNostrAdapter(adapter.createAdapter(), s); window.adapters.push(a); break; } } } else { console.log("no settings exist for this client"); window.settings = { adapters: [] }; } }; function showSettings() { // tab bar hidden const tabbar = $("tabbar"); tabbar.style.display = "none"; // tabcontent to show settings ui const tabcontent = $("tabcontent"); let html = "

this is our settings dialogue

"; html += ""; html += adapters.reduce((self, a) => { self += `
  • ${a.nickname}
  • ` return self; }, ""; html += ""; tabcontent.innerHTML = html; } function addAdapter() { const tabcontent = $("tabcontent"); // dropdown for protocol let html = ""; // depending on protocol, different fields // nostr: privkey, initial relays html += "
    "; html += " "; html += " "; html += " "; html += "
    "; // masto/AP: server, username, pw/apikey // save button, back button html += ""; html += ""; tabcontent.innerHTML = html; } function fillAdapterProtocolOptions() { const proto = $("settings_newadapter_protocolselect"); console.log(proto.options[proto.selectedIndex]); } function saveSettings() { if (window.settings) { localStorage.setItem("settings", JSON.stringify(window.settings)); } // tab bar hidden const tabbar = $("tabbar"); tabbar.style.display = "block"; // tabcontent to show settings ui const tabcontent = $("tabcontent"); tabcontent.innerHTML = ""; } function saveAdapter() { let self = {}; // get selected adapter protocol const proto = $("settings_newadapter_protocolselect"); console.log(proto.options[proto.selectedIndex]); // switch protocol switch (proto.options[proto.selectedIndex].value) { // nostr: save privkey // save relays case "nostr": const privkey = $("settings_newadapter_nostr_privkey").value; const relays = $("settings_newadapter_nostr_default_relays").value; const nickname = $("settings_newadapter_nickname").value; self = { nickname: nickname, protocol: "nostr", privkey: privkey, relays: relays.split(",").map(r=>r.trim()) }; break; // AP/masto: whatever case "ap": break; } window.settings.adapters.push(self); adapters.push(adapter.toNostrAdapter(adapter.createAdapter(), self)); localStorage.setItem("settings", JSON.stringify(window.settings)); showSettings(); } window.addAdapter = addAdapter; window.saveAdapter = saveAdapter; window.fillAdapterProtocolOptions = fillAdapterProtocolOptions; window.showSettings = showSettings; window.saveSettings = saveSettings; main();