Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ Installs Devtron into the Electron app. Refer to [Configuring an Electron App to

#### `Options`

| Option | Type | Default | Description |
| ---------- | -------------------------------------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `logLevel` | `'debug' \| 'info' \| 'warn' \| 'error' \| 'none'` | `'debug'` | Sets the minimum log level for the logger. Messages below this level are ignored. <br><br> **Levels:** <br>• `debug` — logs: debug, info, warn, error <br>• `info` — logs: info, warn, error <br>• `warn` — logs: warn, error <br>• `error` — logs: error only <br>• `none` — disables all logging |
| Option | Type | Default | Description |
| ---------- | -------------------------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `logLevel` | `'debug' \| 'info' \| 'warn' \| 'error' \| 'none'` | `'warn'` | Sets the minimum log level for the logger. Messages below this level are ignored. <br><br> **Levels:** <br>• `debug` — logs: debug, info, warn, error <br>• `info` — logs: info, warn, error <br>• `warn` — logs: warn, error <br>• `error` — logs: error only <br>• `none` — disables all logging |

Examples:

Expand Down
20 changes: 17 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ let isInstalled = false;
let isInstalledToDefaultSession = false;
let devtronSW: Electron.ServiceWorkerMain;

/**
* Count the number of IPC calls that were made before the service worker was ready.
* Used for logging purposes.
*/
let untrackedIpcCalls = 0;

const isPayloadWithUuid = (payload: any[]): boolean => {
// If the first argument is an object with __uuid__devtron then it is a custom payload
return (
Expand Down Expand Up @@ -67,7 +73,10 @@ function trackIpcEvent({
if (excludedIpcChannels.includes(channel)) return;

if (!devtronSW) {
logger.warn('The service-worker for Devtron is not registered yet. Cannot track IPC event.');
logger.info(
`The service worker for Devtron is not registered yet. Cannot track ${direction} IPC event for channel ${channel}.`,
);
untrackedIpcCalls++;
return;
}

Expand Down Expand Up @@ -415,7 +424,12 @@ async function install(options: InstallOptions = {}) {
const extensionPath = path.resolve(serviceWorkerPreloadPath, '..', '..', 'extension');
devtron = await ses.extensions.loadExtension(extensionPath, { allowFileAccess: true });
await startServiceWorker(ses, devtron);
logger.info('Devtron loaded successfully');
if (untrackedIpcCalls > 0) {
logger.warn(
`${untrackedIpcCalls} untracked IPC events were dispatched before the service worker was ready.`,
);
}
logger.info('Devtron service worker loaded successfully');
} catch (error) {
logger.error('Failed to load Devtron:', error);
}
Expand All @@ -440,7 +454,7 @@ async function getEvents(): Promise<IpcEventDataIndexed[]> {
}

if (!devtronSW) {
logger.warn('Devtron service-worker is not registered yet. Cannot get IPC events.');
logger.warn('Devtron service worker is not registered yet. Cannot get IPC events.');
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { LogLevelString } from '../types/shared';
import { LogLevel } from '../types/shared';

class Logger {
private currentLogLevel = LogLevel.debug;
private currentLogLevel = LogLevel.warn;

setLogLevel(level: LogLevelString) {
if (LogLevel[level] === undefined) {
Expand Down