Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New home fw lite for mobile #1351

Merged
merged 21 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ artifacts/
backend/FwLite/FwLiteShared/wwwroot/viewer

*.csproj.user
*.log
15 changes: 2 additions & 13 deletions backend/FwLite/FwLiteMaui/AppVersion.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
using System.Reflection;
using FwLiteShared.Services;

namespace FwLiteMaui;

public class AppVersion
{
static AppVersion()
{
var infoVersion = typeof(AppVersion).Assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
//info version may look like v2024-12-12-3073dd1c+3073dd1ce2ff5510f54a9411366f55c958b9ea45. We want to strip off everything after the +, so we can compare versions
if (infoVersion is not null && infoVersion.Contains('+'))
{
infoVersion = infoVersion[..infoVersion.IndexOf('+')];
}
Version = infoVersion ?? "dev";
}

public static readonly string Version;
public static readonly string Version = VersionHelper.DisplayVersion(typeof(AppVersion).Assembly);
}
26 changes: 25 additions & 1 deletion backend/FwLite/FwLiteMaui/FwLiteMauiKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void AddFwLiteMauiServices(this IServiceCollection services,
FwLiteProjectSync.FwLiteProjectSyncKernel.AddFwLiteProjectSync(services);
#endif
#if WINDOWS
services.AddFwLiteWindows();
services.AddFwLiteWindows(env);
#endif
#if ANDROID
services.Configure<AuthConfig>(config => config.ParentActivityOrWindow = Platform.CurrentActivity);
Expand All @@ -51,6 +51,30 @@ public static void AddFwLiteMauiServices(this IServiceCollection services,
var window = Application.Current?.Windows.FirstOrDefault();
if (window is not null) Application.Current?.ActivateWindow(window);
});
services.Configure<FwLiteConfig>(config =>
{
config.AppVersion = AppVersion.Version;
if (DeviceInfo.Current.Platform == DevicePlatform.Android)
{
config.Os = FwLitePlatform.Android;
}
else if (DeviceInfo.Current.Platform == DevicePlatform.iOS)
{
config.Os = FwLitePlatform.iOS;
}
else if (DeviceInfo.Current.Platform == DevicePlatform.macOS)
{
config.Os = FwLitePlatform.Mac;
}
else if (DeviceInfo.Current.Platform == DevicePlatform.WinUI)
{
config.Os = FwLitePlatform.Windows;
}
else
{
config.Os = FwLitePlatform.Other;
}
});

var defaultDataPath = IsPortableApp ? Directory.GetCurrentDirectory() : FileSystem.AppDataDirectory;
var baseDataPath = Path.GetFullPath(configuration.GetSection("FwLiteMaui").GetValue<string>("BaseDataDir") ??
Expand Down
8 changes: 7 additions & 1 deletion backend/FwLite/FwLiteMaui/Platforms/Windows/WindowsKernel.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
using System.Runtime.InteropServices;
using FwLiteShared;
using Microsoft.Extensions.Hosting;

namespace FwLiteMaui;

public static class WindowsKernel
{
public static void AddFwLiteWindows(this IServiceCollection services)
public static void AddFwLiteWindows(this IServiceCollection services, IHostEnvironment environment)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return;
if (!FwLiteMauiKernel.IsPortableApp)
{
services.AddSingleton<IMauiInitializeService, AppUpdateService>();
services.AddSingleton<IMauiInitializeService, WindowsShortcutService>();
}
services.Configure<FwLiteConfig>(config =>
{
config.UseDevAssets = environment.IsDevelopment();
});
}
}
762 changes: 0 additions & 762 deletions backend/FwLite/FwLiteMaui/app.log

This file was deleted.

28 changes: 28 additions & 0 deletions backend/FwLite/FwLiteShared/FwLiteConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Runtime.InteropServices;

namespace FwLiteShared;

public class FwLiteConfig
{
public bool UseDevAssets { get; set; } = false;
public string AppVersion { get; set; } = "Unknown";
public FwLitePlatform Os { get; set; } = Environment.OSVersion.Platform switch {
PlatformID.Win32NT => FwLitePlatform.Windows,
PlatformID.Unix => FwLitePlatform.Linux,
PlatformID.MacOSX => FwLitePlatform.Mac,
_ => FwLitePlatform.Other
};
public string FeedbackUrl => $"https://docs.google.com/forms/d/e/1FAIpQLSdUdNufT3sdoBscY7vixguYnvtgpaw-hjX-z54BKi9KlYv4vw/viewform?usp=pp_url&entry.2102942583={AppVersion}&entry.1772086822={Os}";
}

