damus.io

damus.io website
git clone git://jb55.com/damus.io
Log | Files | Refs | README | LICENSE

commit ef1c2ca525088f07828b330f6db1d7f2379db1ab
parent 72346522eb7e793f21d65b41c464bc8207e780f0
Author: Thomas Mathews <thomas.c.mathews@gmail.com>
Date:   Fri, 18 Nov 2022 08:51:52 -0800

web: Added interval checking for nos2x

Diffstat:
Mweb/index.html | 5+----
Mweb/js/damus.js | 20++++++++++++++++++++
2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/web/index.html b/web/index.html @@ -18,11 +18,8 @@ <script> // This is our main entry. // https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event - console.log("window.nostr", window.nostr) addEventListener('DOMContentLoaded', (ev) => { - // TODO fix race condition where profile doesn't load fast enough. - setTimeout(damus_web_init, 500); - init_message_textareas(); + damus_web_init() }); </script> <nav id="gnav" class=""> diff --git a/web/js/damus.js b/web/js/damus.js @@ -121,6 +121,26 @@ function notice_chatroom(state, id) async function damus_web_init() { + init_message_textareas(); + + let tries = 0; + function init() { + // only wait for 500ms max + const max_wait = 500 + const interval = 20 + if (window.nostr || tries >= (max_wait/interval)) { + console.info("init after", tries); + damus_web_init_ready(); + return; + } + tries++; + setTimeout(init, interval); + } + init(); +} + +async function damus_web_init_ready() +{ const model = init_home_model() DAMUS = model model.pubkey = await get_pubkey()