From 49a473ad8904d25aeb13b35551ebc6ab5ebff3c7 Mon Sep 17 00:00:00 2001 From: manatlan Date: Tue, 12 Sep 2023 08:15:15 +0200 Subject: [PATCH 1/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 976e0fb..9fa5dc1 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ So developping a htag app which work the same on desktop and on the web, should * multiple ways to handle sessions (file, mem, etc ...) * compatible with **uvloop** !!! * compatible with multiple gunicorn/uvicorn/webworkers !!! - * compatible with **tag.update()** + * compatible with [tag.update()](https://manatlan.github.io/htag/tag_update/) * works on gnu/linux, ios or windows ! * real starlette session available (in tag.state, and starlette request.session) * compatible with oauth2 authent ( [authlib](https://pypi.org/project/Authlib/) ) From 4b758bece8caa0fe90da52e8f015adbc6b9e08df Mon Sep 17 00:00:00 2001 From: manatlan Date: Thu, 14 Sep 2023 11:44:45 +0200 Subject: [PATCH 2/7] feat: ws try to reconnect on disconnection --- htagweb/appserver.py | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/htagweb/appserver.py b/htagweb/appserver.py index 0770cc4..7af222d 100644 --- a/htagweb/appserver.py +++ b/htagweb/appserver.py @@ -262,17 +262,36 @@ async def serve(self, request, obj ) -> HTMLResponse: jsbootstrap=""" %(jsparano)s // instanciate the WEBSOCKET - var _WS_ = new WebSocket("%(protocol)s://"+location.host+"/_/%(fqn)s"+location.search); - _WS_.onmessage = async function(e) { - // when connected -> the full HTML page is returned, installed & start'ed !!! - - let html = await _read_(e.data); - html = html.replace(" the full HTML page is returned, installed & start'ed !!! + + let html = await _read_(e.data); + html = html.replace(" Date: Thu, 14 Sep 2023 18:43:50 +0200 Subject: [PATCH 3/7] feat: transmit fullerror on mode debug (hrenderer) --- htagweb/appserver.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htagweb/appserver.py b/htagweb/appserver.py index 7af222d..c001f0e 100644 --- a/htagweb/appserver.py +++ b/htagweb/appserver.py @@ -154,14 +154,14 @@ async def send_wrapper(message: Message) -> None: await self.app(scope, receive, send_wrapper) -def fqn2hr(fqn:str,js:str,init,session): # fqn is a "full qualified name", full ! +def fqn2hr(fqn:str,js:str,init,session,fullerror=False): # fqn is a "full qualified name", full ! if ":" not in fqn: # replace last "." by ":" fqn="".join( reversed("".join(reversed(fqn)).replace(".",":",1))) klass=getClass(fqn) - return HRenderer( klass, js, init=init, session = session) + return HRenderer( klass, js, init=init, session = session, fullerror=fullerror) class HRSocket(WebSocketEndpoint): encoding = "text" @@ -197,7 +197,7 @@ async def on_connect(self, websocket): """ try: - hr=fqn2hr(fqn,js,commons.url2ak(str(websocket.url)),websocket.session) + hr=fqn2hr(fqn,js,commons.url2ak(str(websocket.url)),websocket.session,fullerror=websocket.app.debug) except Exception as e: await self._sendback( websocket, str(e) ) await websocket.close() @@ -296,7 +296,7 @@ async def serve(self, request, obj ) -> HTMLResponse: # here return a first rendering (only for SEO) # the hrenderer is DESTROYED just after - hr=fqn2hr(fqn,jsbootstrap,commons.url2ak(str(request.url)),request.session) + hr=fqn2hr(fqn,jsbootstrap,commons.url2ak(str(request.url)),request.session, fullerror=self.debug) return HTMLResponse( str(hr) ) From 3388316175c7cf2df03349d5fbbd90c905a59e69 Mon Sep 17 00:00:00 2001 From: manatlan Date: Thu, 14 Sep 2023 18:51:37 +0200 Subject: [PATCH 4/7] feat: toggle "body.htagoff" class when disconnected --- htagweb/appserver.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htagweb/appserver.py b/htagweb/appserver.py index c001f0e..9ef87bc 100644 --- a/htagweb/appserver.py +++ b/htagweb/appserver.py @@ -269,6 +269,7 @@ async def serve(self, request, obj ) -> HTMLResponse: _WS_= new WebSocket("%(protocol)s://"+location.host+"/_/%(fqn)s"+location.search); _WS_.onopen=function(evt) { console.log("** WS connected") + document.body.classList.remove("htagoff"); retryms=500; _WS_.onmessage = async function(e) { @@ -285,6 +286,7 @@ async def serve(self, request, obj ) -> HTMLResponse: _WS_.onclose = function(evt) { console.log("** WS disconnected, retry in (ms):",retryms) + document.body.classList.add("htagoff"); setTimeout( function() { connect(); retryms=retryms*2; From 7c30e4e472d9da5cf69589e75fd53680faf4da82 Mon Sep 17 00:00:00 2001 From: manatlan Date: Fri, 15 Sep 2023 07:51:24 +0200 Subject: [PATCH 5/7] feat: remove the autoreconnect on ws loss --- htagweb/appserver.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/htagweb/appserver.py b/htagweb/appserver.py index 9ef87bc..4a432bb 100644 --- a/htagweb/appserver.py +++ b/htagweb/appserver.py @@ -285,12 +285,14 @@ async def serve(self, request, obj ) -> HTMLResponse: } _WS_.onclose = function(evt) { - console.log("** WS disconnected, retry in (ms):",retryms) + console.log("** WS disconnected"); + //console.log("** WS disconnected, retry in (ms):",retryms); document.body.classList.add("htagoff"); - setTimeout( function() { - connect(); - retryms=retryms*2; - }, retryms); + + //setTimeout( function() { + // connect(); + // retryms=retryms*2; + //}, retryms); }; } connect(); From 74fcf9245f6f41f27a82dc66f049d6c02ed93c2f Mon Sep 17 00:00:00 2001 From: manatlan Date: Fri, 15 Sep 2023 08:19:26 +0200 Subject: [PATCH 6/7] feat: class body.htagoff comes with a default style --- htagweb/appserver.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htagweb/appserver.py b/htagweb/appserver.py index 4a432bb..9177415 100644 --- a/htagweb/appserver.py +++ b/htagweb/appserver.py @@ -161,7 +161,9 @@ def fqn2hr(fqn:str,js:str,init,session,fullerror=False): # fqn is a "full qualif klass=getClass(fqn) - return HRenderer( klass, js, init=init, session = session, fullerror=fullerror) + styles=Tag.style("body.htagoff * {cursor:not-allowed !important;}") + + return HRenderer( klass, js, init=init, session = session, fullerror=fullerror, statics=[styles,]) class HRSocket(WebSocketEndpoint): encoding = "text" From 3b89dd442dab0bf157dfb646dbb44352e7c6d77b Mon Sep 17 00:00:00 2001 From: manatlan Date: Fri, 22 Sep 2023 21:19:07 +0200 Subject: [PATCH 7/7] prepare compat for htag > 0.20 --- examples/oauth_example.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/oauth_example.py b/examples/oauth_example.py index 453d627..804c02b 100644 --- a/examples/oauth_example.py +++ b/examples/oauth_example.py @@ -60,6 +60,7 @@ def user(self): # -> dict or empty dict return self._rootstate.get(OAUTH_SESSION_NAME,{}) def render(self): # dynamic rendering + self.clear() self+= self.title + self.btn if self.user: self.title.set(self.user['name']) @@ -83,6 +84,8 @@ def init(self): self.oa = TagOAuth(self.state) def render(self): # dynamic rendering + self.clear() + self += self.oa self += f"You are {self.oa.user.get('name') or 'unknown'}"