From f8e58dd532a1be8fe6d5eaba22b2436d325c7780 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 28 Jan 2022 16:45:02 +0100 Subject: [PATCH] adapt to new async api and real properties --- index.html | 4 ++-- webxdc.js | 17 ++++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/index.html b/index.html index b97fef0..9604759 100644 --- a/index.html +++ b/index.html @@ -11,7 +11,7 @@ diff --git a/webxdc.js b/webxdc.js index 0f1446f..09989c0 100644 --- a/webxdc.js +++ b/webxdc.js @@ -15,19 +15,14 @@ window.webxdc = (() => { } }); + var params = new URLSearchParams(window.location.hash.substr(1)); return { - selfAddr: () => { - var params = new URLSearchParams(window.location.hash.substr(1)); - return params.get("addr") || "device0@local.host"; - }, - selfName: () => { - var params = new URLSearchParams(window.location.hash.substr(1)); - return params.get("name") || "device0"; - }, + selfAddr: params.get("addr") || "device0@local.host", + selfName: params.get("name") || "device0", setUpdateListener: (cb) => (updateListener = cb), getAllUpdates: () => { var updatesJSON = window.localStorage.getItem(updatesKey); - return updatesJSON ? JSON.parse(updatesJSON) : []; + return Promise.resolve(updatesJSON ? JSON.parse(updatesJSON) : []); }, sendUpdate: (update, description) => { // alert(description+"\n\n"+JSON.stringify(payload)); @@ -72,9 +67,9 @@ window.alterXdcApp = () => { title = document.createElement('title'); document.getElementsByTagName('head')[0].append(title); } - title.innerText = window.webxdc.selfAddr(); + title.innerText = window.webxdc.selfAddr; - if (window.webxdc.selfName() === "device0") { + if (window.webxdc.selfName === "device0") { var div = document.createElement('div'); div.innerHTML = '
' +