Skip to content

[ONCALL-184] fix: bg-process opens for windows#240

Merged
nsrCodes merged 4 commits into
masterfrom
ONCALL-184
Dec 2, 2025
Merged

[ONCALL-184] fix: bg-process opens for windows#240
nsrCodes merged 4 commits into
masterfrom
ONCALL-184

Conversation

@Aarushsr12

@Aarushsr12 Aarushsr12 commented Dec 1, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Refactor

    • Formatting and style consistency improvements across the codebase (spacing, indentation, quotes, and minor syntax refinements).
  • Chores

    • Three menu items renamed from "Toggle Developer Tools" to "Debug Requestly".
    • Toggling DevTools now also enables enhanced background-window debugging to streamline debugging.

✏️ Tip: You can customize this high-level summary in your review settings.

@linear

linear Bot commented Dec 1, 2025

Copy link
Copy Markdown

@Aarushsr12 Aarushsr12 requested a review from nsrCodes December 1, 2025 17:24
@coderabbitai

coderabbitai Bot commented Dec 1, 2025

Copy link
Copy Markdown

Walkthrough

The pull request updates two main-process TypeScript files. src/main/main.ts contains widespread formatting and stylistic changes (spacing, semicolons, quote normalization, indentation) and a few minor control-flow/syntax refinements that do not change exported signatures. src/main/menu.ts renames three menu items from "Toggle Developer Tools" to "Debug Requestly" and adds calls to this.enableBGWindowDebug() immediately after this.mainWindow.webContents.toggleDevTools() in those menu actions. No public/exported entity declarations were modified.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10–15 minutes

  • src/main/main.ts: Quick scan for accidental logic changes around early returns, guard conditions, and window/dialog handling introduced by the minor control-flow edits.
  • src/main/menu.ts: Verify three menu entries were renamed consistently and that each new enableBGWindowDebug() call immediately follows the corresponding toggleDevTools() invocation and that enableBGWindowDebug is accessible in the menu context.
  • Confirm formatting-only edits did not alter runtime behavior (operator precedence, removed tokens, or inadvertent semicolon changes).

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is specific and directly related to the main change: fixing a background process opening issue for Windows by enabling debug window functionality.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ONCALL-184

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f3c0230 and 4b84b93.

📒 Files selected for processing (1)
  • src/main/menu.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/menu.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/main.ts (1)

398-437: Protocol registration needs adjustment: check process.defaultApp instead of platform

The current approach registers the protocol using process.execPath and argv on all Windows platforms, but Electron's recommended pattern checks process.defaultApp (dev mode) instead:

if (process.defaultApp) {
  // dev mode: pass execPath and app entry point so Windows launches correctly
  if (process.argv.length >= 2) {
    app.setAsDefaultProtocolClient("requestly", process.execPath, [path.resolve(process.argv[1])]);
  }
} else {
  // production: simple form sufficient
  app.setAsDefaultProtocolClient("requestly");
}

The code currently passes execPath and argv on all Windows builds, including packaged production releases, which diverges from Electron's documented best practice. Platform-only checks don't distinguish between development and packaged environments.

Additionally, consider calling this earlier (before or during app initialization) rather than inside loadingScreenWindow.once("show", ...) to ensure timely registration.

🧹 Nitpick comments (4)
src/main/main.ts (4)

85-181: Tray recreation and proxy-dependent menu entries are handled cleanly

Destroying any existing tray before creating a new one avoids duplicate tray icons, and splicing out the “Listening On …” submenu when ip or port are not provided keeps the UI sane while the proxy is still initializing. The Windows‑specific .ico icon path also aligns with platform expectations.

If you ever support a port value of 0 as a sentinel, consider tightening the check to ip == null || port == null instead of a generic falsy test, but it’s not required for typical proxy ports.


289-317: Windows-specific focus handling for backgroundWindow is helpful; consider an extra safety check

