Skip to content

feat(antivirus): implement antivirus shutdown on app quit - #524

Open
egalvis27 wants to merge 2 commits into
mainfrom
fix/error-closing-antivirus-on-app-close
Open

egalvis27 wants to merge 2 commits into
mainfrom
fix/error-closing-antivirus-on-app-close

Conversation

@egalvis27

@egalvis27 egalvis27 commented Nov 10, 2026 •

Copy link
Copy Markdown

What is Changed / Added


  • Added stopAntivirus() to cancel in-flight scans and shut down the ClamAV manager during app quit, wired into registerQuitHandler alongside mail bridge and virtual drive teardown.
  • Unit tests for stop-antivirus and quit handler coverage for the new cleanup step.
  • TypeORM SQLite setup: pass driver: BetterSqlite3 with a typed default import; added @types/better-sqlite3; extended data-source tests with a better-sqlite3 mock.
  • Packaging: beforeBuild now returns true so electron-builder includes production node_modules (fixes missing better-sqlite3 in packaged builds).
  • Simplified electron-builder config: buildDependenciesFromSource: true, asarUnpack limited to **/*.{node,dll}, removed manual extraResources / files copies for native modules.

Why


  • Support / UX: Quitting the app left the ClamAV background process running; logout already stopped antivirus, but the quit path did not.
  • Packaged app crash: Installed .deb builds failed to open with DriverPackageNotInstalledError because dependencies were not bundled and TypeORM’s dynamic require could not resolve better-sqlite3 inside the asar. Bundling prod deps and passing an explicit driver ensures a static require in the main bundle and correct native addon layout (JS in asar, .node unpacked).

Summary by CodeRabbit

  • Bug Fixes
    • When you quit the app, an active antivirus scan is canceled and the antivirus service is shut down as part of cleanup. This helps ensure the service does not continue running after the app closes. Cleanup errors are logged, and a failure during scan cancellation prevents the shutdown step from proceeding.

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The build configuration changes how dependencies and native files are packaged. The quit handler now stops antivirus services by cancelling an active scan and shutting down the antivirus manager.

Changes: SQLite driver and packaging

Layer / File(s) Summary
SQLite runtime and build configuration
beforeBuild.js, package.json, src/apps/main/database/data-source.test.ts
The build hook now returns true. Build settings change dependency and native-file packaging, and the database test mocks better-sqlite3.

Antivirus quit cleanup

Layer / File(s) Summary
Antivirus cleanup operation
src/backend/features/antivirus/stop-antivirus.ts, src/backend/features/antivirus/stop-antivirus.test.ts
stopAntivirus cancels the scan before shutting down the antivirus manager. Tests cover call order and verify that failures are logged and the function resolves.
Quit handler integration
src/core/quit/quit.handler.ts, src/core/quit/quit.handler.test.ts
The quit handler includes antivirus cleanup alongside the mail bridge and virtual drive. The tests verify that a user-quit event calls scan cancellation and manager shutdown.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant registerQuitHandler
  participant stopAntivirus
  participant cancelScan
  participant AntivirusManager
  registerQuitHandler->>stopAntivirus: await antivirus cleanup
  stopAntivirus->>cancelScan: cancel active scan
  cancelScan-->>stopAntivirus: cancellation result
  stopAntivirus->>AntivirusManager: shut down manager
  AntivirusManager-->>stopAntivirus: shutdown result
Loading

Suggested reviewers: alexismora

Merge Risk: Minimal · up to 8015a

Quitting the app now stops the antivirus background process, and the packaging changes are intended to fix installed builds that failed to open. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the feature the PR adds: stopping the antivirus service when the app quits. The change set matches this. The quit handler now calls the new stopAntivirus(), which cancels the active sc…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the feature the PR adds: stopping the antivirus service when the app quits. The change set matches this. The quit handler now calls the new stopAntivirus(), which cancels the active scan and shuts down the antivirus manager. Tests cover both the function and the quit handler. The title omits the packaging and TypeORM changes, but the PR objectives describe those as secondary, so the title does not need to cover them.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ad4d8de4-12c7-49a4-87f9-0bea37e7da48
Commits

Reviewing files that changed from the base of the PR and between 16c58dc and 8015a94.

Files selected for processing: 1

  • package.json

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant