Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions android/app/src/main/kotlin/org/lichess/mobileV2/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import android.app.ActivityManager
import android.content.Context
import android.graphics.Rect
import androidx.core.view.ViewCompat
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel

class MainActivity: FlutterActivity() {
private val exclusionChannel = "mobile.lichess.org/gestures_exclusion"
private val storageChannel = "mobile.lichess.org/storage"
private val GESTURES_CHANNEL = "mobile.lichess.org/gestures_exclusion"
private val SYSTEM_CHANNEL = "mobile.lichess.org/system"

override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, exclusionChannel).setMethodCallHandler {
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, GESTURES_CHANNEL).setMethodCallHandler {
call, result ->
if (call.method == "setSystemGestureExclusionRects") {
val arguments = call.arguments as List<Map<String, Int>>
Expand All @@ -27,13 +26,26 @@ class MainActivity: FlutterActivity() {
}
}

MethodChannel(flutterEngine.dartExecutor.binaryMessenger, storageChannel).setMethodCallHandler {
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, SYSTEM_CHANNEL).setMethodCallHandler {
call, result ->
if (call.method == "clearApplicationUserData") {
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
result.success(activityManager.clearApplicationUserData())
} else {
result.notImplemented()
when (call.method) {
"clearApplicationUserData" -> {
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
result.success(activityManager.clearApplicationUserData())
}
"getTotalRam" -> {
val memoryInfo = getAvailableMemory()
val totalMemInMb = memoryInfo.totalMem / 1048576L
result.success(totalMemInMb.toInt())
}
// "getAvailableRam" -> {
// val memoryInfo = getAvailableMemory()
// val availMemInMb = memoryInfo.availMem / 1048576L
// result.success(availMemInMb.toInt())
// }
else -> {
result.notImplemented()
}
}
}
}
Expand All @@ -47,4 +59,11 @@ class MainActivity: FlutterActivity() {
item["bottom"] ?: error("rect at index $index doesn't contain 'bottom' property")
)
}