public enum FwLitePlatform
{
Windows,
Linux,
Mac,
Other,
Android,
// ReSharper disable once InconsistentNaming
iOS,
Web
}
1 change: 1 addition & 0 deletions backend/FwLite/FwLiteShared/FwLiteSharedKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static IServiceCollection AddFwLiteShared(this IServiceCollection service
services.AddSingleton<ChangeEventBus>();
services.AddSingleton<BackgroundSyncService>();
services.AddSingleton<IHostedService>(s => s.GetRequiredService<BackgroundSyncService>());
services.AddOptions<FwLiteConfig>();
return services;
}

Expand Down
5 changes: 3 additions & 2 deletions backend/FwLite/FwLiteShared/Layout/SvelteLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
@using FwLiteShared.Services
@using Microsoft.Extensions.Hosting
@using Microsoft.Extensions.Logging
@using Microsoft.Extensions.Options
@inject IJSRuntime JS
@inject ILogger<SvelteLayout> Logger
@inject FwLiteProvider FwLiteProvider
@inject IHostEnvironment Environment;
@inject IOptions<FwLiteConfig> Config;
@implements IAsyncDisposable
@if (useDevAssets)
{
Expand Down Expand Up @@ -44,7 +45,7 @@ else
@Body

@code {
private bool useDevAssets => Environment.IsDevelopment();
private bool useDevAssets => Config.Value.UseDevAssets;
// private bool useDevAssets => false;
private IJSObjectReference? module;

Expand Down
27 changes: 21 additions & 6 deletions backend/FwLite/FwLiteShared/Services/FwLiteProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using LexCore.Utils;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.JSInterop;
using MiniLcm.Models;
using MiniLcm.Project;
Expand All @@ -20,7 +21,8 @@ public class FwLiteProvider(
LexboxProjectService lexboxProjectService,
ChangeEventBus changeEventBus,
IEnumerable<IProjectProvider> projectProviders,
ILogger<FwLiteProvider> logger
ILogger<FwLiteProvider> logger,
IOptions<FwLiteConfig> config
) : IDisposable
{
public const string OverrideServiceFunctionName = "setOverrideService";
Expand Down Expand Up @@ -50,26 +52,38 @@ public object GetService(DotnetService service)
DotnetService.CombinedProjectsService => projectService,
DotnetService.AuthService => authService,
DotnetService.ImportFwdataService => importFwdataService,
DotnetService.FwLiteConfig => config.Value,
_ => throw new ArgumentOutOfRangeException(nameof(service), service, null)
};
}

public async Task<IDisposable?> SetService(IJSRuntime jsRuntime, DotnetService service, object? serviceInstance)
{
DotNetObjectReference<object>? reference = null;
if (serviceInstance is not null)
if (serviceInstance is null)
{
reference = DotNetObjectReference.Create(serviceInstance);
logger.LogInformation("Clearing Service {Service}", service);
}
else
if (ShouldConvertToDotnetObject(service, serviceInstance))
{
logger.LogInformation("Clearing Service {Service}", service);
reference = DotNetObjectReference.Create(serviceInstance);
serviceInstance = reference;
}

await jsRuntime.DurableInvokeVoidAsync(OverrideServiceFunctionName, service.ToString(), reference);
await jsRuntime.DurableInvokeVoidAsync(OverrideServiceFunctionName, service.ToString(), serviceInstance);
return reference;
}


private bool ShouldConvertToDotnetObject(DotnetService service, [NotNullWhen(true)] object? serviceInstance)
{
return serviceInstance is not null && service switch
{
DotnetService.FwLiteConfig => false,
_ => true
};
}

public async Task<IAsyncDisposable> InjectCrdtProject(IJSRuntime jsRuntime,
IServiceProvider scopedServices,
string projectName)
Expand Down Expand Up @@ -114,4 +128,5 @@ public enum DotnetService
CombinedProjectsService,
AuthService,
ImportFwdataService,
FwLiteConfig,
}
18 changes: 18 additions & 0 deletions backend/FwLite/FwLiteShared/Services/VersionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Reflection;

