fix a bug where posts wouldnt load right after logging in
This commit is contained in:
parent
43b5908488
commit
84d85d70e3
|
@ -124,6 +124,7 @@ void openBrowserForAuthCode(String baseurl, App app) {
|
|||
}
|
||||
|
||||
Future<int> refreshToken() async {
|
||||
print("refreshing_token");
|
||||
final activeId = global.settings!.activeIdentity;
|
||||
final authCode = global.settings!.identities[activeId]!.authCode;
|
||||
final appId = global.settings!.identities[activeId]!.clientId;
|
||||
|
|
|
@ -1 +1 @@
|
|||
import '../../global.dart' as global;
|
||||
|
||||
|
|
|
@ -22,39 +22,47 @@ class AccountSettings {
|
|||
AccountSettings settings = AccountSettings._create(identity);
|
||||
settings.prefs = await SharedPreferences.getInstance();
|
||||
settings.clientSecret =
|
||||
settings.prefs.getString(settings.identity + clientSecretKey) ?? "";
|
||||
settings.prefs.getString("${settings.identity}.$clientSecretKey") ?? "";
|
||||
settings.clientId =
|
||||
settings.prefs.getString(settings.identity + clientIdKey) ?? "";
|
||||
settings.prefs.getString("${settings.identity}.$clientIdKey") ?? "";
|
||||
settings.token =
|
||||
settings.prefs.getString(settings.identity + tokenKey) ?? "";
|
||||
settings.prefs.getString("${settings.identity}.$tokenKey") ?? "";
|
||||
settings.instanceUrl =
|
||||
settings.prefs.getString(settings.identity + instanceUrlKey) ??
|
||||
settings.prefs.getString("${settings.identity}.$instanceUrlKey") ??
|
||||
"example.com";
|
||||
settings.authCode =
|
||||
settings.prefs.getString(settings.identity + authCodeKey) ?? "";
|
||||
settings.prefs.getString("${settings.identity}.$authCodeKey") ?? "";
|
||||
return settings;
|
||||
}
|
||||
|
||||
Future<void> delete() async {
|
||||
prefs.remove("$identity.$instanceUrlKey");
|
||||
prefs.remove("$identity.$authCodeKey");
|
||||
prefs.remove("$identity.$clientSecretKey");
|
||||
prefs.remove("$identity.$clientIdKey");
|
||||
prefs.remove("$identity.$tokenKey");
|
||||
}
|
||||
|
||||
Future<bool> saveInstanceUrl(String url) async {
|
||||
instanceUrl = url;
|
||||
return await prefs.setString(identity + instanceUrlKey, url);
|
||||
return await prefs.setString("$identity.$instanceUrlKey", url);
|
||||
}
|
||||
|
||||
Future<bool> saveAuthCode(String code) async {
|
||||
authCode = code;
|
||||
return await prefs.setString(identity + authCodeKey, code);
|
||||
return await prefs.setString("$identity.$authCodeKey", code);
|
||||
}
|
||||
|
||||
Future<void> saveApp(oauth.App app) async {
|
||||
clientId = app.clientId;
|
||||
clientSecret = clientSecret;
|
||||
prefs.setString(identity + clientSecretKey, app.clientSecret);
|
||||
prefs.setString(identity + clientIdKey, app.clientId);
|
||||
clientSecret = app.clientSecret;
|
||||
prefs.setString("$identity.$clientSecretKey", app.clientSecret);
|
||||
prefs.setString("$identity.$clientIdKey", app.clientId);
|
||||
}
|
||||
|
||||
Future<bool> saveToken(String token) async {
|
||||
this.token = token;
|
||||
return await prefs.setString(identity + tokenKey, token);
|
||||
return await prefs.setString("$identity.$tokenKey", token);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,4 +124,13 @@ class Settings {
|
|||
batchSize = size;
|
||||
return await prefs.setInt(batchSizeKey, size);
|
||||
}
|
||||
|
||||
Future<bool> removeIdentity(String key) async {
|
||||
identities[key]!.delete();
|
||||
identities.remove(key);
|
||||
return prefs.setStringList(
|
||||
identitiesKey,
|
||||
identities.keys.toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,8 +99,8 @@ class ThreadModel {
|
|||
|
||||
Future<List<ThreadModel>> getTimelineFromServer(String? index) async {
|
||||
final activeId = global.settings!.activeIdentity;
|
||||
final limit = global.settings!.batchSize;
|
||||
final token = global.settings!.identities[activeId]!.token;
|
||||
final limit = global.settings?.batchSize;
|
||||
final token = global.settings?.identities[activeId]?.token;
|
||||
|
||||
Map<String, String> query = {"limit": limit.toString()};
|
||||
if (index != null) {
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
import 'package:web_socket_channel/status.dart' as status;
|
||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||
import '../global.dart' as global;
|
||||
|
||||
WebSocketChannel? channel;
|
||||
bool connected = false;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_phoenix/flutter_phoenix.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:localization/localization.dart';
|
||||
import 'package:loris/partials/main_scaffold.dart';
|
||||
|
@ -9,7 +10,6 @@ import 'themes/themes.dart' as themes;
|
|||
import 'global.dart' as global;
|
||||
import 'business_logic/auth/oauth.dart' as oauth;
|
||||
|
||||
String _initRoute = "/";
|
||||
ThemeData theme = themes.getTheme(themes.available[0]);
|
||||
Locale activeLocale = const Locale("en");
|
||||
|
||||
|
@ -19,9 +19,7 @@ void main() async {
|
|||
activeLocale = global.settings!.locale;
|
||||
|
||||
// check if all information is available
|
||||
if (global.settings!.identities.isEmpty) {
|
||||
_initRoute = "/login";
|
||||
} else {
|
||||
if (global.settings!.identities.isNotEmpty) {
|
||||
await oauth.refreshToken();
|
||||
}
|
||||
runApp(const Loris());
|
||||
|
@ -38,21 +36,23 @@ class _LorisState extends State<Loris> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
LocalJsonLocalization.delegate.directories = ['lib/i18n'];
|
||||
return MaterialApp(
|
||||
theme: theme,
|
||||
locale: activeLocale,
|
||||
supportedLocales: global.availableLocales,
|
||||
localizationsDelegates: [
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
LocalJsonLocalization.delegate,
|
||||
],
|
||||
initialRoute: _initRoute,
|
||||
routes: {
|
||||
'/': (context) => const MainScaffold(),
|
||||
'/login': (context) => const Login(),
|
||||
},
|
||||
return Phoenix(
|
||||
child: MaterialApp(
|
||||
theme: theme,
|
||||
locale: activeLocale,
|
||||
supportedLocales: global.availableLocales,
|
||||
localizationsDelegates: [
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
LocalJsonLocalization.delegate,
|
||||
],
|
||||
initialRoute: global.settings!.identities.isEmpty ? "/login" : "/",
|
||||
routes: {
|
||||
'/': (context) => const MainScaffold(),
|
||||
'/login': (context) => const Login(),
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
|||
import 'package:localization/localization.dart';
|
||||
import '../business_logic/auth/oauth.dart' as oauth;
|
||||
import '../global.dart' as global;
|
||||
import '../business_logic/settings.dart' as settings;
|
||||
|
||||
class Login extends StatefulWidget {
|
||||
const Login({Key? key}) : super(key: key);
|
||||
|
@ -49,7 +48,7 @@ class _LoginFormState extends State<LoginForm> {
|
|||
await global.settings!.addNewIdentity(identity);
|
||||
await global.settings!.saveActiveIdentity(identity);
|
||||
await global.settings!.identities[identity]!
|
||||
.saveInstanceUrl(identity);
|
||||
.saveInstanceUrl(value!);
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: "instance-url".i18n(),
|
||||
|
@ -60,9 +59,9 @@ class _LoginFormState extends State<LoginForm> {
|
|||
autofocus: true,
|
||||
),
|
||||
TextFormField(
|
||||
onChanged: (value) {
|
||||
onChanged: ((value) {
|
||||
identity = value;
|
||||
},
|
||||
}),
|
||||
),
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_phoenix/flutter_phoenix.dart';
|
||||
import 'package:localization/localization.dart';
|
||||
import '../../global.dart' as global;
|
||||
|
||||
|
@ -9,14 +10,23 @@ class AccountSettings extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<Widget> children = [];
|
||||
for (int i = 0; i < global.settings!.identities.length; i++) {
|
||||
children.add(
|
||||
LogoutButton(identity: global.settings!.identities.keys.toList()[i]));
|
||||
}
|
||||
return Row(
|
||||
children: const [LogoutButton()],
|
||||
children: children,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class LogoutButton extends StatelessWidget {
|
||||
const LogoutButton({Key? key}) : super(key: key);
|
||||
const LogoutButton({
|
||||
required this.identity,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
final String identity;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -25,10 +35,10 @@ class LogoutButton extends StatelessWidget {
|
|||
|
||||
return Row(
|
||||
children: [
|
||||
Text(url),
|
||||
Text(url + ": " + identity),
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
logout();
|
||||
logout(context, identity);
|
||||
},
|
||||
icon: const Icon(Icons.logout),
|
||||
label: Text("logout".i18n()))
|
||||
|
@ -37,7 +47,7 @@ class LogoutButton extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
void logout() async {
|
||||
//await global.settings!.saveAuthCode("");
|
||||
exit(0);
|
||||
void logout(context, String identity) async {
|
||||
global.settings!.removeIdentity(identity);
|
||||
Phoenix.rebirth(context);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import 'package:loris/pages/chat/chat.dart';
|
|||
import 'package:loris/pages/notifications/notifications.dart';
|
||||
import 'package:loris/pages/timeline/timeline.dart';
|
||||
import 'package:loris/pages/settings/settings.dart';
|
||||
import '../business_logic/websocket.dart' as websocket;
|
||||
|
||||
class MainScaffold extends StatefulWidget {
|
||||
const MainScaffold({Key? key}) : super(key: key);
|
||||
|
|
|
@ -42,7 +42,7 @@ class DisplayName extends StatelessWidget {
|
|||
Key? key,
|
||||
}) : super(key: key);
|
||||
final AccountModel account;
|
||||
final isReblog;
|
||||
final bool isReblog;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
|
@ -114,7 +114,16 @@ ThemeData getTheme(CustomColors colors) {
|
|||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
tooltipTheme: TooltipThemeData(),
|
||||
tooltipTheme: TooltipThemeData(
|
||||
textStyle: TextStyle(
|
||||
color: colors.colorScheme.onPrimary,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -102,6 +102,13 @@ packages:
|
|||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_phoenix:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_phoenix
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
|
|
|
@ -44,6 +44,7 @@ dependencies:
|
|||
shelf: ^1.3.1
|
||||
html: ^0.15.0
|
||||
web_socket_channel: ^2.2.0
|
||||
flutter_phoenix: ^1.0.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in New Issue