Repository navigation
Correct XDG_CURRENT_DESKTOP env var - #1754
Conversation
|
Warning Rate limit exceeded@esimkowitz has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 9 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughThe pull request introduces a new function In Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
emain/emain.ts (1)
125-135: Consider adding error handling for environment variable restoration.The implementation correctly manages the desktop environment during external URL opening. However, consider using try-finally to ensure environment restoration even if an error occurs.
fireAndForget(async () => { const curXdgCurrentDesktop = process.env.XDG_CURRENT_DESKTOP; if (curXdgCurrentDesktop) { process.env.XDG_CURRENT_DESKTOP = getXdgCurrentDesktop(); } - await electron.shell.openExternal(url).catch((err) => { - console.error(`Failed to open URL ${url}:`, err); - }); - if (curXdgCurrentDesktop) { - process.env.XDG_CURRENT_DESKTOP = curXdgCurrentDesktop; - } + try { + await electron.shell.openExternal(url); + } catch (err) { + console.error(`Failed to open URL ${url}:`, err); + } finally { + if (curXdgCurrentDesktop) { + process.env.XDG_CURRENT_DESKTOP = curXdgCurrentDesktop; + } + } });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
emain/emain-wavesrv.ts(2 hunks)emain/emain.ts(3 hunks)emain/platform.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
- GitHub Check: Build for TestDriver.ai
🔇 Additional comments (4)
emain/emain-wavesrv.ts (1)
57-60: LGTM! Environment properly configured for wavesrv.The implementation correctly preserves the desktop environment context when launching wavesrv.
emain/emain.ts (1)
359-370: Apply the same error handling improvement as suggested for open-external.The implementation correctly manages the desktop environment during native path opening.
emain/platform.ts (2)
212-212: LGTM!The export is correctly positioned and follows the module's export pattern.
197-203: Verify integration with dependent modules.Since this function is used by
emain-wavesrv.tsandemain.tsfor managingXDG_CURRENT_DESKTOP, let's verify the integration points:✅ Verification successful
Integration verified successfully
The function is properly exported and correctly used across the codebase. The state management in
emain.tsfollows a consistent pattern of saving, modifying, and restoring the desktop environment value.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check how getXdgCurrentDesktop is used in the codebase # Find files importing getXdgCurrentDesktop rg "import.*getXdgCurrentDesktop.*from.*platform" -A 5 # Find usage of XDG_CURRENT_DESKTOP in the codebase rg "XDG_CURRENT_DESKTOP" -A 5Length of output: 2484
Script:
#!/bin/bash # Check if getXdgCurrentDesktop is exported from platform.ts cat emain/platform.ts | grep -A 10 "export {"Length of output: 268
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
emain/platform.ts (1)
203-211:⚠️ Potential issueFix the return type of
getXdgCurrentDesktop.The function
getXdgCurrentDesktopmay returnundefined, but its return type is declared asstring. To accurately reflect the possible return values, the return type should bestring | undefined.Apply this diff to correct the return type:
-function getXdgCurrentDesktop(): string { +function getXdgCurrentDesktop(): string | undefined {
🧹 Nitpick comments (1)
emain/platform.ts (1)
217-227: Refactor to eliminate code duplication between synchronous and asynchronous functions.The functions
callWithOriginalXdgCurrentDesktopandcallWithOriginalXdgCurrentDesktopAsyncshare similar logic. Consider refactoring them to reduce duplication and improve maintainability.One possible approach is to create a higher-order function that handles both sync and async callbacks:
function withOriginalXdgCurrentDesktop<T>(callback: () => T): T { const currXdgCurrentDesktopDefined = 'XDG_CURRENT_DESKTOP' in process.env; const currXdgCurrentDesktop = process.env.XDG_CURRENT_DESKTOP; const originalXdgCurrentDesktop = getXdgCurrentDesktop(); process.env.XDG_CURRENT_DESKTOP = originalXdgCurrentDesktop; try { return callback(); } finally { if (currXdgCurrentDesktopDefined) { process.env.XDG_CURRENT_DESKTOP = currXdgCurrentDesktop; } else { delete process.env.XDG_CURRENT_DESKTOP; } } }You can then use this function for both synchronous and asynchronous callbacks:
// For synchronous callbacks withOriginalXdgCurrentDesktop(() => { // Your sync code here }); // For asynchronous callbacks await withOriginalXdgCurrentDesktop(async () => { // Your async code here });Also applies to: 233-243
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
emain/emain.ts(3 hunks)emain/platform.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- emain/emain.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Build for TestDriver.ai
- GitHub Check: Analyze (go)
Electron sets XDG_CURRENT_DESKTOP for better Chromium compatibility on Linux. We need to unset this for `wavesrv` and for any calls to open a file or URL externally in `emain`. See https://www.electronjs.org/docs/latest/api/environment-variables#original_xdg_current_desktop There's a bug open in Electron related to this: electron/electron#45129 closes wavetermdev#1733
Electron sets XDG_CURRENT_DESKTOP for better Chromium compatibility on Linux. We need to unset this for
wavesrvand for any calls to open a file or URL externally inemain.See https://www.electronjs.org/docs/latest/api/environment-variables#original_xdg_current_desktop
There's a bug open in Electron related to this: electron/electron#45129
closes #1733