Stop asking for mod scopes at normal login so existing core-only tokens never hit a missing-permissions dialog. Gate moderated-channels Helix, offer an Enable flow for mods/broadcasters, and upgrade atomically. Co-authored-by: Cursor <cursoragent@cursor.com>
79 lines
2.7 KiB
Dart
79 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:frosty/main.dart';
|
|
import 'package:frosty/screens/settings/stores/auth_store.dart';
|
|
import 'package:frosty/widgets/frosty_app_bar.dart';
|
|
import 'package:frosty/widgets/frosty_dialog.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:webview_flutter/webview_flutter.dart';
|
|
|
|
/// Pushes the atomic moderator-scopes upgrade WebView.
|
|
void openEnableModeratorTools(AuthStore authStore, {BuildContext? context}) {
|
|
final navContext = context ?? navigatorKey.currentContext;
|
|
if (navContext == null) return;
|
|
Navigator.of(navContext).push(
|
|
MaterialPageRoute(
|
|
builder: (context) => Provider<AuthStore>.value(
|
|
value: authStore,
|
|
child: const LoginWebView(upgradeModeratorScopes: true),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Reusable WebView widget for Twitch OAuth login flow
|
|
class LoginWebView extends StatelessWidget {
|
|
/// Optional widget to navigate to after successful login
|
|
final Widget? routeAfter;
|
|
|
|
/// When true, requests core + moderator scopes and runs the atomic upgrade
|
|
/// commit instead of a full [AuthStore.login].
|
|
final bool upgradeModeratorScopes;
|
|
|
|
const LoginWebView({
|
|
super.key,
|
|
this.routeAfter,
|
|
this.upgradeModeratorScopes = false,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final authStore = context.read<AuthStore>();
|
|
|
|
return Scaffold(
|
|
appBar: FrostyAppBar(
|
|
title: Text(
|
|
upgradeModeratorScopes
|
|
? 'Enable moderator tools'
|
|
: 'Connect with Twitch',
|
|
),
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.help_rounded),
|
|
onPressed: () => showDialog(
|
|
context: context,
|
|
builder: (context) {
|
|
return FrostyDialog(
|
|
title: 'Workaround for the Twitch cookie banner',
|
|
message:
|
|
'If the Twitch cookie banner is still blocking the login, try clicking one of the links in the cookie policy description and navigating until you reach the Twitch home page. From there, you can try logging in on the top right profile icon. Once logged in, go back to the first step of the onboarding and then try again.',
|
|
actions: [
|
|
TextButton(
|
|
onPressed: Navigator.of(context).pop,
|
|
child: const Text('Close'),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
body: WebViewWidget(
|
|
controller: authStore.createAuthWebViewController(
|
|
routeAfter: routeAfter,
|
|
upgradeModeratorScopes: upgradeModeratorScopes,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|