namespace FwLiteShared.Services;

public class VersionHelper
{
public static string DisplayVersion(Assembly assembly)
{
var infoVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
//info version may look like v2024-12-12-3073dd1c+3073dd1ce2ff5510f54a9411366f55c958b9ea45. We want to strip off everything after the +, so we can compare versions
if (infoVersion is not null && infoVersion.Contains('+'))
{
infoVersion = infoVersion[..infoVersion.IndexOf('+')];
}

return infoVersion ?? "dev";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public static void Configure(ConfigurationBuilder builder)
builder.ExportAsInterface<CrdtProject>().WithPublicProperties();
builder.ExportAsInterface<ProjectData>().WithPublicProperties();
builder.ExportAsInterface<IProjectIdentifier>().WithPublicProperties();
builder.ExportAsInterface<FwLiteConfig>().WithPublicProperties();
builder.ExportAsEnum<FwLitePlatform>().UseString();
builder.ExportAsEnum<ProjectDataFormat>();
}

Expand Down
10 changes: 9 additions & 1 deletion backend/FwLite/FwLiteWeb/FwLiteWebKernel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using SIL.Harmony;
using FwDataMiniLcmBridge;
using FwLiteProjectSync;
using SIL.Harmony;
using FwLiteShared;
using FwLiteShared.Auth;
using LcmCrdt;
Expand All @@ -16,7 +18,13 @@ public static IServiceCollection AddFwLiteWebServices(this IServiceCollection se
services.AddHttpContextAccessor();
services.AddSingleton<UrlContext>();
services.AddSingleton<IRedirectUrlProvider, ServerRedirectUrlProvider>();
services.AddFwDataBridge();
services.AddFwLiteProjectSync();
services.AddFwLiteShared(environment);
if (environment.IsDevelopment())
{
services.Configure<FwLiteConfig>(config => config.UseDevAssets = true);
}

services.AddOptions<FwLiteWebConfig>().BindConfiguration("FwLiteWeb");

Expand Down
8 changes: 7 additions & 1 deletion backend/FwLite/FwLiteWeb/FwLiteWebServer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using FwDataMiniLcmBridge;
using FwDataMiniLcmBridge.LcmUtils;
using FwLiteShared;
using FwLiteShared.Auth;
using FwLiteShared.Services;
using LcmCrdt;
using FwLiteWeb;
using FwLiteWeb.Components;
Expand Down Expand Up @@ -36,7 +38,11 @@ public static WebApplication SetupAppServer(WebApplicationOptions options, Actio
]);
builder.ConfigureProd<AuthConfig>(config =>
config.LexboxServers = [new(new("https://staging.languagedepot.org"), "Lexbox Staging")]);
builder.Services.Configure<AuthConfig>(c => c.ClientId = "becf2856-0690-434b-b192-a4032b72067f");
builder.Services.Configure<FwLiteConfig>(config =>
{
config.AppVersion = VersionHelper.DisplayVersion(typeof(FwLiteWebServer).Assembly);
//todo os should be web, when the server is running remotely to the client, but linux runs the server locally so we will default using the OS to determine the platform (the default value)
});
builder.Logging.AddDebug();
builder.Services.AddRazorComponents().AddInteractiveServerComponents(circuitOptions => circuitOptions.DetailedErrors = true);
if (builder.Configuration.GetValue<string>("FwLiteWeb:LogFileName") is { Length: > 0 } logFileName)
Expand Down
6 changes: 5 additions & 1 deletion frontend/viewer/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<script lang="ts">
import {Router, Route} from 'svelte-routing';
import TestProjectView from './TestProjectView.svelte';
import FwDataProjectView from './FwDataProjectView.svelte';
import HomeView from './HomeView.svelte';
import NotificationOutlet from './lib/notifications/NotificationOutlet.svelte';
import Sandbox from './lib/sandbox/Sandbox.svelte';
Expand All @@ -26,6 +25,11 @@
/* eslint-disable @typescript-eslint/naming-convention */
settings({
components: {
AppBar: {
classes: {
root: 'max-sm:px-2',
},
},
MenuItem: {
classes: {
root: 'justify-end',
Expand Down
Loading
Loading