Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
11 changes: 8 additions & 3 deletions OneGateApp/Pages/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,21 @@ await Microsoft.Maui.ApplicationModel.DataTransfer.Share.RequestAsync(new ShareT
intent.AddFlags(Android.Content.ActivityFlags.NewDocument);
activity.StartActivity(intent);
#else
Dictionary<string, object> GetLaunchParameters()
{
Dictionary<string, object> parameters = new();
if (dapp != null) parameters["dapp"] = dapp;
parameters["uri"] = System.Net.WebUtility.UrlEncode(uri.ToString());
return parameters;
}
#if IOS || MACCATALYST
bool supportOpenWithDeepLink = false;
#else
bool supportOpenWithDeepLink = true;
#endif
if (!supportOpenWithDeepLink || !await Launcher.TryOpenAsync(uri))
{
Dictionary<string, object> parameters = new();
if (dapp != null) parameters["dapp"] = dapp;
parameters["uri"] = System.Net.WebUtility.UrlEncode(uri.ToString());
Dictionary<string, object> parameters = GetLaunchParameters();
Comment thread
Jim8y marked this conversation as resolved.
Outdated
#if IOS
bool supportMultiWindow = DeviceInfo.Idiom == DeviceIdiom.Desktop || DeviceInfo.Idiom == DeviceIdiom.Tablet;
#else
Expand Down
37 changes: 35 additions & 2 deletions OneGateApp/Pages/LaunchDAppPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,38 @@
<ToolbarItem x:Name="developerToolsButton" Order="Secondary" Text="{x:Static og:Strings.DAppDebugPanel}" Clicked="OnDeveloperToolsClicked" />
<ToolbarItem x:Name="reportButton" Order="Secondary" Text="{x:Static og:Strings.Report}" Clicked="OnReportClicked" />
</ContentPage.ToolbarItems>
<og:BridgeWebView x:Name="webView" Source="{Binding Url}" Navigating="OnNavigating" InvokedFromJavaScript="OnInvokedFromJavaScript" />
</ContentPage>
<Grid>
<og:BridgeWebView x:Name="webView" Source="{Binding Url}" Navigating="OnNavigating" Navigated="OnNavigated" InvokedFromJavaScript="OnInvokedFromJavaScript" />
<Grid BackgroundColor="{toolkit:AppThemeResource PageBackground}" IsVisible="{Binding IsDAppLoading}">
<VerticalStackLayout Spacing="12" HorizontalOptions="Center" VerticalOptions="Center">
<ActivityIndicator IsRunning="{Binding IsDAppLoading}" WidthRequest="32" HeightRequest="32" />
<Label FontAttributes="Bold" HorizontalOptions="Center">
<Label.FormattedText>
<FormattedString>
<Span Text="{x:Static og:Strings.Loading}" />
<Span Text="…" />
</FormattedString>
</Label.FormattedText>
</Label>
</VerticalStackLayout>
</Grid>
<Grid Padding="16" InputTransparent="True" IsVisible="{Binding IsDAppPreparing}" VerticalOptions="Start">
<Border StyleClass="Card" HorizontalOptions="Center" MaximumWidthRequest="420">
<Grid ColumnDefinitions="Auto,*" ColumnSpacing="12">
<Border BackgroundColor="{toolkit:AppThemeResource Brand}" StrokeThickness="0" StrokeShape="Ellipse" WidthRequest="10" HeightRequest="10" VerticalOptions="Center" />
<VerticalStackLayout Grid.Column="1" Spacing="2">
<Label Text="{x:Static og:Strings.DAppPreparing}" FontAttributes="Bold" LineBreakMode="TailTruncation" MaxLines="1" />
<Label StyleClass="Secondary" Text="{x:Static og:Strings.DAppPreparingText}" FontSize="12" LineBreakMode="TailTruncation" MaxLines="2" />
</VerticalStackLayout>
</Grid>
</Border>
</Grid>
<Grid BackgroundColor="{toolkit:AppThemeResource PageBackground}" IsVisible="{Binding HasDAppLoadError}" Padding="32">
<VerticalStackLayout Spacing="16" HorizontalOptions="Center" VerticalOptions="Center" MaximumWidthRequest="420">
<Label Text="{Binding DAppLoadErrorTitle}" FontAttributes="Bold" FontSize="22" HorizontalTextAlignment="Center" />
<Label StyleClass="Secondary" Text="{Binding DAppLoadErrorMessage}" HorizontalTextAlignment="Center" />
<Button Text="{Binding RetryText}" Padding="36,14" Clicked="OnRetryDAppClicked" />
</VerticalStackLayout>
</Grid>
</Grid>
</ContentPage>
112 changes: 111 additions & 1 deletion OneGateApp/Pages/LaunchDAppPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace NeoOrder.OneGate.Pages;
public partial class LaunchDAppPage : ContentPage, IQueryAttributable
{
const string DeveloperModeKey = "preference/developer_mode_enabled";
const int DAppPreparationDurationMs = 12000;

readonly IServiceProvider serviceProvider;
readonly ProtocolSettings protocolSettings;
Expand All @@ -28,11 +29,30 @@ public partial class LaunchDAppPage : ContentPage, IQueryAttributable
readonly HttpClient httpClient;
readonly RpcServer rpcServer;
readonly RpcClient rpcClient;
CancellationTokenSource? dappPreparationCancellation;
string? url;

public required DApp DApp { get; set { field = value; OnPropertyChanged(); } }
public required string Url { get; set { field = value; OnPropertyChanged(); } }
public string? Url
{
get => url;
set
{
if (url == value) return;
url = value;
if (!string.IsNullOrWhiteSpace(url))
BeginDAppLoad();
OnPropertyChanged();
}
}
public bool IsFavorite { get; set { field = value; OnPropertyChanged(); } }
public bool IsDeveloperToolsEnabled { get; set { field = value; OnPropertyChanged(); } }
public bool IsDAppLoading { get; set { field = value; OnPropertyChanged(); } }
public bool IsDAppPreparing { get; set { field = value; OnPropertyChanged(); } }
public bool HasDAppLoadError { get; set { field = value; OnPropertyChanged(); } }
public string DAppLoadErrorTitle { get; set { field = value; OnPropertyChanged(); } } = "";
public string DAppLoadErrorMessage { get; set { field = value; OnPropertyChanged(); } } = "";
public string RetryText => Strings.Retry;

public LaunchDAppPage(IServiceProvider serviceProvider, ProtocolSettings protocolSettings, IWalletProvider walletProvider, WalletAuthorizationService walletAuthorizationService, ApplicationDbContext dbContext, HttpClient httpClient, RpcClient rpcClient, IHomeShortcutService homeShortcutService)
{
Expand All @@ -53,6 +73,12 @@ public LaunchDAppPage(IServiceProvider serviceProvider, ProtocolSettings protoco
ToolbarItems.Remove(developerToolsButton);
}

protected override void OnDisappearing()
{
base.OnDisappearing();
CancelDAppPreparation();
}

public async void ApplyQueryAttributes(IDictionary<string, object> query)
{
if (query.TryGetValue("dapp", out var value))
Expand Down Expand Up @@ -144,7 +170,91 @@ async void OnNavigating(object sender, WebNavigatingEventArgs e)
{
e.Cancel = true;
await Toast.Show(Strings.RedirectionBlockedText);
IsDAppLoading = false;
IsDAppPreparing = false;
HasDAppLoadError = false;
return;
}
BeginDAppLoad();
}

void OnNavigated(object sender, WebNavigatedEventArgs e)
{
IsDAppLoading = false;
if (e.Result == WebNavigationResult.Success || e.Result == WebNavigationResult.Cancel)
{
HasDAppLoadError = false;
if (e.Result == WebNavigationResult.Success)
BeginDAppPreparation();
else
IsDAppPreparing = false;
return;
}
ShowDAppLoadError(e.Url, e.Result);
}

void OnRetryDAppClicked(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(Url)) return;
BeginDAppLoad();
webView.Reload();
}

void BeginDAppLoad()
{
CancelDAppPreparation();
IsDAppLoading = true;
IsDAppPreparing = false;
HasDAppLoadError = false;
}

void ShowDAppLoadError(string failedUrl, WebNavigationResult result)
{
CancelDAppPreparation();
string appName = DApp?.NameLocalizer.Localize() ?? GetHostOrUrl(failedUrl);
DAppLoadErrorTitle = Strings.DAppLoadFailed;
DAppLoadErrorMessage = string.Format(Strings.DAppLoadFailedText, appName, (int)result);
HasDAppLoadError = true;
}

void BeginDAppPreparation()
{
CancelDAppPreparation();
dappPreparationCancellation = new();
IsDAppPreparing = true;
_ = WatchDAppPreparationAsync(dappPreparationCancellation.Token);
}

void CancelDAppPreparation()
{
dappPreparationCancellation?.Cancel();
dappPreparationCancellation?.Dispose();
dappPreparationCancellation = null;
IsDAppPreparing = false;
}

async Task WatchDAppPreparationAsync(CancellationToken cancellationToken)
{
try
{
await Task.Delay(DAppPreparationDurationMs, cancellationToken);
}
catch (OperationCanceledException)
{
return;
}
finally
{
if (!cancellationToken.IsCancellationRequested)
MainThread.BeginInvokeOnMainThread(() => IsDAppPreparing = false);
}
}

static string GetHostOrUrl(string url)
{
return Uri.TryCreate(url, UriKind.Absolute, out Uri? uri) && !string.IsNullOrWhiteSpace(uri.Host)
? uri.Host
: url;
}

string CreateDocumentStartScript()
Expand Down
49 changes: 47 additions & 2 deletions OneGateApp/Properties/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions OneGateApp/Properties/Strings.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,21 @@ Möchten Sie fortfahren?</value>
<data name="OpenDAppFailedText" xml:space="preserve">
<value>Rückkehr zur DApp fehlgeschlagen</value>
</data>
<data name="DAppLoadFailed" xml:space="preserve">
<value>DApp wurde nicht geladen</value>
</data>
<data name="DAppLoadFailedText" xml:space="preserve">
<value>{0} konnte nicht geladen werden. Prüfen Sie Ihre Verbindung und versuchen Sie es erneut. Status: {1}</value>
</data>
<data name="DAppPreparing" xml:space="preserve">
<value>DApp wird vorbereitet</value>
</data>
<data name="DAppPreparingText" xml:space="preserve">
<value>Spiele mit großen Ressourcen können einen Moment dauern.</value>
</data>
<data name="Retry" xml:space="preserve">
<value>Erneut versuchen</value>
</data>
<data name="Share" xml:space="preserve">
<value>Teilen</value>
</data>
Expand Down
15 changes: 15 additions & 0 deletions OneGateApp/Properties/Strings.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,21 @@ Después de desactivarla, deberá introducir manualmente la contraseña de la bi
<data name="OpenDAppFailedText" xml:space="preserve">
<value>No se pudo volver a la DApp</value>
</data>
<data name="DAppLoadFailed" xml:space="preserve">
<value>La DApp no se cargó</value>
</data>
<data name="DAppLoadFailedText" xml:space="preserve">
<value>No se pudo cargar {0}. Revisa tu conexión e inténtalo de nuevo. Estado: {1}</value>
</data>
<data name="DAppPreparing" xml:space="preserve">
<value>Preparando la DApp</value>
</data>
<data name="DAppPreparingText" xml:space="preserve">
<value>Los juegos con recursos grandes pueden tardar un momento.</value>
</data>
<data name="Retry" xml:space="preserve">
<value>Reintentar</value>
</data>
<data name="Share" xml:space="preserve">
<value>Compartir</value>
</data>
Expand Down
15 changes: 15 additions & 0 deletions OneGateApp/Properties/Strings.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,21 @@ Voulez-vous continuer ?</value>
<data name="OpenDAppFailedText" xml:space="preserve">
<value>Impossible de revenir à la DApp</value>
</data>
<data name="DAppLoadFailed" xml:space="preserve">
<value>La DApp n’a pas été chargée</value>
</data>
<data name="DAppLoadFailedText" xml:space="preserve">
<value>{0} n’a pas pu être chargée. Vérifiez votre connexion et réessayez. État : {1}</value>
</data>
<data name="DAppPreparing" xml:space="preserve">
<value>Préparation de la DApp</value>
</data>
<data name="DAppPreparingText" xml:space="preserve">
<value>Les jeux avec des ressources volumineuses peuvent prendre un moment.</value>
</data>
<data name="Retry" xml:space="preserve">
<value>Réessayer</value>
</data>
<data name="Share" xml:space="preserve">
<value>Partager</value>
</data>
Expand Down
15 changes: 15 additions & 0 deletions OneGateApp/Properties/Strings.id.resx
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,21 @@ Apakah Anda ingin melanjutkan?</value>
<data name="OpenDAppFailedText" xml:space="preserve">
<value>Tidak dapat kembali ke DApp</value>
</data>
<data name="DAppLoadFailed" xml:space="preserve">
<value>DApp tidak dimuat</value>
</data>
<data name="DAppLoadFailedText" xml:space="preserve">
<value>{0} tidak dapat dimuat. Periksa koneksi Anda dan coba lagi. Status: {1}</value>
</data>
<data name="DAppPreparing" xml:space="preserve">
<value>Menyiapkan DApp</value>
</data>
<data name="DAppPreparingText" xml:space="preserve">
<value>Game dengan aset besar mungkin perlu waktu sebentar.</value>
</data>
<data name="Retry" xml:space="preserve">
<value>Coba lagi</value>
</data>
<data name="Share" xml:space="preserve">
<value>Bagikan</value>
</data>
Expand Down
15 changes: 15 additions & 0 deletions OneGateApp/Properties/Strings.it.resx
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,21 @@ Vuoi continuare?</value>
<data name="OpenDAppFailedText" xml:space="preserve">
<value>Impossibile tornare alla DApp</value>
</data>
<data name="DAppLoadFailed" xml:space="preserve">
<value>La DApp non è stata caricata</value>
</data>
<data name="DAppLoadFailedText" xml:space="preserve">
<value>Impossibile caricare {0}. Controlla la connessione e riprova. Stato: {1}</value>
</data>
<data name="DAppPreparing" xml:space="preserve">
<value>Preparazione della DApp</value>
</data>
<data name="DAppPreparingText" xml:space="preserve">
<value>I giochi con risorse grandi possono richiedere qualche istante.</value>
</data>
<data name="Retry" xml:space="preserve">
<value>Riprova</value>
</data>
<data name="Share" xml:space="preserve">
<value>Condividi</value>
</data>
Expand Down
Loading