private fun getAvailableMemory(): ActivityManager.MemoryInfo {
val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
return ActivityManager.MemoryInfo().also { memoryInfo ->
activityManager.getMemoryInfo(memoryInfo)
}
}
}
Binary file added assets/sounds/standard/puzzleStormEnd.aifc
Binary file not shown.
20 changes: 7 additions & 13 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,12 @@ PODS:
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
- soundpool (0.0.1):
- sound_effect (0.0.2):
- Flutter
- sqflite (0.0.3):
- Flutter
- FlutterMacOS
- stockfish (1.6.0):
- Flutter
- system_info_plus (0.0.1):
- stockfish (1.6.1):
- Flutter
- url_launcher_ios (0.0.1):
- Flutter
Expand All @@ -156,10 +154,9 @@ DEPENDENCIES:
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- share_plus (from `.symlinks/plugins/share_plus/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- soundpool (from `.symlinks/plugins/soundpool/ios`)
- sound_effect (from `.symlinks/plugins/sound_effect/ios`)
- sqflite (from `.symlinks/plugins/sqflite/darwin`)
- stockfish (from `.symlinks/plugins/stockfish/ios`)
- system_info_plus (from `.symlinks/plugins/system_info_plus/ios`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
- wakelock_plus (from `.symlinks/plugins/wakelock_plus/ios`)

Expand Down Expand Up @@ -210,14 +207,12 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/share_plus/ios"
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
soundpool:
:path: ".symlinks/plugins/soundpool/ios"
sound_effect:
:path: ".symlinks/plugins/sound_effect/ios"
sqflite:
:path: ".symlinks/plugins/sqflite/darwin"
stockfish:
:path: ".symlinks/plugins/stockfish/ios"
system_info_plus:
:path: ".symlinks/plugins/system_info_plus/ios"
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"
wakelock_plus:
Expand Down Expand Up @@ -253,10 +248,9 @@ SPEC CHECKSUMS:
PromisesSwift: 9d77319bbe72ebf6d872900551f7eeba9bce2851
share_plus: 8875f4f2500512ea181eef553c3e27dba5135aad
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
soundpool: c7f4422ca206e77f8900ed3c4ee6a6ff5a0e38a9
sound_effect: 5280cfa89d4a576032186f15600dc948ca6d39ce
sqflite: 673a0e54cc04b7d6dba8d24fb8095b31c3a99eec
stockfish: 1cee686b12e2541a977d062746d2eb3f794d891c
system_info_plus: 5393c8da281d899950d751713575fbf91c7709aa
stockfish: 9e398e73bfb36580f16b79e8b9b45568b9e1dcd9
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe
wakelock_plus: 78ec7c5b202cab7761af8e2b2b3d0671be6c4ae1

Expand Down
24 changes: 22 additions & 2 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import Flutter
) -> Bool {

let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let badgeChannel = FlutterMethodChannel(name: "mobile.lichess.org/badge",
let BADGE_CHANNEL = FlutterMethodChannel(name: "mobile.lichess.org/badge",
binaryMessenger: controller.binaryMessenger)

badgeChannel.setMethodCallHandler({
let SYSTEM_CHANNEL = FlutterMethodChannel(name: "mobile.lichess.org/system",
binaryMessenger: controller.binaryMessenger)

BADGE_CHANNEL.setMethodCallHandler({
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
guard call.method == "setBadge" else {
result(FlutterMethodNotImplemented)
Expand All @@ -28,7 +31,24 @@ import Flutter
}
})

SYSTEM_CHANNEL.setMethodCallHandler({
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
guard call.method == "getTotalRam" else {
result(FlutterMethodNotImplemented)
return
}

result(self.getPhysicalMemory())
})

GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

private func getPhysicalMemory() -> Int {
let memory : Int = Int(ProcessInfo.processInfo.physicalMemory)
let constant : Int = 1_048_576
let res = memory / constant
return Int(res)
}
}
4 changes: 2 additions & 2 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import 'package:lichess_mobile/src/model/settings/general_preferences.dart';
import 'package:lichess_mobile/src/navigation.dart';
import 'package:lichess_mobile/src/notification_service.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
import 'package:lichess_mobile/src/utils/android.dart';
import 'package:lichess_mobile/src/utils/connectivity.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
import 'package:lichess_mobile/src/utils/screen.dart';
import 'package:lichess_mobile/src/utils/system.dart';
import 'package:lichess_mobile/src/view/game/game_screen.dart';

class LoadingAppScreen extends ConsumerWidget {
Expand Down Expand Up @@ -71,7 +71,7 @@ class LoadingAppScreen extends ConsumerWidget {
const SizedBox(height: 16.0),
ElevatedButton(
onPressed: () {
AndroidStorage.instance.clearUserData();
System.instance.clearUserData();
},
child: const Text('Clear storage'),
),
Expand Down
15 changes: 7 additions & 8 deletions lib/src/app_initialization.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:convert';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
Expand All @@ -17,15 +16,14 @@ import 'package:lichess_mobile/src/model/settings/board_preferences.dart';
import 'package:lichess_mobile/src/model/settings/general_preferences.dart';
import 'package:lichess_mobile/src/utils/color_palette.dart';
import 'package:lichess_mobile/src/utils/string.dart';
import 'package:lichess_mobile/src/utils/system.dart';
import 'package:logging/logging.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:path/path.dart' as p;
import 'package:pub_semver/pub_semver.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:soundpool/soundpool.dart';
import 'package:sqflite/sqflite.dart';
import 'package:system_info_plus/system_info_plus.dart';

part 'app_initialization.freezed.dart';
part 'app_initialization.g.dart';
Expand All @@ -41,8 +39,6 @@ Future<AppInitializationData> appInitialization(
final pInfo = await PackageInfo.fromPlatform();
final deviceInfo = await DeviceInfoPlugin().deviceInfo;
final prefs = await SharedPreferences.getInstance();
final soundTheme = GeneralPreferences.fetchFromStorage(prefs).soundTheme;
final soundPool = await ref.watch(soundPoolProvider(soundTheme).future);

final dbPath = p.join(await getDatabasesPath(), kLichessDatabaseName);

Expand All @@ -54,6 +50,11 @@ Future<AppInitializationData> appInitialization(
prefs.setString('installed_version', appVersion.canonicalizedVersion);
}

// preload sounds
final soundTheme = GeneralPreferences.fetchFromStorage(prefs).soundTheme;
final soundService = ref.read(soundServiceProvider);
await soundService.initialize(soundTheme);

final db = await openDb(databaseFactory, dbPath);

if (prefs.getBool('first_run') ?? true) {
Expand Down Expand Up @@ -119,14 +120,13 @@ Future<AppInitializationData> appInitialization(
}
}

final physicalMemory = await SystemInfoPlus.physicalMemory ?? 256.0;
final physicalMemory = await System.instance.getTotalRam() ?? 256.0;
final engineMaxMemory = (physicalMemory / 10).ceil();

return AppInitializationData(
packageInfo: pInfo,
deviceInfo: deviceInfo,
sharedPreferences: prefs,
soundPool: soundPool,
userSession: await sessionStorage.read(),
database: db,
sri: sri,
Expand All @@ -140,7 +140,6 @@ class AppInitializationData with _$AppInitializationData {
required PackageInfo packageInfo,
required BaseDeviceInfo deviceInfo,
required SharedPreferences sharedPreferences,
required (Soundpool, IMap<Sound, int>) soundPool,
required AuthSessionState? userSession,
required Database database,
required String sri,
Expand Down
Loading