Skip to content

fix(linux): resolve single-instance locking on AppImage, gate updater, and improve window control - #12

Merged
itsbkm merged 5 commits into
FreeOpenSourcePOS:mainfrom
khaira777:main
Jun 27, 2026
Merged

itsbkm merged 5 commits into
FreeOpenSourcePOS:mainfrom
khaira777:main

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

Description

This PR addresses several critical platform-specific issues to stabilize the Linux build (AppImage and Debian package variants) of Flo Cafe, which was previously only optimized for macOS and Windows.

Key Enhancements & Fixes

  1. AppImage Single-Instance Locking (Resolved)

    • The Issue: The default Electron app.requestSingleInstanceLock() checks process executable paths inside the mount points (e.g., /tmp/.mount_FloXXXXXX/), causing it to consider previous locks stale and launch duplicate windows.
    • The Fix: Implemented a custom PID-based file lock at ~/.config/flo-desktop/singleton.lock using /proc/<pid> process checks.
    • Persistent Paths: Explicitly set the userData directory to ~/.config/flo-desktop early in the main process lifecycle to prevent path resolution discrepancies between AppImage mount iterations.
  2. Improved Process Resource Control

    • Capped the port scanning loops in server.ts and kds-server.ts to a maximum of 10 attempts (terminating at 3010/3011).
    • Enforced immediate process.exit() on initialization failure and lock detection to prevent CPU/memory-hogging zombie background processes from accumulating.
  3. Window Close & Tray Integration

    • Configured the close handler on Linux to minimize the window to the taskbar/dock instead of hiding it. This keeps the app recoverable in environments where GNOME extensions or tiling window managers do not support status icons.
    • Silently gated the auto-updater to avoid startup crash logs on unsupported platforms.
    • Wrapped Windows-specific Next.js path rewriting middleware to only execute on win32 hosts.
  4. Linux Documentation

    • Added docs/linux.md mapping package options (AppImage vs deb), FUSE dependencies (Ubuntu libfuse2/libfuse2t64), CUPS printer setup, and current limitations.

Known Issues / Future Work (Captured in TODOs)

  • Tray "Quit" Handler: Investigate why right-clicking the system tray icon and selecting "Quit" fails to trigger clean exits in some Linux window managers.
  • Debian Store Metadata: Create AppStream .metainfo.xml files to resolve "unknown license / potentially unsafe" warnings in graphical software centers (Gnome Software / Discover).
  • Thermal Printers Make/Model: Integrate lpoptions or lsusb to enrich make/model detection on Linux.

@khaira777
khaira777 requested a review from itsbkm June 27, 2026 10:26
@itsbkm
itsbkm merged commit 9e9167d into FreeOpenSourcePOS:main Jun 27, 2026
khaira777 added a commit that referenced this pull request Jul 5, 2026
…ts/discounts/tax/loyalty)

Integration tests (7 files, 123 assertions):
- Happy path: order→discount→bill→payment→completed
- Tax correctness: India GST calculation and recalculation
- Payment integrity: split payments, wallet double-spend, zero-amount rejection
- Order lifecycle: status transitions, cancel with PIN
- Bill reconciliation: discount sync, add-items sync
- Loyalty points: cashback, idempotency, wallet balance
- Discount edge cases: combined discounts, max limits, addon prices

Bug fixes:
- #3: Add-items filters cancelled items from total recalculation
- #4: Add-items syncs bill after updating order total
- #5: Cancel/restore round-off formula corrected
- #6: Discount endpoint wrapped in withTxn (race condition)
- #7: Infinity passes validation (NaN/isFinite check)
- #8: Missing amount defaults to remaining balance
- #9: Amount capped at remaining balance
- #11: Removing discount restores original tax
- #12: Add-items preserves order-level discount
- #13: Cancel/restore preserves order-level discount
- #14: Item-level discount checks max settings
- #15: Item-level discount syncs to bill
- #17: Cancel/restore wrapped in withTxn
- #20: Cashback calculated on discounted subtotal
- #23: Quantity/price validation on order creation

