Skip to content

Conversation

samruddhi-Rahegaonkar
Copy link
Member

@samruddhi-Rahegaonkar samruddhi-Rahegaonkar commented Aug 27, 2025

Fixes #1242

Changes

Screenshots / Recordings

Checklist:

  • No hard coding: I have used resources from constants.dart without hard coding any value.
  • No end of file edits: No modifications done at end of resource files.
  • Code reformatting: I have reformatted code and fixed indentation in every file included in this pull request.
  • Code analyzation: My code passes analyzations run in flutter analyze and tests run in flutter test.

Summary by Sourcery

Enable next-generation streaming profile alongside legacy transfer by introducing a new streaming mode throughout the BLE pipeline, updating the UI and data manager to support streaming, and expanding CI to build on macOS, Windows, and Debian.

New Features:

  • Add TransferMode enum and implement a streaming data transfer path in DataTransferManager, WriteState, ScanState, and ConnectState
  • Add a dedicated “Stream” button in the home screen and a new handleStreamingTransfer method in AnimationBadgeProvider
  • Extend GitHub Actions to include macOS, Windows, and Debian build workflows

Enhancements:

  • Refactor WriteState into separate _handleLegacyMode and _handleStreamingMode branches with automatic fallback to legacy
  • Enhance ScanState to detect streaming services first, switch modes dynamically, and streamline scan completion
  • Unify BLE state transitions and improve error handling in ConnectState and CompletedState

CI:

  • Add composite GitHub Actions and jobs for macOS, Windows, and Debian Flutter builds

Copy link
Contributor

sourcery-ai bot commented Aug 27, 2025

Reviewer's Guide

Introduces next-gen streaming profile alongside legacy BLE transfer by refactoring write and scan states, extending the data manager and providers for streaming mode, updating UI to offer separate transfer buttons, unifying the BLE state machine, and expanding CI workflows for macOS, Windows, and Debian builds.

Sequence diagram for streaming BLE transfer process

sequenceDiagram
    actor User
    participant HomeScreen
    participant AnimationBadgeProvider
    participant BadgeMessageProvider
    participant DataTransferManager
    participant BLEStateMachine
    participant BLEDevice
    User->>HomeScreen: Clicks 'Stream' button
    HomeScreen->>AnimationBadgeProvider: handleStreamingTransfer(...)
    AnimationBadgeProvider->>BadgeMessageProvider: checkAndTransfer(..., useStreaming=true)
    BadgeMessageProvider->>DataTransferManager: DataTransferManager.forStreaming(...)
    BadgeMessageProvider->>BLEStateMachine: Start BLE state machine (ScanState)
    BLEStateMachine->>BLEDevice: Scan for streaming service
    BLEStateMachine->>BLEDevice: Connect
    BLEStateMachine->>BLEDevice: Discover streaming service/characteristics
    BLEStateMachine->>DataTransferManager: enterStreamingMode()
    DataTransferManager->>BLEDevice: Write enter streaming command
    BLEStateMachine->>User: Show transfer completion feedback
Loading

Class diagram for DataTransferManager and BLE state changes

classDiagram
    class DataTransferManager {
      +Data? data
      +TransferMode mode
      +BluetoothDevice? connectedDevice
      +BluetoothCharacteristic? legacyWriteCharacteristic
      +BluetoothCharacteristic? streamingWriteCharacteristic
      +BluetoothCharacteristic? streamingNotifyCharacteristic
      +StreamSubscription<List<int>>? notificationSubscription
      +bool isStreamingActive
      +generateDataChunk()
      +clearConnectedDevice()
      +handleStreamingErrorCode(int)
      +streamBitmap(List<int>)
      +enterStreamingMode()
      +exitStreamingMode()
      +convertBitmapToColumns(List<List<bool>>)
      <<factory>> forLegacy(Data)
      <<factory>> forStreaming(Data)
    }
    class TransferMode {
      <<enum>>
      legacy
      streaming
    }
    DataTransferManager --> TransferMode
    class ScanState {
      +processState()
      +_deviceSupportsRequiredMode(ScanResult, TransferMode)
      +_getServicesForMode(TransferMode)
    }
    class WriteState {
      +processState()
      +_handleLegacyMode(List<BluetoothService>)
      +_handleStreamingMode(List<BluetoothService>)
      +_findStreamingService(List<BluetoothService>)
      +_setupStreamingService(BluetoothService)
    }
    class CompletedState {
      +bool isSuccess
      +String message
      +TransferMode? mode
      +bool shouldDisconnect
      +processState()
    }
    WriteState --> DataTransferManager
    ScanState --> DataTransferManager
    CompletedState --> TransferMode
Loading

File-Level Changes

Change Details Files
Refactored WriteState to support both legacy and streaming modes
  • Split processState into _handleLegacyMode and _handleStreamingMode
  • Branch on TransferMode and implement streaming service discovery
  • Set up notification subscription and enter streaming mode with dedicated characteristics
lib/bademagic_module/bluetooth/write_state.dart
Enhanced DataTransferManager with streaming capabilities
  • Added TransferMode enum, mode property, and factory constructors
  • Introduced streaming write/notify characteristics and notification cleanup
  • Implemented enter/exit streaming mode, streamBitmap, and bitmap‐to‐columns conversion
