Skip to content

Commit

Permalink
Crdt demo (#1053)
Browse files Browse the repository at this point in the history
* add upload button to project config, display configured server when there is one.

* only push changes to the front end if they match the current filter. If the front end gets an entry not in the list, then add it to the end.

---------

Co-authored-by: Tim Haasdyk <tim_haasdyk@sil.org>
  • Loading branch information
hahn-kev and myieye authored Oct 2, 2024
1 parent e75aa06 commit 3dffa35
Show file tree
Hide file tree
Showing 39 changed files with 627 additions and 163 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ dump.sql
test-results/
**/*.sqlite
**/*.sqlite-*
msal.json
msal.cache
artifacts/
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FwDataMiniLcmBridge.LcmUtils;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace FwDataMiniLcmBridge.Tests.Fixtures;
Expand All @@ -8,6 +9,7 @@ public static class FwDataTestsKernel
public static IServiceCollection AddTestFwDataBridge(this IServiceCollection services)
{
services.AddFwDataBridge();
services.AddSingleton<IConfiguration>(_ => new ConfigurationRoot([]));
services.AddSingleton<MockFwProjectLoader>();
services.AddSingleton<IProjectLoader>(sp => sp.GetRequiredService<MockFwProjectLoader>());
services.AddSingleton<FieldWorksProjectList, MockFwProjectList>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0"/>
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
Expand Down
2 changes: 1 addition & 1 deletion backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private WritingSystem FromLcmWritingSystem(CoreWritingSystemDefinition ws)
internal void CompleteExemplars(WritingSystems writingSystems)
{
var wsExemplars = writingSystems.Vernacular.Concat(writingSystems.Analysis)
.Distinct()
.DistinctBy(ws => ws.Id)
.ToDictionary(ws => ws, ws => ws.Exemplars.Select(s => s[0]).ToHashSet());
var wsExemplarsByHandle = wsExemplars.ToFrozenDictionary(kv => GetWritingSystemHandle(kv.Key.Id), kv => kv.Value);

Expand Down
2 changes: 1 addition & 1 deletion backend/FwLite/FwDataMiniLcmBridge/FwDataBridgeKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static IServiceCollection AddFwDataBridge(this IServiceCollection service
{
services.AddMemoryCache();
services.AddLogging();
services.AddOptions<FwDataBridgeConfig>();
services.AddOptions<FwDataBridgeConfig>().BindConfiguration("FwDataBridge");
services.AddSingleton<FwDataFactory>();
services.AddSingleton<FieldWorksProjectList>();
services.AddSingleton<IProjectLoader, ProjectLoader>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="SIL.Core" Version="14.2.0-beta0009" />
<PackageReference Include="Microsoft.ICU.ICU4C.Runtime" Version="72.1.0.3" Condition="$([MSBuild]::IsOsPlatform('Windows'))" />
<PackageReference Include="SIL.LCModel" Version="11.0.0-beta0100 " />
Expand Down
2 changes: 1 addition & 1 deletion backend/FwLite/FwLiteDesktop/FwLiteDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<MauiIcon Include="Resources\AppIcon\logo_light.svg" />

<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#152747" BaseSize="512,512" />

<!-- Images -->
<MauiImage Include="Resources\Images\*" />
Expand Down
9 changes: 8 additions & 1 deletion backend/FwLite/FwLiteDesktop/FwLiteDesktopKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using LcmCrdt;
using LocalWebApp.Auth;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NReco.Logging.File;

Expand All @@ -15,7 +16,11 @@ public static void AddFwLiteDesktopServices(this IServiceCollection services,
{
services.AddSingleton<MainPage>();

var serverManager = new ServerManager(webAppBuilder =>
string environment = "Production";
#if DEBUG
environment = "Development";
#endif
var serverManager = new ServerManager(environment, webAppBuilder =>
{
webAppBuilder.Logging.AddFile(Path.Combine(FileSystem.AppDataDirectory, "web-app.log"));
webAppBuilder.Services.Configure<LcmCrdtConfig>(config =>
Expand All @@ -31,9 +36,11 @@ public static void AddFwLiteDesktopServices(this IServiceCollection services,
//using a lambda here means that the serverManager will be disposed when the app is disposed
services.AddSingleton<ServerManager>(_ => serverManager);
services.AddSingleton<IMauiInitializeService>(_ => _.GetRequiredService<ServerManager>());
services.AddSingleton<IHostEnvironment>(_ => _.GetRequiredService<ServerManager>().WebServices.GetRequiredService<IHostEnvironment>());
configuration.Add<ServerConfigSource>(source => source.ServerManager = serverManager);
services.AddOptions<LocalWebAppConfig>().BindConfiguration("LocalWebApp");
logging.AddFile(Path.Combine(FileSystem.AppDataDirectory, "app.log"));
logging.AddConsole();
#if DEBUG
logging.AddDebug();
#endif
Expand Down
2 changes: 1 addition & 1 deletion backend/FwLite/FwLiteDesktop/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="FwLiteDesktop.MainPage">

<WebView x:Name="webView"/>
<WebView x:Name="webView" IsVisible="False"/>

</ContentPage>
29 changes: 26 additions & 3 deletions backend/FwLite/FwLiteDesktop/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace FwLiteDesktop;

public partial class MainPage : ContentPage
{
public MainPage(IOptionsMonitor<LocalWebAppConfig> options, ILogger<MainPage> logger)
private readonly ILogger<MainPage> _logger;
private readonly IHostEnvironment _environment;

public MainPage(IOptionsMonitor<LocalWebAppConfig> options, ILogger<MainPage> logger, IHostEnvironment environment)
{
_logger = logger;
_environment = environment;
InitializeComponent();
options.OnChange(o =>
{
Expand Down Expand Up @@ -39,7 +45,24 @@ public MainPage(IOptionsMonitor<LocalWebAppConfig> options, ILogger<MainPage> lo
logger.LogWarning("Too many navigations, stopping");
}
}
else if (!args.Url.StartsWith("https://appdir"))
{
NavigationSuccess();
}
};
}
}

private void NavigationSuccess()
{
webView.IsVisible = true;
if (_environment.IsDevelopment())
{
_logger.LogInformation("Enabling dev mode in browser");
//lang=js
webView.Eval("""
localStorage.setItem('devMode', 'true');
if (enableDevMode) enableDevMode();
""");
}
}
}
Loading

0 comments on commit 3dffa35

Please sign in to comment.