-
Notifications
You must be signed in to change notification settings - Fork 108
feat: use Session to track IPCs and improve UI
#268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
aacbd32
e9ebfa8
a325be3
49b9278
802f6a9
9532eb1
1061de2
6d79297
e810813
9e62744
2425951
4387be5
1102a77
56da3ae
544bc34
6b6e2ea
f7b8436
de1c472
333d2d1
315efd9
b572b8e
48da593
1de3100
44a8f47
87adb6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| { | ||
| "singleQuote": true, | ||
| "printWidth": 100 | ||
| "printWidth": 100, | ||
| "plugins": ["prettier-plugin-tailwindcss"] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,43 @@ | ||
| # Devtron | ||
|
|
||
| > [!NOTE] | ||
| > This project is under development and subject to change. | ||
|
|
||
| ## Building and Development | ||
|
|
||
| - Clone the repository to your local machine | ||
| - Run `npm install` to install dependencies | ||
| - Run `npm link` to link the package globally | ||
| - Run `npm run build` to build the project | ||
|
|
||
| #### Configuring an Electron App to use Devtron | ||
|
|
||
| - In your Electron app run `npm link @electron/devtron` to link the Devtron package | ||
| - In your Electron app's `main.js` (or other relevant file) add the following code to load Devtron: | ||
|
|
||
| ```js | ||
| // main.js | ||
| const { devtron } = require('@electron/devtron') | ||
| const { monitorMain } = require('@electron/devtron/monitorMain') | ||
| monitorMain() | ||
| const { devtron } = require('@electron/devtron'); | ||
| // or import { devtron } from '@electron/devtron' | ||
|
|
||
| // function createWindow() {...} | ||
|
|
||
| app.whenReady().then(() => { | ||
| devtron.install() | ||
| devtron.install(); | ||
| // ... | ||
| }) | ||
| }); | ||
| ``` | ||
|
|
||
| - In your Electron app's `preload.js` (or other relevant file) add the following code to load Devtron: | ||
|
|
||
| ```js | ||
| // preload.js | ||
| const { monitorRenderer } = require('@electron/devtron/monitorRenderer') | ||
| monitorRenderer() | ||
| const { monitorRenderer } = require('@electron/devtron/monitorRenderer'); | ||
| // or import { monitorRenderer } from '@electron/devtron/monitorRenderer' | ||
|
|
||
| monitorRenderer(); | ||
| ``` | ||
|
|
||
| If Devtron is installed correctly, it should appear as a tab in the Developer Tools of your Electron app. | ||
|  | ||
|
|
||
| <img src="https://github.com/user-attachments/assets/0f278b54-50fe-4116-9317-9c1525bf872b" width="800"> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import type { IpcEventData } from './src/types/shared'; | ||
|
|
||
| declare global { | ||
| function addIpcEvent(data: IpcEventData): void; | ||
| } | ||
| export {}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,17 +7,6 @@ import type { | |
| MessagePanel, | ||
| } from '../../types/shared'; | ||
|
|
||
| /* ------------------------------------------------------ */ | ||
| /** | ||
| * This is used to keep the background script alive. More testing is needed to determine whether it is needed or not | ||
| * since other KEEP_ALIVE methods are already implemented in the content script and panel script. | ||
| * Code copied from: https://stackoverflow.com/questions/66618136/persistent-service-worker-in-chrome-extension | ||
| */ | ||
| const keepAlive = () => setInterval(chrome.runtime.getPlatformInfo, 20e3); | ||
| chrome.runtime.onStartup.addListener(keepAlive); | ||
| keepAlive(); | ||
| /* ------------------------------------------------------ */ | ||
|
|
||
|
Comment on lines
-10
to
-20
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to put an explainer in the PR body to explain why we don't need to keep the background script alive using this hack anymore.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a bullet point explaining the change. |
||
| const MAX_EVENTS = 1000; | ||
| const ipcEvents = new Denque<IpcEventDataIndexed>(); | ||
|
|
||
|
|
@@ -34,8 +23,6 @@ function handlePanelMessage(message: MessagePanel): void { | |
| case MSG_TYPE.PING: | ||
| connections.panel?.postMessage({ type: MSG_TYPE.PONG }); // (mimics `port.postMessage(...)`) | ||
| break; | ||
| case MSG_TYPE.KEEP_ALIVE: | ||
| break; | ||
| case MSG_TYPE.GET_ALL_EVENTS: | ||
| for (let i = 0; i < ipcEvents.length; i++) { | ||
| const event = ipcEvents.get(i); | ||
|
|
@@ -49,7 +36,7 @@ function handlePanelMessage(message: MessagePanel): void { | |
| throw new Error( | ||
| `Devtron - Background script: Unknown message type from panel: ${ | ||
| (message as MessagePanel).type | ||
| }` | ||
| }`, | ||
| ); | ||
| } | ||
| } | ||
|
|
@@ -76,8 +63,6 @@ function handleContentMessage(message: MessageContentScript): void { | |
| case MSG_TYPE.ADD_IPC_EVENT: | ||
| addIpcEvent(message.event); | ||
| break; | ||
| case MSG_TYPE.KEEP_ALIVE: | ||
| break; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -102,3 +87,5 @@ chrome.runtime.onConnect.addListener((port) => { | |
| }); | ||
| } | ||
| }); | ||
|
|
||
| (globalThis as any).addIpcEvent = addIpcEvent; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With Prettier 3.6, we can enable the
--experimental-cliflag for a performance boost.ref electron/website#841
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, added the linting scripts here - 1102a77
Edit: Ran the linters in this commit - 56da3ae