Skip to content

Commit

Permalink
Merge branch 'lichess-org:main' into cloudydino/issue-1309
Browse files Browse the repository at this point in the history
  • Loading branch information
CloudyDino authored Feb 4, 2025
2 parents 089b609 + 408748b commit 3c8b91d
Show file tree
Hide file tree
Showing 48 changed files with 1,723 additions and 1,603 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install Flutter
uses: subosito/flutter-action@v2
with:
channel: main
channel: beta
- run: flutter doctor -v

- name: Checkout mobile code
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

- uses: subosito/flutter-action@v2
with:
channel: main
channel: beta
- run: flutter doctor -v

- name: Install requirements for sqflite_common_ffi package
Expand Down
2 changes: 1 addition & 1 deletion COPYING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ Fontawesome in assets/fonts | [davegandy](https://fontawesome.com) | [SIL OFL 1.
External services
-----------------

Lichobile relies on these external services:
Lichess Mobile relies on these external services:

* [lichess.org](https://lichess.org)
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
2 changes: 1 addition & 1 deletion android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version '8.1.0' apply false
id "com.android.application" version '8.6.0' apply false
id "org.jetbrains.kotlin.android" version "1.8.21" apply false
id "com.google.gms.google-services" version "4.4.0" apply false
id "com.google.firebase.crashlytics" version "2.9.9" apply false
Expand Down
13 changes: 4 additions & 9 deletions docs/setting_dev_env.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@ This project uses Flutter.
> Installing on Linux using `snapd` might cause some [problems](https://github.com/lichess-org/mobile/issues/123) building stockfish.
> Installing flutter manually is a known workaround.
2. Switch to the main channel by running `flutter channel main` and `flutter upgrade`
2. Switch to the beta channel by running `flutter channel beta` and `flutter upgrade`

> [!NOTE]
> We're using Flutter's `main` channel while the app itself is in Beta.
> This is to ensure that we're getting the latest bug fixes and features from
> Flutter as early as possible.
> We'll update the flutter version lower bound in the `pubspec.yaml` file from
> time to time to ensure that the app is compatible with the latest stable. So
> make sure to run `flutter upgrade` regularly.
> We'll use Flutter's `beta` channel while the app itself is in Beta.
3. Ensure Flutter is correctly configured by running `flutter doctor`

Expand Down Expand Up @@ -122,7 +117,7 @@ simulator.
If you use systemd-resolved, the recommended mode of handling `/etc/resolv.conf` is to symlink `/etc/resolv.conf` to `/run/systemd/resolve/stub-resolv.conf`.

- If you experience high lags or freezes, check the memory settings and be sure to enable hardware acceleration (`-gpu host`).

Also disabling the snapshot storage may help:

```bash
Expand Down Expand Up @@ -193,7 +188,7 @@ flutter run \
--dart-define=LICHESS_WS_HOST=[lila_gitpod_host]
```

To find the host of your lila Gitpod instance, use the command `gp url 8080`. Just be careful to not include the full url in the hosts variables, you need to remove the https:// from the url.
To find the host of your lila Gitpod instance, use the command `gp url 8080`. Just be careful to not include the full url in the hosts variables, you need to remove the https:// from the url.

#### When using lila-docker

Expand Down
6 changes: 3 additions & 3 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ PODS:
- GoogleUtilities/Reachability (~> 8.0)
- GoogleUtilities/UserDefaults (~> 8.0)
- nanopb (~> 3.30910.0)
- FirebaseRemoteConfigInterop (11.6.0)
- FirebaseRemoteConfigInterop (11.8.0)
- FirebaseSessions (11.6.0):
- FirebaseCore (~> 11.6.0)
- FirebaseCoreExtension (~> 11.6.0)
Expand Down Expand Up @@ -238,7 +238,7 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/wakelock_plus/ios"

SPEC CHECKSUMS:
app_settings: 3507c575c2b18a462c99948f61d5de21d4420999
app_settings: 5127ae0678de1dcc19f2293271c51d37c89428b2
AppAuth: d4f13a8fe0baf391b2108511793e4b479691fb73
connectivity_plus: 2256d3e20624a7749ed21653aafe291a46446fee
cupertino_http: 94ac07f5ff090b8effa6c5e2c47871d48ab7c86c
Expand All @@ -253,7 +253,7 @@ SPEC CHECKSUMS:
FirebaseCrashlytics: b21c665fb50138766480bce73ebdb1aa30f7f300
FirebaseInstallations: efc0946fc756e4d22d8113f7c761948120322e8c
FirebaseMessaging: e1aca1fcc23e8b9eddb0e33f375ff90944623021
FirebaseRemoteConfigInterop: e75e348953352a000331eb77caf01e424248e176
FirebaseRemoteConfigInterop: 98897a64aa372eac3c5b3fe2816594ccfaac55ef
FirebaseSessions: 9529d14180868e29a8da164b3a729c036204918b
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_appauth: 914057fda669db5073d3ca9d94ea932e7df3c964
Expand Down
30 changes: 0 additions & 30 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:lichess_mobile/src/init.dart';
import 'package:lichess_mobile/src/intl.dart';
import 'package:lichess_mobile/src/log.dart';
import 'package:lichess_mobile/src/model/common/service/sound_service.dart';
import 'package:shared_preferences/shared_preferences.dart';

Future<void> main() async {
final widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
Expand All @@ -18,11 +17,6 @@ Future<void> main() async {
// See src/app.dart for splash screen removal
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);

// Old API.
// TODO: Remove this once all SharedPreferences usage is migrated to SharedPreferencesAsync.
SharedPreferences.setPrefix('lichess.');
await migrateSharedPreferences();

await lichessBinding.preloadSharedPreferences();

if (defaultTargetPlatform == TargetPlatform.android) {
Expand All @@ -43,27 +37,3 @@ Future<void> main() async {

runApp(ProviderScope(observers: [ProviderLogger()], child: const AppInitializationScreen()));
}

Future<void> migrateSharedPreferences() async {
final prefs = await SharedPreferences.getInstance();
final didMigrate = prefs.getBool('shared_preferences_did_migrate') ?? false;
if (didMigrate) {
return;
}
final newPrefs = SharedPreferencesAsync();
for (final key in prefs.getKeys()) {
final value = prefs.get(key);
if (value is String) {
await newPrefs.setString(key, value);
} else if (value is int) {
await newPrefs.setInt(key, value);
} else if (value is double) {
await newPrefs.setDouble(key, value);
} else if (value is bool) {
await newPrefs.setBool(key, value);
} else if (value is List<String>) {
await newPrefs.setStringList(key, value);
}
}
await prefs.setBool('shared_preferences_did_migrate', true);
}
37 changes: 32 additions & 5 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,25 @@ class _AppState extends ConsumerState<Application> {
cupertinoOverrideTheme: const CupertinoThemeData(applyThemeToAll: true),
appBarStyle: isIOS ? null : FlexAppBarStyle.scaffoldBackground,
);

// Defined in 2 steps to allow for a different scaffold background color.
final darkFlexScheme = FlexColorScheme.dark(
colors: flexScheme.dark,
surfaceMode: FlexSurfaceMode.highSurfaceLowScaffold,
blendLevel: 20,
);
final themeDark = FlexThemeData.dark(
colors: flexScheme.dark,
surfaceMode: FlexSurfaceMode.highSurfaceLowScaffold,
blendLevel: 25,
blendLevel: 20,
cupertinoOverrideTheme: const CupertinoThemeData(applyThemeToAll: true),
scaffoldBackground:
darkFlexScheme.scaffoldBackground != null
? lighten(darkFlexScheme.scaffoldBackground!, 0.05)
: null,
appBarStyle: isIOS ? null : FlexAppBarStyle.scaffoldBackground,
);

final darkScaffoldBackgroundColor = lighten(themeDark.scaffoldBackgroundColor, 0.05);

final floatingActionButtonTheme =
generalPrefs.systemColors
? null
Expand Down Expand Up @@ -182,7 +191,7 @@ class _AppState extends ConsumerState<Application> {
primaryColor: themeDark.colorScheme.primaryFixed,
primaryContrastingColor: themeDark.colorScheme.onPrimaryFixed,
brightness: Brightness.dark,
scaffoldBackgroundColor: darkScaffoldBackgroundColor,
scaffoldBackgroundColor: themeDark.scaffoldBackgroundColor,
barBackgroundColor: themeDark.appBarTheme.backgroundColor?.withValues(
alpha: isTablet ? 1.0 : 0.9,
),
Expand All @@ -206,6 +215,13 @@ class _AppState extends ConsumerState<Application> {
blendLevel: 20,
);

const iosMenuTheme = MenuThemeData(
style: MenuStyle(
elevation: WidgetStatePropertyAll(0),
shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: kCardBorderRadius)),
),
);

return AnnotatedRegion<SystemUiOverlayStyle>(
value: FlexColorScheme.themedSystemNavigationBar(
context,
Expand All @@ -225,6 +241,7 @@ class _AppState extends ConsumerState<Application> {
subtitleTextStyle: isIOS ? lightCupertino.textTheme.textStyle : null,
leadingAndTrailingTextStyle: isIOS ? lightCupertino.textTheme.textStyle : null,
),
menuTheme: isIOS ? iosMenuTheme : null,
floatingActionButtonTheme: floatingActionButtonTheme,
navigationBarTheme: NavigationBarTheme.of(context).copyWith(
height: remainingHeight < kSmallRemainingHeightLeftBoardThreshold ? 60 : null,
Expand All @@ -235,7 +252,6 @@ class _AppState extends ConsumerState<Application> {
extensions: [lichessCustomColors.harmonized(themeLight.colorScheme)],
),
darkTheme: themeDark.copyWith(
scaffoldBackgroundColor: darkScaffoldBackgroundColor,
cupertinoOverrideTheme: darkCupertino,
splashFactory: isIOS ? NoSplash.splashFactory : null,
textTheme: isIOS ? Typography.whiteCupertino : null,
Expand All @@ -244,6 +260,7 @@ class _AppState extends ConsumerState<Application> {
subtitleTextStyle: isIOS ? darkCupertino.textTheme.textStyle : null,
leadingAndTrailingTextStyle: isIOS ? darkCupertino.textTheme.textStyle : null,
),
menuTheme: isIOS ? iosMenuTheme : null,
floatingActionButtonTheme: floatingActionButtonTheme,
navigationBarTheme: NavigationBarTheme.of(context).copyWith(
height: remainingHeight < kSmallRemainingHeightLeftBoardThreshold ? 60 : null,
Expand All @@ -256,6 +273,16 @@ class _AppState extends ConsumerState<Application> {
BackgroundThemeMode.dark => ThemeMode.dark,
BackgroundThemeMode.system => ThemeMode.system,
},
builder:
isIOS
? (context, child) => IconTheme.merge(
data: IconThemeData(color: CupertinoTheme.of(context).textTheme.textStyle.color),
child: DefaultTextStyle.merge(
style: CupertinoTheme.of(context).textTheme.textStyle,
child: Material(color: Colors.transparent, child: child),
),
)
: null,
home: const BottomNavScaffold(),
navigatorObservers: [rootNavPageRouteObserver],
),
Expand Down
19 changes: 17 additions & 2 deletions lib/src/init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ Future<void> setupFirstLaunch() async {
final appVersion = Version.parse(pInfo.version);
final installedVersion = prefs.getString('installed_version');

// TODO remove this migration code after a few releases
if (installedVersion != null && Version.parse(installedVersion) < Version(0, 13, 14)) {
if (installedVersion != null && Version.parse(installedVersion) < Version(0, 14, 0)) {
// TODO remove this migration code after a few releases
_migrateThemeSettings();

_resetHomePrefs();
}

if (installedVersion == null || Version.parse(installedVersion) != appVersion) {
Expand All @@ -54,6 +56,19 @@ Future<void> setupFirstLaunch() async {
}
}

Future<void> _resetHomePrefs() async {
final prefs = LichessBinding.instance.sharedPreferences;
try {
final stored = prefs.getString(PrefCategory.home.storageKey);
if (stored == null) {
return;
}
await prefs.setString(PrefCategory.home.storageKey, jsonEncode(null));
} catch (e) {
_logger.warning('Failed to migrate home preferences: $e');
}
}

Future<void> _migrateThemeSettings() async {
if (getCorePalette() == null) {
return;
Expand Down
10 changes: 10 additions & 0 deletions lib/src/model/common/preloaded_data.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io' show Directory;

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand All @@ -8,6 +10,7 @@ import 'package:lichess_mobile/src/model/auth/session_storage.dart';
import 'package:lichess_mobile/src/utils/string.dart';
import 'package:lichess_mobile/src/utils/system.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:path_provider/path_provider.dart' show getApplicationDocumentsDirectory;
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'preloaded_data.g.dart';
Expand All @@ -19,6 +22,7 @@ typedef PreloadedData =
AuthSessionState? userSession,
String sri,
int engineMaxMemoryInMb,
Directory? appDocumentsDirectory,
});

@Riverpod(keepAlive: true)
Expand Down Expand Up @@ -50,11 +54,17 @@ Future<PreloadedData> preloadedData(Ref ref) async {
final physicalMemory = await System.instance.getTotalRam() ?? 256.0;
final engineMaxMemory = (physicalMemory / 10).ceil();

Directory? appDocumentsDirectory;
try {
appDocumentsDirectory = await getApplicationDocumentsDirectory();
} catch (_) {}

return (
packageInfo: pInfo,
deviceInfo: deviceInfo,
userSession: userSession,
sri: sri,
engineMaxMemoryInMb: engineMaxMemory,
appDocumentsDirectory: appDocumentsDirectory,
);
}
Loading

0 comments on commit 3c8b91d

Please sign in to comment.