Compare commits

..

No commits in common. "ce2124451742402eb06662e4a5740719220ef710" and "2fcb6e1faee7f233b3060933aa37f8c5c23d367e" have entirely different histories.

21 changed files with 26 additions and 103 deletions

View file

@ -1,9 +1,5 @@
namespace Neighbourhood.omg.lol {
public partial class App : Application {
public static string Name { get; set; }
public static string Version { get; set; }
public App(NavigatorService navigatorService) {
InitializeComponent();

View file

@ -72,7 +72,6 @@
if (!string.IsNullOrEmpty(Pic?.Id)) {
await api.DeletePic(State.SelectedAddressName, Pic.Id);
await State.RefreshPics();
State.SendRefresh();
await InvokeAsync(StateHasChanged);
}
@ -93,7 +92,6 @@
if(!string.IsNullOrEmpty(Pic?.Id)) {
await api.PostPicDescription(State.SelectedAddressName, Pic.Id, Description);
await State.RefreshPics();
State.SendRefresh();
await InvokeAsync(StateHasChanged);
}

View file

@ -91,7 +91,6 @@
if (!string.IsNullOrEmpty(Status?.Id)) {
await api.DeleteStatus(State.SelectedAddressName, Status.Id);
await State.RefreshStatuses();
State.SendRefresh();
await InvokeAsync(StateHasChanged);
}
@ -113,7 +112,6 @@
if (!string.IsNullOrEmpty(Status?.Id)) {
await api.PatchStatus(State.SelectedAddressName, Status.Id, Content, Emoji);
await State.RefreshStatuses();
State.SendRefresh();
await InvokeAsync(StateHasChanged);
}

View file

@ -19,13 +19,13 @@
}
public async Task Reload() {
// if (Html == null){
if (Html == null){
Html = await api.GetHtml(Url);
string? HtmlString = Html?.ToString();
HtmlString = HtmlString?.Replace("</head>", "<base target='_blank'></head>");
HtmlString = HtmlString?.Replace("</body>", "<script src='https://cdn.jsdelivr.net/npm/@iframe-resizer/child'></script></body>");
Html = (MarkupString)HtmlString;
// }
}
await InvokeAsync(StateHasChanged);
}
}

View file

@ -1,4 +1,5 @@
@inject CustomAuthenticationStateProvider AuthStateProvider;
@using System.Reflection
@inject CustomAuthenticationStateProvider AuthStateProvider;
@inject State State;
<AuthorizeView>
<Authorized>
@ -44,7 +45,7 @@
</a>
<a class="row medium-opacity">
<i class="fa-solid fa-circle-info tiny"></i>
<small>@App.Name - @App.Version</small>
<small>@assembly.Name - @assembly.Version?.ToString()</small>
</a>
</menu>
</button>
@ -80,6 +81,7 @@
</AuthorizeView>
@code {
AssemblyName assembly = Assembly.GetExecutingAssembly().GetName();
public void changeAddress(AddressResponseData address) {
State.SelectedAddress = address;
}

View file

@ -78,7 +78,6 @@
if(!string.IsNullOrEmpty(Description) && response != null && !string.IsNullOrEmpty(response.Id)) {
await api.PostPicDescription(State.SelectedAddressName, response.Id, Description);
await State.RefreshPics();
State.SendRefresh();
await InvokeAsync(StateHasChanged);
}

View file

@ -81,9 +81,8 @@
var result = await api.StatusPost(State!.SelectedAddressName!, post);
if(result != null){
await State.RefreshStatuses();
State.SendRefresh();
await InvokeAsync(StateHasChanged);
// navigationManager.NavigateTo("/statuslog/latest");
navigationManager.NavigateTo("/statuslog/latest");
}
this.Active = false;

View file

@ -65,11 +65,9 @@ else {
private async void StateChanged(object? sender, PropertyChangedEventArgs e) {
if (e.PropertyName == nameof(State.IsRefreshing) && State.IsRefreshing) {
using (State.GetRefreshToken()) {
addresses = await State.GetDirectory(true);
GroupAddresses();
await InvokeAsync(StateHasChanged);
}
addresses = await State.GetDirectory(true);
GroupAddresses();
State.IsRefreshing = false;
}
}

View file

@ -36,10 +36,8 @@
private async void StateChanged(object? sender, PropertyChangedEventArgs e) {
if (e.PropertyName == nameof(State.IsRefreshing) && State.IsRefreshing) {
using (State.GetRefreshToken()) {
messages = await State.GetEphemeralMessages(true);
await InvokeAsync(StateHasChanged);
}
messages = await State.GetEphemeralMessages(true);
State.IsRefreshing = false;
}
}

View file

@ -43,10 +43,8 @@
private async void StateChanged(object? sender, PropertyChangedEventArgs e) {
if (e.PropertyName == nameof(State.IsRefreshing) && State.IsRefreshing) {
using (State.GetRefreshToken()){
garden = await State.GetNowGarden(true);
await InvokeAsync(StateHasChanged);
}
garden = await State.GetNowGarden(true);
State.IsRefreshing = false;
}
}

View file

@ -129,18 +129,6 @@
if (fragment.EndsWith("now")) await ReloadNow();
else if (fragment.EndsWith("profile")) await ReloadProfile();
bio = await State.GetBio(Address);
State.PropertyChanged += StateChanged;
}
private async void StateChanged(object? sender, PropertyChangedEventArgs e) {
if (e.PropertyName == nameof(State.IsRefreshing) && State.IsRefreshing) {
using (State.GetRefreshToken()){
await ReloadNow();
await ReloadProfile();
bio = await State.GetBio(Address);
await InvokeAsync(StateHasChanged);
}
}
}
private async Task ReloadNow() {

View file

@ -34,10 +34,8 @@
private async void StateChanged(object? sender, PropertyChangedEventArgs e) {
if (e.PropertyName == nameof(State.IsRefreshing) && State.IsRefreshing) {
using (State.GetRefreshToken()){
pics = await PicsFunc(true);
await InvokeAsync(StateHasChanged);
}
pics = await PicsFunc(true);
State.IsRefreshing = false;
}
}

View file

@ -1,6 +1,6 @@
@inject State State
<button id="refreshButton" class="absolute transparent circle top right margin" @onclick="() => State.SendRefresh()">
<button id="refreshButton" class="absolute transparent circle top right margin" @onclick="() => State.IsRefreshing = true">
<i class="fa-solid fa-arrow-rotate-right @(State.IsRefreshing ? "fa-spin" : "")"></i>
</button>

View file

@ -33,10 +33,8 @@
private async void StateChanged(object? sender, PropertyChangedEventArgs e) {
if (e.PropertyName == nameof(State.IsRefreshing) && State.IsRefreshing) {
using (State.GetRefreshToken()) {
statuses = await StatusFunc(true);
await InvokeAsync(StateHasChanged);
}
statuses = await StatusFunc(true);
State.IsRefreshing = false;
}
}

View file

@ -33,7 +33,6 @@ public partial class LoginWebViewPage : ContentPage
if ( client_id != null
&& client_secret != null
&& redirect_uri != null) {
//this.loginwebview.UserAgent = new System.Net.Http.Headers.ProductInfoHeaderValue(App.Name, App.Version).ToString();
this.loginwebview.Source = $"https://home.omg.lol/oauth/authorize?client_id={client_id}&scope=everything&redirect_uri={redirect_uri}&response_type=code";
}
}

View file

@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Neighbourhood.omg.lol.Models;
using System.Reflection;
namespace Neighbourhood.omg.lol {
public static class MauiProgram {
@ -23,16 +22,8 @@ namespace Neighbourhood.omg.lol {
builder.Services.AddSingleton<State>();
builder.Services.AddSingleton<NavigatorService>();
//ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
//builder.Services.AddSingleton<IConfiguration>(configurationBuilder.AddUserSecrets<App>().Build());
var assembly = Assembly.GetExecutingAssembly();
var details = assembly.GetName();
App.Name = details.Name!;
App.Version = details.Version!.ToString();
var appSettings = $"{App.Name}.appsettings.json";
using var stream = assembly.GetManifestResourceStream(appSettings);
var config = new ConfigurationBuilder().AddJsonStream(stream).Build();
builder.Configuration.AddConfiguration(config);
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
builder.Services.AddSingleton<IConfiguration>(configurationBuilder.AddUserSecrets<App>().Build());
builder.Services.AddAuthorizationCore();
builder.Services.AddScoped<CustomAuthenticationStateProvider>();

View file

@ -70,37 +70,12 @@ namespace Neighbourhood.omg.lol.Models {
private bool _isRefreshing;
public bool IsRefreshing {
get => _isRefreshing;
private set {
set {
_isRefreshing = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsRefreshing)));
}
}
public void SendRefresh() => IsRefreshing = true;
private static int _refresherCount = 0;
private static Mutex mutex = new Mutex();
public class RefreshToken : IDisposable {
public event EventHandler? Disposed;
public void Dispose() => Disposed?.Invoke(this, EventArgs.Empty);
}
public RefreshToken GetRefreshToken() {
mutex.WaitOne();
_refresherCount++;
mutex.ReleaseMutex();
RefreshToken token = new RefreshToken();
token.Disposed += RefreshToken_Disposed;
return token;
}
private void RefreshToken_Disposed(object? sender, EventArgs e) {
mutex.WaitOne();
_refresherCount--;
if (_refresherCount == 0) IsRefreshing = false;
mutex.ReleaseMutex();
}
private bool _canRefresh;
public bool CanRefresh {
get => _canRefresh;

View file

@ -90,10 +90,6 @@
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
<Content Remove="appsettings.json" />
</ItemGroup>
<ItemGroup>
<MauiFont Remove="Resources\Fonts\fa-brands-400.ttf" />
<MauiFont Remove="Resources\Fonts\fa-brands-400.woff2" />
@ -199,10 +195,6 @@
</Content>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="appsettings.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="Markdig" Version="0.37.0" />

View file

@ -19,7 +19,8 @@ namespace Neighbourhood.omg.lol {
public RestService(string? token = null) {
_client = new HttpClient();
_client.BaseAddress = new Uri(BaseUrl);
_client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue(App.Name, App.Version));
AssemblyName name = Assembly.GetExecutingAssembly().GetName();
_client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue(name.Name ?? "Neighbourhood.omg.lol", name.Version?.ToString()));
_serializerOptions = new JsonSerializerOptions {
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
WriteIndented = true

View file

@ -1,5 +0,0 @@
{
"client_id": "08656a9ade42b8ff16b868c4bb33379e",
"client_secret": "529e47904ca8900a4fb187ecee2f6221",
"redirect_uri": "https://auth.neighbourhood.omg.lol/"
}

View file

@ -461,7 +461,7 @@ article {
overflow-wrap: anywhere;
}
nav label:is(.checkbox, .radio, .switch) {
nav label {
white-space: break-spaces;
flex: 1 1 100%;
}