Skip to content

Commit 5b63837

Browse files
committed
more logs. Got the extension to load on the same tab as the one that invoked it.
1 parent 1004ca6 commit 5b63837

File tree

8 files changed

+59
-24
lines changed

8 files changed

+59
-24
lines changed

src/app/components/Diff.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,16 @@ function Diff(props: DiffProps): JSX.Element {
8080
return newObj; // return the cleaned state snapshot(s)
8181
};
8282

83-
console.log('previousDisplay before stateless cleaning: ', previous);
83+
// console.log('previousDisplay before stateless cleaning: ', previous);
8484
const previousDisplay: StatelessCleaning = statelessCleaning(previous); // displays stateful data from the first snapshot that was taken before our current snapshot.
85-
console.log('previousDisplay after stateless cleaning: ', previousDisplay);
85+
86+
// console.log('previousDisplay after stateless cleaning: ', previousDisplay);
8687
const delta: StatelessCleaning = diff(previousDisplay, snapshot); // diff function from 'jsondiffpatch' returns the difference in state between 'previousDisplay' and 'snapshot'
87-
console.log('delta: ', delta);
88+
89+
// console.log('delta: ', delta);
8890
const html: StatelessCleaning = formatters.html.format(delta, previousDisplay); // formatters function from 'jsondiffpatch' returns an html string that shows the difference between delta and the previousDisplay
89-
console.log('html: ', html);
91+
92+
// console.log('html: ', html);
9093

9194
console.log(show);
9295
console.log(formatters.html.showUnchanged());

src/app/components/SwitchApp.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,8 @@ const SwitchAppDropdown = (): JSX.Element => {
4646
classNamePrefix='tab-select'
4747
value={currTab}
4848
styles={customStyles}
49-
onInputChange={(inputValue, { action }): void => {
50-
console.log('onInputChange action', action);
51-
if (action === 'set-value') {
52-
console.log('Option selected: ', inputValue);
53-
// dispatch(setTab(parseInt(e.value, 10)));
54-
}
49+
onChange={(e): void => {
50+
dispatch(setTab(parseInt(e.value, 10)));
5551
}}
5652
options={tabsArray}
5753
/>

src/app/components/theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createTheme } from '@mui/material/styles';
22
const theme = createTheme({
33
palette: {
44
primary: {
5-
main: '#8Fb5f9',
5+
main: '#b2f7a1',
66
},
77
secondary: {
88
main: '#BF6DD2',

src/app/slices/mainSlice.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export const mainSlice = createSlice({
127127
setTab: (state, action) => {
128128
const { tabs, currentTab } = state;
129129
const { mode } = tabs[currentTab] || {};
130-
console.log('mainSlice. mode: ', mode, 'payload: ', action.payload);
130+
console.log('mainSlice setTab, mode: ', mode, 'payload: ', action.payload);
131131
if (!mode?.paused) {
132132
if (typeof action.payload === 'number') {
133133
state.currentTab = action.payload;
@@ -176,7 +176,19 @@ export const mainSlice = createSlice({
176176

177177
changeView: (state, action) => {
178178
const { tabs, currentTab } = state;
179+
console.log(
180+
'changeView tabs: ',
181+
tabs,
182+
'currentTab: ',
183+
currentTab,
184+
'tabs[currentTab]: ',
185+
tabs[currentTab],
186+
);
187+
console.log(tabs);
188+
console.log('changeView state: ', state);
179189
const { viewIndex } = tabs[currentTab] || {};
190+
console.log('changeView viewIndex: ', viewIndex);
191+
console.log('changeView action.payload: ', action.payload);
180192
// unselect view if same index was selected
181193
tabs[currentTab].viewIndex = viewIndex === action.payload ? -1 : action.payload;
182194
},

src/extension/background.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Import snapshots from "../app/components/snapshots".
22
// import 'core-js';
33

4+
import { invoke } from 'lodash';
5+
46
// Store ports in an array.
57
const portsArr = [];
68
const reloaded = {};
@@ -62,6 +64,7 @@ class Node {
6264
tabObj.index += 1;
6365
// continues the order of number of states changed from that parent
6466
tabObj.currParent += 1;
67+
console.log('new Node tabObj: ', tabObj);
6568
this.name = tabObj.currParent;
6669
// marks from what branch this node is originated
6770
this.branch = tabObj.currBranch;
@@ -162,6 +165,7 @@ chrome.runtime.onConnect.addListener((port) => {
162165
console.log('tabsObj onConnect: ', tabsObj);
163166
portsArr.push(port); // push each Reactime communication channel object to the portsArr
164167
console.log('portsArr onConnect: ', portsArr);
168+
165169
// JR: CONSIDER DELETING
166170
if (portsArr.length > 0) {
167171
portsArr.forEach((bg) => {
@@ -491,14 +495,34 @@ chrome.runtime.onInstalled.addListener(() => {
491495

492496
// when context menu is clicked, listen for the menuItemId,
493497
// if user clicked on reactime, open the devtools window
498+
499+
// JR 12.19.23
500+
// As of V22, if multiple monitors are used, it would open the reactime panel on the other screen, which was inconvenient when opening repeatedly for debugging.
501+
// V23 fixes this by making use of chrome.windows.getCurrent to get the top and left of the screen which invoked the extension.
502+
// The reason you must use chrome.windows.getCurrent is that as of chrome manifest V3, background.js is a 'service worker', which does not have access to the DOM or to the native 'window' method.
503+
// chrome.windows.getCurrent allows us to still get the window from within a service worker. It returns a promise (asynchronous), so all resulting functionality must happen in the callback function,
504+
// or it will run before 'invokedScreen' variables have been captured.
494505
chrome.contextMenus.onClicked.addListener(({ menuItemId }) => {
495-
const options = {
496-
type: 'panel',
497-
left: 0,
498-
top: 0,
499-
width: 1000,
500-
height: 1000,
501-
url: chrome.runtime.getURL('panel.html'),
502-
};
503-
if (menuItemId === 'reactime') chrome.windows.create(options);
506+
console.log('background ext screenX', chrome.windows.getCurrent());
507+
508+
chrome.system.display.getInfo((displayUnitInfo) => {
509+
console.log(displayUnitInfo);
510+
});
511+
512+
let invokedScreenTop = 0;
513+
let invokedScreenLeft = 0;
514+
chrome.windows.getCurrent((window) => {
515+
invokedScreenTop = window.top + 300 || 0;
516+
console.log('invokedTop', invokedScreenTop);
517+
invokedScreenLeft = window.left || 0;
518+
const options = {
519+
type: 'panel',
520+
left: invokedScreenLeft,
521+
top: invokedScreenTop,
522+
width: 1000,
523+
height: 1000,
524+
url: chrome.runtime.getURL('panel.html'),
525+
};
526+
if (menuItemId === 'reactime') chrome.windows.create(options);
527+
});
504528
});

src/extension/build/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
"matches": ["<all_urls>"]
2525
}
2626
],
27-
"permissions": ["contextMenus", "tabs", "activeTab", "scripting"],
27+
"permissions": ["contextMenus", "tabs", "activeTab", "scripting", "system.display"],
2828
"host_permissions": ["<all_urls>"]
2929
}

src/extension/build/panel.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
7-
<title>Reactime 22.0</title>
7+
<title>Reactime 23.0</title>
88
</head>
99

1010
<body>

typedoc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"out": "docs",
44
"includes": ["./src/backend"],
55
"exclude": ["**/__tests__/**", "**/**/**/build/**", "**/types/**"],
6-
"name": "Reactime 21.0"
6+
"name": "Reactime 23.0"
77
}

0 commit comments

Comments
 (0)