-
Notifications
You must be signed in to change notification settings - Fork 121
[Woo POS] [Barcodes] Play error sound when a barcode scan fails #15746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Woo POS] [Barcodes] Play error sound when a barcode scan fails #15746
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a failure sound cue when barcode scans fail in the POS system and updates tests and project configuration accordingly.
- Introduces
PointOfSaleSoundPlayerandPointOfSaleSoundfor playing.mp3assets. - Injects a
soundPlayerintoPointOfSaleAggregateModeland triggers playback on scan errors. - Adds a mock sound player and a new async test to verify failure sound behavior.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Classes/POS/Models/PointOfSaleAggregateModel.swift | Inject soundPlayer and call playSound(.barcodeScanFailure) on barcode scan errors |
| Classes/POS/Utils/Audio/PointOfSaleSoundPlayer.swift | Implement AVAudio-based sound playback and define the PointOfSaleSound type |
| Tests/POS/Mocks/MockPointOfSaleSoundPlayer.swift | Add a mock conforming to PointOfSaleSoundPlayerProtocol |
| Tests/POS/Mocks/MockPointOfSaleBarcodeScanService.swift | Change mock to a class and allow throwing errors for test scenarios |
| Tests/POS/Models/PointOfSaleAggregateModelTests.swift | Inject the mock sound player into existing tests and add a new failure test |
| WooCommerce.xcodeproj/project.pbxproj | Register PointOfSaleSoundPlayer.swift, MockPointOfSaleSoundPlayer.swift, and pos_scan_failure.mp3 in build and resource targets |
Comments suppressed due to low confidence (3)
WooCommerce/WooCommerceTests/POS/Models/PointOfSaleAggregateModelTests.swift:1262
- You’ve added a test for failure playback. Consider also adding a counterpart test to verify that no sound is played when a barcode scan succeeds, ensuring both paths are covered.
struct BarcodeTests {
WooCommerce/Classes/POS/Utils/Audio/PointOfSaleSoundPlayer.swift:2
- The file uses
DDLogErrorbut doesn’t import the logging framework. Please add the appropriateimport CocoaLumberjack(or your chosen logger) at the top soDDLogErrorresolves correctly.
import AVFoundation
WooCommerce/WooCommerceTests/POS/Models/PointOfSaleAggregateModelTests.swift:28
- [nitpick] Most existing tests don’t verify sound behavior; since
soundPlayerhas a default parameter, you can omit injecting it in tests that don’t need to observe playback. This will reduce test boilerplate and maintenance.
soundPlayer: MockPointOfSaleSoundPlayer())
| DDLogError("Sound file not found: \(sound.name).\(sound.type)") | ||
| return | ||
| } | ||
| do { |
Copilot
AI
Jun 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider stopping or reusing the existing audioPlayer before creating a new instance to avoid overlapping or resource leakage when sounds are played in rapid succession.
| do { | |
| do { | |
| if let currentPlayer = audioPlayer { | |
| currentPlayer.stop() | |
| audioPlayer = nil | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried with this suggestion... but it doesn't really seem to make any difference to how it sounds with lots of rapid failures.
The leak comment is worth thinking about, but I don't really see how it would leak.
It probably doesn't hurt to add this, but I'll leave it up to you @staskus
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a little bit of optimization makes sense here, especially given that if an item is scanned once, it's likely to be scanned multiple times.
Plus, in an extreme case when we scan multiple wrong items in a row fast, it doesn't make sense to stop the previous sound and start another.
|
|
|
Version |
joshheald
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works well. You could integrate the copilot suggestion if you want.
I've added a credit to the licenses section for the sound.
| barcodeScanService: MockPointOfSaleBarcodeScanService(), | ||
| soundPlayer: MockPointOfSaleSoundPlayer()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping iOS16 support is so annoying with this...
| DDLogError("Sound file not found: \(sound.name).\(sound.type)") | ||
| return | ||
| } | ||
| do { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried with this suggestion... but it doesn't really seem to make any difference to how it sounds with lots of rapid failures.
The leak comment is worth thinking about, but I don't really see how it would leak.
It probably doesn't hurt to add this, but I'll leave it up to you @staskus
…-when-a-barcode-scan-fails
- Use a player cache to reuse a player between the plays - Don't restart the sound it the previous one plays - Use MainActor for safety when accessing player's cache
|
@staskus I noticed today that we noticably block the main thread when we play the sound, especially the very first time. Perhaps there's a way we can pre-load the sound on another thread to avoid that? Repro:
It's also noticable with a stop in the shimmer effect if you're not tapping items and just watching the screen. |
|
@joshheald thanks for reporting, I'll check |

Description
Added a functionality to play a sound when barcode scanning fails. Using the same sound as on Android:
.mp3into a projectSteps to reproduce
pointOfSaleBarcodeScanningi1Testing information
Tested on iPad Air M2 18.3 Device
Screenshots
ScreenRecording_06-13-2025.11-24-03_1.MP4
RELEASE-NOTES.txtif necessary.