The enableBGWindowDebug helper now:

  • shows and focuses globalAny.backgroundWindow,
  • on Windows, briefly sets alwaysOnTop to bring it to the foreground,
  • then toggles its DevTools.

That matches the PR goal of making the background process window actually surface on Windows. One small robustness tweak you might consider:

-        if (process.platform === "win32") {
-          globalAny.backgroundWindow.setAlwaysOnTop(true);
-          setTimeout(() => {
-            globalAny.backgroundWindow.setAlwaysOnTop(false);
-          }, 100);
-        }
+        if (process.platform === "win32") {
+          globalAny.backgroundWindow.setAlwaysOnTop(true);
+          setTimeout(() => {
+            if (
+              globalAny.backgroundWindow &&
+              !globalAny.backgroundWindow.isDestroyed()
+            ) {
+              globalAny.backgroundWindow.setAlwaysOnTop(false);
+            }
+          }, 100);
+        }

to avoid potential errors if the background window is closed within that 100 ms window.


323-327: onWebAppReadyHandlers queue for open-url/open-file is solid; requeue on file read error may not be needed

The pattern of:

  • pushing handlers into onWebAppReadyHandlers when open-url or open-file events fire before webAppWindow is ready, and
  • draining them once in executeOnWebAppReadyHandlers() after the window is ready-to-show,

is a clean way to avoid dropping those OS-level events.

Two small observations:

  1. In handleFileOpen’s catch block you do:

    logger.error(`Error while reading file ${filePath}`, error);
    onWebAppReadyHandlers.push(() => handleFileOpen(filePath));

    For actual I/O errors (file missing, permission issues, etc.), re-queueing won’t fix the problem and won’t get executed anyway until the next time you explicitly call executeOnWebAppReadyHandlers. It might be clearer to just log the error (and maybe surface it to the user) without pushing a new handler.

  2. In the "open-file" app event, logging "webAppWindow not ready" and pushing a handler into the queue is good; just be aware this is macOS-only behavior and that, by design, those queued handlers run only once per window creation.

Neither point is blocking, but cleaning up the requeue in the catch block would simplify the mental model.

Also applies to: 330-338, 351-358, 360-382, 384-393


486-500: Shutdown cleanup and error logging improvements look good

In before-quit:

  • Removing listeners from ipcMain, webAppWindow, and backgroundWindow is a reasonable cleanup step to minimize stray event handling during shutdown (the duplicate ipcMain.removeAllListeners() is harmless but redundant).
  • Adding process.on("uncaughtException") and process.on("unhandledRejection") handlers that log via logger during quit helps capture late-stage failures that might otherwise be lost.

If you want to tighten this further, you could drop the second ipcMain.removeAllListeners() call, but it’s not functionally problematic.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 00d00da and 46a17f5.

📒 Files selected for processing (2)
  • src/main/main.ts (18 hunks)
  • src/main/menu.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/main/main.ts (2)
src/main/actions/cleanup.js (2)
  • getReadyToQuitApp (17-31)
  • getReadyToQuitApp (17-31)
src/main/events.js (1)
  • trackRecentlyAccessedFile (46-66)
🔇 Additional comments (4)
src/main/menu.ts (1)

128-135: Consistent wiring of enableBGWindowDebug with DevTools toggles looks good

Hooking this.enableBGWindowDebug() immediately after each toggleDevTools() keeps the background window debugging behavior consistent across macOS and default menus, and aligns with the Windows focus fix in enableBGWindowDebug. No functional concerns from this change.

Also applies to: 328-335, 391-397

src/main/main.ts (3)

15-24: Import restructuring from electron is fine

Switching to the grouped destructured import from "electron" is stylistic and keeps the main-process dependencies clear; no behavioral change here.


197-205: Frameless macOS window options via spread are correct

Using a framelessOptions object only on process.platform === "darwin" and then spreading it into the BrowserWindow options keeps the macOS customization isolated without affecting Windows/Linux behavior. This is a clean way to introduce platform-specific tweaks.

Also applies to: 220-221


457-467: Setapp usage logging changes are benign

