From c39119112c1c1a7bd1e2cd8eff55a118edb72b4c Mon Sep 17 00:00:00 2001 From: Oliver-Cho Date: Tue, 27 Feb 2024 15:52:40 -0500 Subject: [PATCH 1/4] fixed clear button bug where pressing it multiple times would crash the app. Still some console.logs left in there tho --- src/app/slices/mainSlice.ts | 4 ++-- src/extension/background.js | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/app/slices/mainSlice.ts b/src/app/slices/mainSlice.ts index c7299e649..107d9769a 100644 --- a/src/app/slices/mainSlice.ts +++ b/src/app/slices/mainSlice.ts @@ -51,8 +51,7 @@ export const mainSlice = createSlice({ const currAxSnapshot = tabs[currentTab].axSnapshots[tabs[currentTab].currLocation.index]; // current snapshot tabs[currentTab].hierarchy.stateSnapshot = { ...currSnapshot }; // resets hierarchy to page current snapshot - // not sure why shallow deep copy - tabs[currentTab].hierarchy.axSnapshot = currAxSnapshot; // resets hierarchy to current snapshot + tabs[currentTab].hierarchy.axSnapshot = { ...currAxSnapshot }; // resets hierarchy to current accessibility tree snapshot tabs[currentTab].hierarchy.children = []; // resets hierarchy tabs[currentTab].snapshots = [currSnapshot]; // resets snapshots to current snapshot tabs[currentTab].axSnapshots = [currAxSnapshot]; // resets snapshots to current snapshot @@ -61,6 +60,7 @@ export const mainSlice = createSlice({ tabs[currentTab].index = 1; tabs[currentTab].currParent = 0; tabs[currentTab].currBranch = 1; + tabs[currentTab].currLocation = tabs[currentTab].hierarchy; tabs[currentTab].seriesSavedStatus = false; }, diff --git a/src/extension/background.js b/src/extension/background.js index 59b001c80..94e7bf9f0 100644 --- a/src/extension/background.js +++ b/src/extension/background.js @@ -358,6 +358,10 @@ chrome.runtime.onConnect.addListener((port) => { // emptySnap actions comes through when the user uses the 'clear' button on the front end to clear the snapshot history and move slider back to 0 position case 'emptySnap': + console.log( + 'background.js: top of emptySnap tabsObj[tabId]:', + JSON.parse(JSON.stringify(tabsObj[tabId])), + ); tabsObj[tabId].snapshots = [tabsObj[tabId].snapshots[tabsObj[tabId].currLocation.index]]; // reset snapshots to current page state tabsObj[tabId].hierarchy.children = []; // resets hierarchy tabsObj[tabId].hierarchy.stateSnapshot = { @@ -366,12 +370,23 @@ chrome.runtime.onConnect.addListener((port) => { ...tabsObj[tabId].snapshots[0], }; tabsObj[tabId].axSnapshots = [ - tabsObj[tabId].axSnapshots[tabsObj[tabId].currLocation.index], + JSON.parse(JSON.stringify(tabsObj[tabId].axSnapshots[tabsObj[tabId].currLocation.index])), ]; // resets axSnapshots to current page state - tabsObj[tabId].hierarchy.axSnapshot = tabsObj[tabId].axSnapshots[0]; // resets hierarchy to ax tree of current page state + console.log( + 'background.js: tabsObj[tabId].axSnapshots:', + JSON.parse(JSON.stringify(tabsObj[tabId].axSnapshots)), + ); + tabsObj[tabId].hierarchy.axSnapshot = JSON.parse( + JSON.stringify(tabsObj[tabId].axSnapshots[0]), + ); // resets hierarchy to ax tree of current page state tabsObj[tabId].index = 1; //reset index tabsObj[tabId].currParent = 0; // reset currParent tabsObj[tabId].currBranch = 1; // reset currBranch + tabsObj[tabId].currLocation = tabsObj[tabId].hierarchy; + console.log( + 'background.js: bottom of emptySnap tabsObj[tabId]:', + JSON.parse(JSON.stringify(tabsObj[tabId])), + ); return true; // return true so that port remains open From d6a9ca13f79b4f76e2dce2d1fe9a1cb046b83d38 Mon Sep 17 00:00:00 2001 From: Oliver-Cho Date: Tue, 27 Feb 2024 16:00:43 -0500 Subject: [PATCH 2/4] removed console.logs --- src/app/slices/mainSlice.ts | 4 ++-- src/extension/background.js | 14 +------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/app/slices/mainSlice.ts b/src/app/slices/mainSlice.ts index 107d9769a..82a0aadaa 100644 --- a/src/app/slices/mainSlice.ts +++ b/src/app/slices/mainSlice.ts @@ -48,7 +48,7 @@ export const mainSlice = createSlice({ tabs[currentTab].playing = false; const currSnapshot = tabs[currentTab].snapshots[tabs[currentTab].currLocation.index]; // current snapshot - const currAxSnapshot = tabs[currentTab].axSnapshots[tabs[currentTab].currLocation.index]; // current snapshot + const currAxSnapshot = tabs[currentTab].axSnapshots[tabs[currentTab].currLocation.index]; // current accessibility tree snapshot tabs[currentTab].hierarchy.stateSnapshot = { ...currSnapshot }; // resets hierarchy to page current snapshot tabs[currentTab].hierarchy.axSnapshot = { ...currAxSnapshot }; // resets hierarchy to current accessibility tree snapshot @@ -60,7 +60,7 @@ export const mainSlice = createSlice({ tabs[currentTab].index = 1; tabs[currentTab].currParent = 0; tabs[currentTab].currBranch = 1; - tabs[currentTab].currLocation = tabs[currentTab].hierarchy; + tabs[currentTab].currLocation = tabs[currentTab].hierarchy; // reset currLocation tabs[currentTab].seriesSavedStatus = false; }, diff --git a/src/extension/background.js b/src/extension/background.js index 94e7bf9f0..195abf144 100644 --- a/src/extension/background.js +++ b/src/extension/background.js @@ -358,10 +358,6 @@ chrome.runtime.onConnect.addListener((port) => { // emptySnap actions comes through when the user uses the 'clear' button on the front end to clear the snapshot history and move slider back to 0 position case 'emptySnap': - console.log( - 'background.js: top of emptySnap tabsObj[tabId]:', - JSON.parse(JSON.stringify(tabsObj[tabId])), - ); tabsObj[tabId].snapshots = [tabsObj[tabId].snapshots[tabsObj[tabId].currLocation.index]]; // reset snapshots to current page state tabsObj[tabId].hierarchy.children = []; // resets hierarchy tabsObj[tabId].hierarchy.stateSnapshot = { @@ -372,21 +368,13 @@ chrome.runtime.onConnect.addListener((port) => { tabsObj[tabId].axSnapshots = [ JSON.parse(JSON.stringify(tabsObj[tabId].axSnapshots[tabsObj[tabId].currLocation.index])), ]; // resets axSnapshots to current page state - console.log( - 'background.js: tabsObj[tabId].axSnapshots:', - JSON.parse(JSON.stringify(tabsObj[tabId].axSnapshots)), - ); tabsObj[tabId].hierarchy.axSnapshot = JSON.parse( JSON.stringify(tabsObj[tabId].axSnapshots[0]), ); // resets hierarchy to ax tree of current page state tabsObj[tabId].index = 1; //reset index tabsObj[tabId].currParent = 0; // reset currParent tabsObj[tabId].currBranch = 1; // reset currBranch - tabsObj[tabId].currLocation = tabsObj[tabId].hierarchy; - console.log( - 'background.js: bottom of emptySnap tabsObj[tabId]:', - JSON.parse(JSON.stringify(tabsObj[tabId])), - ); + tabsObj[tabId].currLocation = tabsObj[tabId].hierarchy; // reset currLocation return true; // return true so that port remains open From 19ccfc480af40fc89e8aa7d41eaf2b3e4e6d1762 Mon Sep 17 00:00:00 2001 From: Oliver-Cho Date: Tue, 27 Feb 2024 16:04:28 -0500 Subject: [PATCH 3/4] removed unnecessary deep copies in background.js for emptySnap for clear button --- src/extension/background.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/extension/background.js b/src/extension/background.js index 195abf144..5014d565a 100644 --- a/src/extension/background.js +++ b/src/extension/background.js @@ -366,11 +366,9 @@ chrome.runtime.onConnect.addListener((port) => { ...tabsObj[tabId].snapshots[0], }; tabsObj[tabId].axSnapshots = [ - JSON.parse(JSON.stringify(tabsObj[tabId].axSnapshots[tabsObj[tabId].currLocation.index])), + tabsObj[tabId].axSnapshots[tabsObj[tabId].currLocation.index], ]; // resets axSnapshots to current page state - tabsObj[tabId].hierarchy.axSnapshot = JSON.parse( - JSON.stringify(tabsObj[tabId].axSnapshots[0]), - ); // resets hierarchy to ax tree of current page state + tabsObj[tabId].hierarchy.axSnapshot = tabsObj[tabId].axSnapshots[0]; // resets hierarchy to ax tree of current page state tabsObj[tabId].index = 1; //reset index tabsObj[tabId].currParent = 0; // reset currParent tabsObj[tabId].currBranch = 1; // reset currBranch From 78dd524a9b39099932d9a8871dcf0d8b53545d1d Mon Sep 17 00:00:00 2001 From: Oliver-Cho Date: Tue, 27 Feb 2024 16:10:30 -0500 Subject: [PATCH 4/4] changed some comments for clarification --- src/app/slices/mainSlice.ts | 2 +- src/extension/background.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/slices/mainSlice.ts b/src/app/slices/mainSlice.ts index 82a0aadaa..98fd12d6e 100644 --- a/src/app/slices/mainSlice.ts +++ b/src/app/slices/mainSlice.ts @@ -50,7 +50,7 @@ export const mainSlice = createSlice({ const currSnapshot = tabs[currentTab].snapshots[tabs[currentTab].currLocation.index]; // current snapshot const currAxSnapshot = tabs[currentTab].axSnapshots[tabs[currentTab].currLocation.index]; // current accessibility tree snapshot - tabs[currentTab].hierarchy.stateSnapshot = { ...currSnapshot }; // resets hierarchy to page current snapshot + tabs[currentTab].hierarchy.stateSnapshot = { ...currSnapshot }; // resets hierarchy to current snapshot tabs[currentTab].hierarchy.axSnapshot = { ...currAxSnapshot }; // resets hierarchy to current accessibility tree snapshot tabs[currentTab].hierarchy.children = []; // resets hierarchy tabs[currentTab].snapshots = [currSnapshot]; // resets snapshots to current snapshot diff --git a/src/extension/background.js b/src/extension/background.js index 5014d565a..210950082 100644 --- a/src/extension/background.js +++ b/src/extension/background.js @@ -368,7 +368,7 @@ chrome.runtime.onConnect.addListener((port) => { tabsObj[tabId].axSnapshots = [ tabsObj[tabId].axSnapshots[tabsObj[tabId].currLocation.index], ]; // resets axSnapshots to current page state - tabsObj[tabId].hierarchy.axSnapshot = tabsObj[tabId].axSnapshots[0]; // resets hierarchy to ax tree of current page state + tabsObj[tabId].hierarchy.axSnapshot = tabsObj[tabId].axSnapshots[0]; // resets hierarchy to accessibility tree of current page state tabsObj[tabId].index = 1; //reset index tabsObj[tabId].currParent = 0; // reset currParent tabsObj[tabId].currBranch = 1; // reset currBranch