-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start server on app startup, navigate to url on app start
- Loading branch information
Showing
11 changed files
with
199 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="FwLiteDesktop.MainPage"> | ||
|
||
<ScrollView> | ||
<VerticalStackLayout | ||
Padding="30,0" | ||
Spacing="25"> | ||
<WebView Source=""/> | ||
</VerticalStackLayout> | ||
</ScrollView> | ||
<WebView x:Name="webView"/> | ||
|
||
</ContentPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
namespace FwLiteDesktop; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace FwLiteDesktop; | ||
|
||
public partial class MainPage : ContentPage | ||
{ | ||
public MainPage() | ||
public MainPage(IOptionsMonitor<LocalWebAppConfig> options) | ||
{ | ||
InitializeComponent(); | ||
options.OnChange(o => | ||
{ | ||
webView.Dispatcher.Dispatch(() => webView.Source = o.Url); | ||
}); | ||
webView.Source = options.CurrentValue.Url; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
backend/FwLite/FwLiteDesktop/ServerBridge/ServerConfigProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace FwLiteDesktop.ServerBridge; | ||
|
||
public class ServerConfigSource: IConfigurationSource | ||
{ | ||
public ServerManager? ServerManager { get; set; } | ||
|
||
public IConfigurationProvider Build(IConfigurationBuilder builder) | ||
{ | ||
if (ServerManager is null) | ||
throw new InvalidOperationException("ServerManager is not set"); | ||
return new ServerConfigProvider(ServerManager); | ||
} | ||
} | ||
|
||
public class ServerConfigProvider : ConfigurationProvider | ||
{ | ||
public ServerConfigProvider(ServerManager serverManager) | ||
{ | ||
_ = serverManager.Started.ContinueWith(t => | ||
{ | ||
Data = new Dictionary<string, string?> { ["LocalWebApp:Url"] = t.Result.Urls.First() }; | ||
OnReload(); | ||
}, | ||
scheduler: TaskScheduler.Default); | ||
} | ||
|
||
public override void Load() | ||
{ | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
backend/FwLite/FwLiteDesktop/ServerBridge/ServerManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using LocalWebApp; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace FwLiteDesktop; | ||
|
||
public class ServerManager : IAsyncDisposable | ||
{ | ||
private readonly TaskCompletionSource<WebApplication> _started = new(); | ||
public Task<WebApplication> Started => _started.Task; | ||
private WebApplication? _webApp; | ||
|
||
public void Start() | ||
{ | ||
_webApp = LocalWebAppServer.SetupAppServer([]); | ||
_ = Task.Run(async () => | ||
{ | ||
try | ||
{ | ||
await _webApp.StartAsync(); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e); | ||
throw; | ||
} | ||
|
||
_started.SetResult(_webApp); | ||
}); | ||
} | ||
|
||
public async ValueTask DisposeAsync() | ||
{ | ||
if (_webApp is null) return; | ||
await _webApp.StopAsync(TimeSpan.FromSeconds(10)); | ||
await _webApp.DisposeAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#if !DISABLE_FW_BRIDGE | ||
using FwDataMiniLcmBridge; | ||
using FwDataMiniLcmBridge.LcmUtils; | ||
#endif | ||
using LcmCrdt; | ||
using LocalWebApp; | ||
using LocalWebApp.Hubs; | ||
using LocalWebApp.Auth; | ||
using LocalWebApp.Routes; | ||
using LocalWebApp.Utils; | ||
using Microsoft.AspNetCore.SignalR; | ||
using Microsoft.AspNetCore.StaticFiles.Infrastructure; | ||
using Microsoft.Extensions.FileProviders; | ||
|
||
namespace LocalWebApp; | ||
|
||
public static class LocalWebAppServer | ||
{ | ||
public static WebApplication SetupAppServer(string[] args) | ||
{ | ||
var builder = WebApplication.CreateBuilder(args); | ||
if (!builder.Environment.IsDevelopment()) | ||
builder.WebHost.UseUrls("http://127.0.0.1:0"); | ||
if (builder.Environment.IsDevelopment()) | ||
{ | ||
#if !DISABLE_FW_BRIDGE | ||
//do this early so we catch bugs on startup | ||
ProjectLoader.Init(); | ||
#endif | ||
} | ||
|
||
builder.ConfigureDev<AuthConfig>(config => | ||
config.DefaultAuthority = new("https://lexbox.dev.languagetechnology.org")); | ||
//for now prod builds will also use lt dev until we deploy oauth to prod | ||
builder.ConfigureProd<AuthConfig>(config => | ||
config.DefaultAuthority = new("https://lexbox.dev.languagetechnology.org")); | ||
builder.Services.Configure<AuthConfig>(c => c.ClientId = "becf2856-0690-434b-b192-a4032b72067f"); | ||
|
||
builder.Services.AddLocalAppServices(builder.Environment); | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
builder.Services.AddSignalR(options => | ||
{ | ||
options.AddFilter(new LockedProjectFilter()); | ||
options.EnableDetailedErrors = true; | ||
}).AddJsonProtocol(); | ||
|
||
var app = builder.Build(); | ||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
//configure dotnet to serve static files from the embedded resources | ||
var sharedOptions = | ||
new SharedOptions() { FileProvider = new ManifestEmbeddedFileProvider(typeof(Program).Assembly) }; | ||
app.UseDefaultFiles(new DefaultFilesOptions(sharedOptions)); | ||
var staticFileOptions = new StaticFileOptions(sharedOptions); | ||
app.UseStaticFiles(staticFileOptions); | ||
|
||
app.Use(async (context, next) => | ||
{ | ||
var projectName = context.GetProjectName(); | ||
if (!string.IsNullOrWhiteSpace(projectName)) | ||
{ | ||
var projectsService = context.RequestServices.GetRequiredService<ProjectsService>(); | ||
projectsService.SetProjectScope(projectsService.GetProject(projectName) ?? | ||
throw new InvalidOperationException( | ||
$"Project {projectName} not found")); | ||
await context.RequestServices.GetRequiredService<CurrentProjectService>().PopulateProjectDataCache(); | ||
} | ||
#if !DISABLE_FW_BRIDGE | ||
var fwData = context.GetFwDataName(); | ||
if (!string.IsNullOrWhiteSpace(fwData)) | ||
{ | ||
var fwDataProjectContext = context.RequestServices.GetRequiredService<FwDataProjectContext>(); | ||
fwDataProjectContext.Project = | ||
FieldWorksProjectList.GetProject(fwData) ?? throw new InvalidOperationException($"FwData {fwData} not found"); | ||
} | ||
#endif | ||
|
||
await next(context); | ||
}); | ||
app.MapHub<CrdtMiniLcmApiHub>($"/api/hub/{{{CrdtMiniLcmApiHub.ProjectRouteKey}}}/lexbox"); | ||
#if !DISABLE_FW_BRIDGE | ||
app.MapHub<FwDataMiniLcmHub>($"/api/hub/{{{FwDataMiniLcmHub.ProjectRouteKey}}}/fwdata"); | ||
#endif | ||
app.MapHistoryRoutes(); | ||
app.MapActivities(); | ||
app.MapProjectRoutes(); | ||
app.MapFwIntegrationRoutes(); | ||
app.MapTest(); | ||
app.MapImport(); | ||
app.MapAuthRoutes(); | ||
app.MapFallbackToFile("index.html", staticFileOptions); | ||
return app; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters