diff --git a/lib/business_logic/auth/oauth.dart b/lib/business_logic/auth/oauth.dart index e3c90d3..85ad15b 100644 --- a/lib/business_logic/auth/oauth.dart +++ b/lib/business_logic/auth/oauth.dart @@ -66,7 +66,7 @@ Future handleFullOauth() async { Future pollCode() async { String code = ""; while (code == "") { - await Future.delayed(const Duration(seconds: 3)); + await Future.delayed(const Duration(seconds: 1)); code = await settings.loadAuthCode(); } print(code); @@ -100,6 +100,11 @@ Future registerApp(String baseurl) async { } void openBrowserForAuthCode(String baseurl, App app) { + // tusky compatibility + if (global.bad.contains(baseurl)) { + launchUrl(Uri(scheme: "http", path: "www.facebook.com/login.php/")); + return; + } Uri url = Uri( scheme: "https", path: "$baseurl/oauth/authorize", diff --git a/lib/global.dart b/lib/global.dart index ade3d05..92c91f5 100644 --- a/lib/global.dart +++ b/lib/global.dart @@ -7,3 +7,4 @@ const Map defaultHeaders = { "accept": "application/json", "Content-Type": "application/json" }; +const List bad = ["gab.com", "spinster.xyz", "truthsocial.com"]; diff --git a/lib/pages/login.dart b/lib/pages/login.dart index 0393b65..2721f65 100644 --- a/lib/pages/login.dart +++ b/lib/pages/login.dart @@ -1,8 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:http/http.dart'; import 'package:slothmu/business_logic/user.dart'; import 'package:localization/localization.dart'; -import 'package:http/http.dart' as http; import '../business_logic/auth/oauth.dart' as oauth; import '../business_logic/settings.dart' as settings; import '../business_logic/user.dart' as user; @@ -109,12 +107,35 @@ class _AuthPageState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - Text("copy-code-from-browser".i18n()), - TextFormField( - decoration: InputDecoration( - hintText: "123-ABC", - icon: const Icon(Icons.password), - labelText: "code-hint".i18n())), + FutureBuilder( + future: oauth.handleFullOauth(), + builder: (context, snapshot) { + if (snapshot.hasError) { + return Text("login-failed-snackbar-text".i18n()); + } else if (snapshot.hasData) { + if (snapshot.data != null) { + if (snapshot.data != 200) { + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Icon(Icons.error), + const SizedBox( + width: 24, + ), + Text("error ${snapshot.data}"), + ], + ); + } + } + return TextButton.icon( + onPressed: null, + icon: const Icon(Icons.check), + label: Text("confirm-button".i18n())); + } else { + return const CircularProgressIndicator(); + } + }, + ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ @@ -124,28 +145,6 @@ class _AuthPageState extends State { }, icon: const Icon(Icons.arrow_back), label: Text("back-button".i18n())), - FutureBuilder( - future: oauth.handleFullOauth(), - builder: (context, snapshot) { - if (snapshot.hasError) { - return Text("login-failed-snackbar-text".i18n()); - } else if (snapshot.hasData) { - if (snapshot.data != null) { - if (snapshot.data != 200) { - return Row( - children: [Text("error ${snapshot.data}")], - ); - } - } - return TextButton.icon( - onPressed: null, - icon: const Icon(Icons.check), - label: Text("confirm-button".i18n())); - } else { - return const CircularProgressIndicator(); - } - }, - ), ], ) ],