Shared test helper (tests/helpers/test-setup.ts):
- Extracts 40 lines of boilerplate per test file
- Provides: initTestDb, createApp, startServer, seed helpers, assert utilities

Co-Authored-By: Claude <[email protected]>
khaira777 pushed a commit that referenced this pull request Jul 6, 2026
fix(linux): resolve single-instance locking on AppImage, gate updater, and improve window control
richanonymous22 referenced this pull request in richanonymous22/FloCafe Aug 13, 2026
Milestone 2, Part 1+2. Finishes the work Phase 2A flagged as its natural next
step: POST /orders/:id/items now goes through SaleService, and the per-item
loop that used to be duplicated between order creation and item addition is
one implementation with two callers.

## Shared line engine

createSale and addSaleItems used to carry two near-identical copies of the
per-item loop: product lookup, stock guard, price/quantity validation, addon
subtotal, tax calculation, insert, addon insert, stock decrement. Both now
call the internal persistSaleLine() for that work. What still differs between
them is aggregation, and that difference is preserved deliberately:
createSale sums per-line results as it goes (nothing else exists on a brand
new sale); addSaleItems re-derives totals from every ACTIVE line in the
database afterwards, because it may be adding to a sale that already has
items, some of which may be cancelled — the inherited "BUG #3 FIX".

One direct benefit of consolidation: items added via addSaleItems now receive
a ULID uid, same as items from createSale. The old add-items route never
populated it — an artifact of Phase 2A only having migrated one of the two
paths.

## addSaleItems

Behaviour-preserving extraction of the second half of
docs/PHASE_2A_SALE_FLOW.md. All four inherited "BUG #N FIX" comments in the
original handler are preserved and each has an explicit test: cancelled-line
exclusion from recalculated totals (#3), order-level discount rescaling when
a percentage discount meets a changed subtotal (#12), re-fetching the order
under the transaction lock to catch a concurrent completion/cancellation
(#175), and re-syncing an existing unpaid bill so it doesn't go stale (#4).

Two guard clauses stay in the route rather than moving into the service, and
the reasoning is written down at both ends (the route handler and the
addSaleItems docstring): the bills.split_group_id lock is a simple,
self-contained check with nothing to share, and the waiter-ownership check is
an HTTP-layer authorization decision tied to the caller's role — it belongs
beside requireRole, not inside a service with no Express dependency. Both run
in the same relative order as before, so no response code changes for any
input. actorUserId is threaded through for audit attribution only; it plays
no part in either check.

One new audit event type, sale.items_added, recorded inside the same
transaction as the items it describes — added to the AuditEventType union
introduced in Phase 1.

## Verification

Extended tests/plemmo-sale-service.test.ts with 45 new checks (84 -> 129):
shared-engine wiring (uid on newly added lines, stock decrement for
post-creation additions), every rejection path with its exact status,
rollback (a failure on line 2 of an add leaves no line, no audit event, and
an unchanged subtotal), the four BUG-fix behaviours above with dedicated
assertions, idempotent replay, the specialInstructions presence-vs-absence
distinction (needed a typed { value } wrapper since `undefined` alone can't
tell "leave untouched" apart from "clear the notes"), and a tableless counter
sale proving the retail shape works for a multi-call flow, not just creation.

Targeted regression: integration-happy, integration-tax,
integration-reconciliation, integration-discount, issue-122 (exercises
POST /orders/:id/items addon-quantity validation directly, exact 400s),
issue-125, issue-24, order-item-addons, orders-authz, authz-phase3,
tax-pack-management — all pass unchanged.

Full npm test suite green (exit 0, 42 suites reporting 0 failed, zero
assertion errors). Build clean, lint 0 errors.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011HjBK8R8ArAjzGRLS7gjUj
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