Skip to content

Commit

Permalink
Don't use not recommended runWithClient
Browse files Browse the repository at this point in the history
Closes #850
  • Loading branch information
veloce committed Aug 3, 2024
1 parent 5a54921 commit a63427c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
2 changes: 1 addition & 1 deletion android/fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ platform :android do
end

def deploy_to_play_store(track)
sh "flutter build appbundle -v --obfuscate --split-debug-info=./build/app/outputs/bundle/release/symbols --dart-define=cronetHttpNoPlay=true --dart-define=no_default_http_client=true --dart-define=LICHESS_HOST=lichess.org --dart-define=LICHESS_WS_HOST=socket.lichess.org --dart-define=LICHESS_WS_SECRET=#{ENV['WS_SECRET']}"
sh "flutter build appbundle -v --obfuscate --split-debug-info=./build/app/outputs/bundle/release/symbols --dart-define=cronetHttpNoPlay=true --dart-define=LICHESS_HOST=lichess.org --dart-define=LICHESS_WS_HOST=socket.lichess.org --dart-define=LICHESS_WS_SECRET=#{ENV['WS_SECRET']}"
upload_to_play_store(
track: track,
aab: '../build/app/outputs/bundle/release/app-release.aab',
Expand Down
8 changes: 1 addition & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:http/http.dart';
import 'package:lichess_mobile/src/db/database.dart';
import 'package:lichess_mobile/src/intl.dart';
import 'package:lichess_mobile/src/log.dart';
import 'package:lichess_mobile/src/model/common/http.dart';
import 'package:lichess_mobile/src/model/common/id.dart';
import 'package:lichess_mobile/src/model/correspondence/correspondence_game_storage.dart';
import 'package:lichess_mobile/src/model/correspondence/offline_correspondence_game.dart';
Expand All @@ -28,11 +26,7 @@ import 'firebase_options.dart';
import 'src/app.dart';
import 'src/utils/color_palette.dart';

void main() {
runWithClient(_startFlutterApp, httpClientFactory);
}

Future<void> _startFlutterApp() async {
Future<void> main() async {
final widgetsBinding = WidgetsFlutterBinding.ensureInitialized();

// logging setup
Expand Down
29 changes: 10 additions & 19 deletions lib/src/app_initialization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,16 @@ Future<AppInitializationData> appInitialization(

final storedSession = await sessionStorage.read();
if (storedSession != null) {
final client = httpClientFactory();
try {
final response = await client.get(
lichessUri('/api/account'),
headers: {
'Authorization': 'Bearer ${signBearerToken(storedSession.token)}',
'User-Agent':
makeUserAgent(pInfo, deviceInfo, sri, storedSession.user),
},
).timeout(const Duration(seconds: 3));
if (response.statusCode == 401) {
await sessionStorage.delete();
}
} catch (e) {
debugPrint(
'WARNING: [AppInitialization] Error while checking session: $e',
);
} finally {
client.close();
final client = ref.read(defaultClientProvider);
final response = await client.get(
lichessUri('/api/account'),
headers: {
'Authorization': 'Bearer ${signBearerToken(storedSession.token)}',
'User-Agent': makeUserAgent(pInfo, deviceInfo, sri, storedSession.user),
},
).timeout(const Duration(seconds: 3));
if (response.statusCode == 401) {
await sessionStorage.delete();
}
}

Expand Down

0 comments on commit a63427c

Please sign in to comment.