The additional log.log statements around Setapp integration ("[SETAPP] build identified" and "[SETAPP] integration complete") are low-risk and should help diagnose issues specific to Setapp builds without affecting other distributions.

Comment thread src/main/main.ts
Comment on lines +183 to 184
let closingAccepted = false;
const createWindow = async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Sanity-check where "quit-app" is invoked from the renderer side.
rg -n "quit-app" --type ts --type tsx

Repository: requestly/requestly-desktop-app

Length of output: 102


🏁 Script executed:

#!/bin/bash
# Search for "quit-app" invocations
rg -n "quit-app" src/

Repository: requestly/requestly-desktop-app

Length of output: 136


🏁 Script executed:

#!/bin/bash
# Get file info and read the relevant sections
wc -l src/main/main.ts
echo "---"
# Read around line 183-184
sed -n '175,195p' src/main/main.ts
echo "---"
# Read around line 276-288
sed -n '270,295p' src/main/main.ts
echo "---"
# Read around line 481-484
sed -n '475,490p' src/main/main.ts

Repository: requestly/requestly-desktop-app

Length of output: 1694


🏁 Script executed:

#!/bin/bash
# Search for initiate-app-close in the codebase
rg -n "initiate-app-close" src/

Repository: requestly/requestly-desktop-app

Length of output: 155


🏁 Script executed:

#!/bin/bash
# Explore directory structure
ls -la src/
echo "---"
# Look for all TypeScript/JavaScript files that might be renderer code
find src/ -type f -name "*.ts" -o -name "*.tsx" -o -name "*.js" | head -20

Repository: requestly/requestly-desktop-app

Length of output: 1300


🏁 Script executed:

#!/bin/bash
# Search in renderer directory for initiate-app-close
rg -n "initiate-app-close" src/renderer/
echo "---"
# Also search for quit-app invocation in renderer
rg -n "quit-app" src/renderer/
echo "---"
# Search for ipcRenderer.on or ipcRenderer.handle patterns
rg -n "ipcRenderer\.(on|handle)" src/renderer/ | head -20

Repository: requestly/requestly-desktop-app

Length of output: 2010


🏁 Script executed:

#!/bin/bash
# Check the full initEventHandlers.js file for any close-related handlers
cat -n src/renderer/actions/initEventHandlers.js | grep -i "close\|quit"
echo "---"
# Also check if there are any other files that might handle this
rg -r "initiate-app-close|initiate.*close" src/renderer/

Repository: requestly/requestly-desktop-app

Length of output: 78


🏁 Script executed:

#!/bin/bash
# Get more context around the close handler and quit-app handler
sed -n '275,290p' src/main/main.ts
echo "---"
sed -n '475,495p' src/main/main.ts

Repository: requestly/requestly-desktop-app

Length of output: 1045


Missing renderer-side handler for initiate-app-close creates unrecoverable window lock

The close/quit coordination pattern requires the renderer to listen for initiate-app-close and respond with ipcRenderer.invoke("quit-app"), but no such handler exists in the renderer code. When a user attempts to close the window, the main process prevents the close and sends initiate-app-close to a listener that doesn't exist, leaving the window permanently stuck and unable to close. Add the corresponding IPC handler in the renderer to complete this pattern.

🤖 Prompt for AI Agents
In src/main/main.ts around lines 183-184, the main process sends
'initiate-app-close' but there is no renderer-side listener, which causes the
window to get stuck; add a renderer-side IPC listener (in your preload script if
contextIsolation is enabled, or in the renderer entry file otherwise) that
listens for 'initiate-app-close' and calls ipcRenderer.invoke('quit-app') to
continue the close flow; if using preload/contextBridge, expose a small API or
directly register ipcRenderer.on('initiate-app-close', () =>
ipcRenderer.invoke('quit-app')) so the renderer responds and allows the main
process to proceed.

Comment thread src/main/main.ts
@nsrCodes nsrCodes merged commit f1f29c4 into master Dec 2, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants