2026-06-15 10:19:24 +02:00
|
|
|
using System.Threading.Tasks;
|
2026-06-12 16:06:37 +02:00
|
|
|
using Android.App;
|
2026-06-15 10:19:24 +02:00
|
|
|
using Android.Content;
|
2026-06-12 16:06:37 +02:00
|
|
|
using Android.Content.PM;
|
2026-06-15 10:19:24 +02:00
|
|
|
using Android.OS;
|
2026-06-12 16:06:37 +02:00
|
|
|
using Avalonia.Android;
|
2026-07-19 16:01:07 +02:00
|
|
|
using AvaloniaApp = PalladiumWallet.App.App;
|
2026-06-12 16:06:37 +02:00
|
|
|
|
|
|
|
|
namespace PalladiumWallet.Mobile;
|
|
|
|
|
|
|
|
|
|
[Activity(
|
|
|
|
|
Label = "Palladium Wallet",
|
|
|
|
|
Theme = "@style/MyTheme.NoActionBar",
|
|
|
|
|
MainLauncher = true,
|
|
|
|
|
ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.UiMode)]
|
|
|
|
|
public class MainActivity : AvaloniaMainActivity
|
|
|
|
|
{
|
2026-06-15 10:19:24 +02:00
|
|
|
internal const int ScanRequestCode = 9001;
|
|
|
|
|
internal static TaskCompletionSource<string?>? ScanTcs;
|
|
|
|
|
internal static MainActivity? Current;
|
2026-07-19 16:01:07 +02:00
|
|
|
private bool _wasPaused;
|
2026-06-15 10:19:24 +02:00
|
|
|
|
|
|
|
|
protected override void OnCreate(Bundle? savedInstanceState)
|
|
|
|
|
{
|
|
|
|
|
base.OnCreate(savedInstanceState);
|
|
|
|
|
Current = this;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-19 16:01:07 +02:00
|
|
|
protected override void OnPause()
|
|
|
|
|
{
|
|
|
|
|
base.OnPause();
|
|
|
|
|
_wasPaused = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnResume()
|
|
|
|
|
{
|
|
|
|
|
base.OnResume();
|
|
|
|
|
if (!_wasPaused) return;
|
|
|
|
|
_wasPaused = false;
|
|
|
|
|
// The TCP socket can die silently while the screen was off/locked (Doze,
|
|
|
|
|
// mobile radio suspend, NAT timeout) without the app ever observing the
|
|
|
|
|
// failure. Force an immediate health check instead of waiting for the next
|
|
|
|
|
// 20s keep-alive tick, which may itself have been suspended for longer than
|
|
|
|
|
// the lock.
|
|
|
|
|
if (AvaloniaApp.MainViewModel is { } vm)
|
|
|
|
|
_ = vm.CheckConnectionOnResumeAsync();
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-15 10:19:24 +02:00
|
|
|
protected override void OnActivityResult(int requestCode, Result resultCode, Intent? data)
|
|
|
|
|
{
|
|
|
|
|
base.OnActivityResult(requestCode, resultCode, data);
|
|
|
|
|
if (requestCode == ScanRequestCode)
|
|
|
|
|
{
|
|
|
|
|
var text = resultCode == Result.Ok ? data?.GetStringExtra(ScannerActivity.ResultKey) : null;
|
|
|
|
|
ScanTcs?.TrySetResult(text);
|
|
|
|
|
ScanTcs = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-06-12 16:06:37 +02:00
|
|
|
}
|