Skip to content

Improve single-instance safety and browser process handling - #1

Open
geovanibruno wants to merge 1 commit into
saad-shaikh-256:mainfrom
geovanibruno:codex/security-and-process-handling
Open

Improve single-instance safety and browser process handling#1
geovanibruno wants to merge 1 commit into
saad-shaikh-256:mainfrom
geovanibruno:codex/security-and-process-handling

Conversation

@geovanibruno

Copy link
Copy Markdown

Summary

This pull request improves WinLock's process handling, single-instance
behavior, browser shutdown flow, and compatibility with virtual environments.

Motivation

Browsers commonly run several processes using the same executable name.
Treating each process as a separate protected application can cause duplicate
lock screens during the same monitoring cycle.

The previous single-instance implementation also searched for and terminated
Python processes based on their command line. In virtual environments, the
launcher and runtime may appear as separate Python processes, which can cause
WinLock to terminate its own active instance.

Finally, immediately killing every browser process can make browsers interpret
Cancel as an unexpected shutdown and display crash-recovery or troubleshooting
prompts on the next launch.

Changes

  • Replace command-line-based Python process termination with a named Windows
    mutex.
  • Deduplicate protected applications by executable name during each process
    scan.
  • Request a normal browser shutdown through WM_CLOSE before using a bounded
    forced-termination fallback.
  • Handle missing process names and expected psutil process-access errors
    explicitly.
  • Preserve the executable path correctly when registering auto-start,
    including virtual-environment installations.
  • Add unit tests for:
    • multi-process application deduplication;
    • case-insensitive executable names;
    • missing process names;
    • custom targets such as Zen Browser.
  • Document the test behavior and how to configure additional applications.

Compatibility

  • The default PIN remains 1234.
  • The default protected applications remain unchanged.
  • Zen Browser is documented and tested as an example of a custom target, but
    is not enabled by default.
  • No machine-specific paths or user-specific configuration are included.

Testing

python -m unittest discover -s tests -v

Result:

Ran 3 tests in 0.001s

OK

The tests use simulated process information and do not start or terminate real
browsers.

Licensing note

The repository currently does not include an explicit license. No license is
added in this pull request because that choice should be made by the original
copyright holder.

Replace command-line-based Python process termination with a native Windows mutex to prevent duplicate instances safely.

Deduplicate multi-process applications during each scan and request a graceful browser shutdown before using a bounded forced-termination fallback.

Harden auto-start path handling, add mocked process-scanning tests, and document custom targets such as Zen Browser.

Tests: python -m unittest discover -s tests -v
@geovanibruno
geovanibruno marked this pull request as ready for review August 15, 2026 23:46
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