import 'package:flutter/foundation.dart'; import 'social_connection.dart'; import 'social_settings.dart'; /// The one place that turns the sharing side of Tane on and off. /// /// Sharing is opt-in: until someone joins it, the app opens no connection at /// all and the seed book is entirely offline. Joining has to move three things /// at once — the stored choice, the live relay connection, and the flag the UI /// listens to — and doing that from several screens is how they drift apart. /// So every caller (the community-rules gate, the invite sheet, the sharing /// setup) goes through here instead. class SharingSwitch { SharingSwitch({ required SocialSettings settings, SocialConnection? connection, bool enabled = false, }) : _settings = settings, _connection = connection, on = ValueNotifier(enabled); final SocialSettings _settings; final SocialConnection? _connection; /// Whether sharing is on right now. Screens listen so the drawer's social /// entries light up the moment someone joins, with no restart. final ValueNotifier on; Future enable() async { await _settings.setSharingEnabled(true); // Safe to call even if it is already running: `start` guards itself. _connection?.start(); on.value = true; } /// Turning it off must actually go offline — closing the live session, not /// just recording the choice for the next launch. Future disable() async { await _settings.setSharingEnabled(false); await _connection?.stop(); on.value = false; } void dispose() => on.dispose(); }