synchronously log

Signed-off-by: Xe Iaso <me@christine.website>
This commit is contained in:
Cadey Ratio 2022-05-09 18:34:50 +00:00
parent 2c2f545a9a
commit 43058cbd15
2 changed files with 13 additions and 12 deletions

View File

@ -2,10 +2,12 @@ import json
import os import os
import pathlib import pathlib
import subprocess import subprocess
import sys
class Plugin: class Plugin:
async def log(self, message=""): async def log(self, message=""):
print("frontend: " + message) print("frontend: " + message)
sys.stdout.flush()
async def whoami(self, *args): async def whoami(self, *args):
return os.getuid() return os.getuid()
@ -30,8 +32,9 @@ class Plugin:
return "impossible state" return "impossible state"
async def install_state(self, *args): async def install_state(self, *args):
result = await self.install_state() await self.log("fetching state")
print("status: " + result) result = self.install_state()
await self.log("status: " + result)
return result return result
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded # Asyncio-compatible long-running code, executed in a task when the plugin is loaded

View File

@ -5,29 +5,27 @@
<link rel="stylesheet" href="/steam_resource/css/library.css"> <link rel="stylesheet" href="/steam_resource/css/library.css">
<script src="/static/library.js"></script> <script src="/static/library.js"></script>
<script> <script>
function log(message) { async function log(message) {
return call_plugin_method("log", {"message": message}); return call_plugin_method("log", {"message": `${message}`);
} }
function getUID() { async function getUID() {
return call_plugin_method("whoami", {}); return call_plugin_method("whoami", {});
} }
function getInstallState() { async function getInstallState() {
return call_plugin_method("install_state", {}); return call_plugin_method("install_state", {});
} }
function getStatus() { async function getStatus() {
let status = document.getElementById("status"); let status = document.getElementById("status");
let installStatus = getInstallState(); let installStatus = await getInstallState();
log(installStatus);
status.innerText = `${installStatus}`; status.innerText = `${installStatus}`;
} }
function onReady() { async function onReady() {
let heading = document.getElementById("heading"); let heading = document.getElementById("heading");
let id = getUID(); let id = await getUID();
heading.innerText = `Hello ${id}`; heading.innerText = `Hello ${id}`;
} }
</script> </script>