From 1d561b8397e087b19a16ed23bacb39c5a4ba595d Mon Sep 17 00:00:00 2001 From: enriquepablo Date: Wed, 22 Jan 2025 17:35:16 +0100 Subject: [PATCH] old code must work with new service - wip --- package-lock.json | 25 +++++++++++++++++++++---- package.json | 2 +- src/cta/index.js | 2 +- src/index.js | 10 +++++----- src/ps/index.js | 37 +++++++++++++++++++++++++++++-------- 5 files changed, 57 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3786133e..eedffdfb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,7 @@ "lodash": "^4.17.21", "mocha": "^10.7.3", "path-browserify": "^1.0.1", - "post-robot": "==8.0.32", + "post-robot": "==10.0.14", "proxy-agent": "^6.4.0", "sass": "1.77.8", "stream-browserify": "^3.0.0" @@ -2216,6 +2216,16 @@ "post-robot": "==8.0.32" } }, + "node_modules/@theidentityselector/thiss-ds/node_modules/post-robot": { + "version": "8.0.32", + "resolved": "https://registry.npmjs.org/post-robot/-/post-robot-8.0.32.tgz", + "integrity": "sha512-PMOdDAt3pyuKUxZcTzdcXXFxLqkdeLpRlcCQl7QAJpI+e7J1YHH+PfC7KAbcL8hRVQ1LknQYGoirbA1/eO/a1g==", + "dependencies": { + "cross-domain-safe-weakmap": "^1.0.1", + "cross-domain-utils": "^2.0.0", + "zalgo-promise": "^1.0.3" + } + }, "node_modules/@tootallnate/quickjs-emscripten": { "version": "0.23.0", "resolved": "https://registry.npmjs.org/@tootallnate/quickjs-emscripten/-/quickjs-emscripten-0.23.0.tgz", @@ -9521,12 +9531,14 @@ } }, "node_modules/post-robot": { - "version": "8.0.32", - "resolved": "https://registry.npmjs.org/post-robot/-/post-robot-8.0.32.tgz", - "integrity": "sha512-PMOdDAt3pyuKUxZcTzdcXXFxLqkdeLpRlcCQl7QAJpI+e7J1YHH+PfC7KAbcL8hRVQ1LknQYGoirbA1/eO/a1g==", + "version": "10.0.14", + "resolved": "https://registry.npmjs.org/post-robot/-/post-robot-10.0.14.tgz", + "integrity": "sha512-Q0ZCH16u4UbEr4vxRFx562pFx4ktyTeyZienQyZIyERgb9H8pZCIRZRy5lBTQRoNV9MoutaEP6GsVxRObJ6g9Q==", "dependencies": { + "belter": "^1.0.41", "cross-domain-safe-weakmap": "^1.0.1", "cross-domain-utils": "^2.0.0", + "universal-serialize": "^1.0.4", "zalgo-promise": "^1.0.3" } }, @@ -11696,6 +11708,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/universal-serialize": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/universal-serialize/-/universal-serialize-1.0.10.tgz", + "integrity": "sha512-FdouA4xSFa0fudk1+z5vLWtxZCoC0Q9lKYV3uUdFl7DttNfolmiw2ASr5ddY+/Yz6Isr68u3IqC9XMSwMP+Pow==" + }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", diff --git a/package.json b/package.json index 14374309..9b5d79f3 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "lodash": "^4.17.21", "mocha": "^10.7.3", "path-browserify": "^1.0.1", - "post-robot": "==8.0.32", + "post-robot": "==10.0.14", "proxy-agent": "^6.4.0", "sass": "1.77.8", "stream-browserify": "^3.0.0" diff --git a/src/cta/index.js b/src/cta/index.js index 1bac920e..2f95ac19 100644 --- a/src/cta/index.js +++ b/src/cta/index.js @@ -124,7 +124,7 @@ if (window.xprops.pinned) { start.push(ds.pin(window.xprops.pinned)); } -postRobot.on('init', {window: ds.ps.dst}, function(event) { +postRobot.on('initialized', {window: ds.ps.dst}, function(event) { recoverPersisted(start, context); }); diff --git a/src/index.js b/src/index.js index 046e76bf..ee0cd3f1 100644 --- a/src/index.js +++ b/src/index.js @@ -51,7 +51,7 @@ window.onload = function() { ds.ps.update(ds.context, entity); }); - postRobot.on('start', {window: ds.ps.dst}, function(event) { + postRobot.on('storage-access-granted', {window: ds.ps.dst}, function(event) { ds.ps.entities(ds.context).then(function(result) { if (result && result.data) { updateUI(result.data, "out-adv-1"); @@ -64,7 +64,7 @@ window.onload = function() { process.env.PERSISTENCE_URL, process.env.DEFAULT_CONTEXT); - ds2.ps.entities(ds.context).then(function(result) { + ds2.ps.entities(ds2.context).then(function(result) { if (result && result.data) { updateUI(result.data, "out-adv-2"); } @@ -78,8 +78,8 @@ window.onload = function() { const div = window.document.getElementById("checkbox-sa-preholder"); div.appendChild(elem); ds2.ps.show_checkbox("#checkbox-sa-holder-2"); - postRobot.on('start', {window: ds2.ps.dst}, function(event) { - ds2.ps.entities(ds.context).then(function(result) { + postRobot.on('storage-access-granted', {window: ds2.ps.dst}, function(event) { + ds2.ps.entities(ds2.context).then(function(result) { if (result && result.data) { updateUI(result.data, "out-adv-2"); } @@ -88,7 +88,7 @@ window.onload = function() { }); const button3 = window.document.getElementById("adv-set-entity2"); button3.addEventListener("click", (e) => { - ds2.ps.update(ds.context, entity2); + ds2.ps.update(ds2.context, entity2); }); // ########################################################################################### // diff --git a/src/ps/index.js b/src/ps/index.js index 72ba6510..a631bd00 100644 --- a/src/ps/index.js +++ b/src/ps/index.js @@ -179,11 +179,26 @@ async function reduceCookieStorage(context) { } } +function isCheckboxVisible(advCheckbox) { + if (advCheckbox) { + if (advCheckbox.checkVisibility) { + const visible = advCheckbox.checkVisibility(); + if (!visible) + return false; + } + if (window.outerHeight === 0 || window.outerWidth === 0) { + return false; + } else { + return true; + } + } else { + return false; + } +} + async function initCheckbox() { const advCheckbox = document.getElementById('ps-checkbox-adv'); - if (advCheckbox.checkVisibility) { - checkboxVisible = advCheckbox.checkVisibility(); - } + checkboxVisible = isCheckboxVisible(advCheckbox); if (checkboxVisible) { advCheckbox.addEventListener('click', async (event) => { @@ -202,8 +217,7 @@ async function initCheckbox() { stored_institutions.forEach(ins => { set_entity(storage, ins); }); - postRobot.send(window.parent, 'init') - postRobot.send(window.parent, 'start') + postRobot.send(window.parent, 'storage-access-granted') }); doPersist = advCheckbox.checked; }); @@ -217,7 +231,9 @@ async function initCheckbox() { } } -await initCheckbox(); +postRobot.on('init-checkbox', {window: window.parent}, async function(event) { + await initCheckbox(); +}); postRobot.on('persist', {window: window.parent}, function(event) { if (checkboxVisible && !doPersist) { @@ -235,6 +251,7 @@ postRobot.on('persist', {window: window.parent}, function(event) { }); postRobot.on('update', {window: window.parent}, async function(event) { + console.log(`TTTRYing to update, cbvis: ${checkboxVisible}, dP: ${doPersist}`); if (checkboxVisible && !doPersist) { return } @@ -243,7 +260,6 @@ postRobot.on('update', {window: window.parent}, async function(event) { let entity = event.data.entity; let storage = ctx(event.data.context); const ret = set_entity(storage, entity); - postRobot.send(window.parent, 'start'); return ret; }); @@ -298,4 +314,9 @@ postRobot.on('remove', {window: window.parent}, function(event) { remove_entity(event.data.context, event.data.entity_id); }); -postRobot.send(window.parent, 'init'); +try { + await initCheckbox(); + postRobot.send(window.parent, 'initialized'); +} catch (err) { + console.log(`Problem initializing client: ${err}`); +}