Neighbourhood.omg.lol/MainPage.xaml.cs

33 lines
1.1 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.WebView;
using Microsoft.AspNetCore.Components.WebView.Maui;
using Neighbourhood.omg.lol.Models;
using System.ComponentModel;
using System.Diagnostics;
namespace Neighbourhood.omg.lol {
public partial class MainPage : ContentPage {
private State State { get; set; }
public MainPage() {
InitializeComponent();
State = IPlatformApplication.Current!.Services.GetService<State>()!;
BindingContext = State;
State.PropertyChanged += State_PropertyChanged;
}
private void State_PropertyChanged(object? sender, PropertyChangedEventArgs e) {
if (e.PropertyName == nameof(State.CanRefresh) || e.PropertyName == nameof(State.AtTop)) {
refreshView.IsEnabled = State.CanRefresh && State.AtTop;
}
}
private void BlazorUrlLoading(object? sender, UrlLoadingEventArgs e) {
if(e.Url.Host == "home.omg.lol" && e.Url.AbsolutePath == "/oauth/authorize") {
e.UrlLoadingStrategy = UrlLoadingStrategy.CancelLoad;
Shell.Current.GoToAsync(nameof(LoginWebViewPage));
}
}
}
}