Skip to content

Commit

Permalink
old code must work with new service - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
enriquepablo committed Jan 22, 2025
1 parent 24162cb commit 1d561b8
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 19 deletions.
25 changes: 21 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/cta/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
}
Expand All @@ -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");
}
Expand All @@ -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);
});

// ########################################################################################### //
Expand Down
37 changes: 29 additions & 8 deletions src/ps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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;
});
Expand All @@ -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) {
Expand All @@ -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
}
Expand All @@ -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;
});

Expand Down Expand Up @@ -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}`);
}

0 comments on commit 1d561b8

Please sign in to comment.