lib/bademagic_module/bluetooth/datagenerator.dart
Updated ScanState for mode-specific device discovery
  • Show different toasts and scan filters based on TransferMode
  • Added _getServicesForMode and _deviceSupportsRequiredMode helpers
  • Automatically fallback from streaming to legacy if next-gen service is absent
lib/bademagic_module/bluetooth/scan_state.dart
Unified transfer pipeline in providers and added streaming handler
  • Extended BadgeMessageProvider.checkAndTransfer with useStreaming flag
  • Choose DataTransferManager.forStreaming or .forLegacy and run unified state loop
  • Added AnimationBadgeProvider.handleStreamingTransfer to kick off streaming transfers
lib/providers/badge_message_provider.dart
lib/providers/animation_badge_provider.dart
Added distinct UI controls for streaming and legacy transfers
  • Inserted separate Stream button next to legacy transfer
  • Adjusted spacing and container decorations for consistency
  • Removed outdated comments around save dialog logic
lib/view/homescreen.dart
Unified BLE state flow with mode-aware connect and completion
  • Simplified ConnectState to log and return WriteState or CompletedState on failure
  • Extended CompletedState to include mode and shouldDisconnect flags
  • Ensure disconnect only for legacy and keep connection for streaming
lib/bademagic_module/bluetooth/connect_state.dart
lib/bademagic_module/bluetooth/completed_state.dart
Expanded GitHub Actions workflows for desktop platforms
  • Added macOS, Windows, and Debian jobs to pull_request.yml
  • Created composite actions under .github/actions for each platform
  • Configured Flutter setup and build steps per OS
.github/workflows/pull_request.yml
.github/actions/macos/action.yml
.github/actions/windows/action.yml
.github/actions/debian/action.yml

Assessment against linked issues

Issue Objective Addressed Explanation
#1242 Allow users to update the badge message without needing to press the Bluetooth button for transfer.
#1242 Implement periodic polling or a streaming transfer mode so the badge can receive updates automatically (e.g., every 30 seconds or continuously).

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

github-actions bot commented Aug 27, 2025

Build Status

Build successful. APKs to test: https://github.com/fossasia/badgemagic-app/actions/runs/17292146246/artifacts/3872000334.

Screenshots

Android Screenshots
iPhone Screenshots
iPad Screenshots

@samruddhi-Rahegaonkar samruddhi-Rahegaonkar marked this pull request as ready for review August 28, 2025 09:32
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @samruddhi-Rahegaonkar, you have reached your weekly rate limit for Sourcery. Please try again later

@samruddhi-Rahegaonkar
Copy link
Member Author

samruddhi-Rahegaonkar commented Aug 28, 2025

@mariobehling @hpdang @Jhalakupadhyay according to the next gen profile of the firmware i have added the streaming function to the app for the live stream it should work correctly on the firmware which supports next gen profile.
I cannot test it because i guess firmware doesn't support it.

@hpdang
Copy link
Member

hpdang commented Aug 28, 2025

@nope3472 please review this

@hpdang hpdang requested a review from nope3472 August 28, 2025 14:42
Copy link
Member

@mariobehling mariobehling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

Please make the following changes:

  1. This feature should only be visible for badges that support this feature. In the config section add the option "Enable/Disable Streaming Option"
  2. Pre-requisite for this feature is to add "config options" as outlined here #1205 (comment)

Testing:
This feature should be tested and demonstrated with an actual badge.

@samruddhi-Rahegaonkar
Copy link
Member Author

Thank you.

Please make the following changes:

  1. This feature should only be visible for badges that support this feature. In the config section add the option "Enable/Disable Streaming Option"
  2. Pre-requisite for this feature is to add "config options" as outlined here #1205 (comment)

Testing: This feature should be tested and demonstrated with an actual badge.

Okay!

@samruddhi-Rahegaonkar
Copy link
Member Author

@hpdang @mariobehling the failing screenshots are because of additional config screen in the navbar.
following are the changed UI. and the flow

Streaming Mode – Simple Flow :

  • Turn On Streaming Mode
  • In Badge Configuration, there’s a switch called “Streaming Mode (Bluetooth Always On)”.
  • Flip the switch ON to start.
  • The app will search for your badge automatically.
  • Connecting to Your Badge
  • The app tries to find your badge via Bluetooth.
  • When it finds it, it connects automatically.
  • Once connected, the switch stays ON, and you can send messages live.
  • Type Your Message: Just type your message in the text field.
  • The text will immediately appear on your badge.
  • You don’t need to press “Transfer” anymore.
  • Special Effects : If you added effects like Flash, Invert LEDs, or Marquee, they will also appear on the badge automatically.
  • Stop Streaming : Flip the switch OFF to stop streaming.
  • This disconnects the badge safely.
  • Manual Transfer (Optional) : If Streaming Mode is OFF, you can still type your message and press Transfer to send it manually.
  • While streaming is ON, the manual Transfer button is disabled.

@samruddhi-Rahegaonkar
Copy link
Member Author

Screenshot_20250830_100435 Screenshot_20250830_100709

Copy link
Member

@mariobehling mariobehling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please test this with the hardware and document this in a video here.

@mariobehling
Copy link
Member

mariobehling commented Sep 1, 2025

Screenshots are failing. Please check and fix it.

@mariobehling
Copy link
Member

Thank you, please document this feature with a video showcasing that it works with a badge.

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.

Live Badge/Demo Mode - Use periodic transfer to allow users to interact with the badge
3 participants