Skip to content

Commit

Permalink
Merge pull request #51 from Luthetus/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Luthetus authored Sep 3, 2023
2 parents c6e3804 + 6852d03 commit 36a51ca
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 82 deletions.
40 changes: 3 additions & 37 deletions Source/Host/Luthetus.Ide.Photino/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
using Luthetus.Common.RazorLib.BackgroundTaskCase.Usage;
using Luthetus.Ide.ClassLib.HostedServiceCase.FileSystem;
using Luthetus.Ide.ClassLib.HostedServiceCase.Terminal;
using Luthetus.Common.RazorLib;
using Luthetus.Ide.RazorLib;
using Luthetus.TextEditor.RazorLib;
using Luthetus.TextEditor.RazorLib.HostedServiceCase.CompilerServiceCase;
using Luthetus.TextEditor.RazorLib.HostedServiceCase.TextEditorCase;
using Microsoft.Extensions.DependencyInjection;
using Photino.Blazor;
using System;
using System.Reflection.PortableExecutable;
using System.Threading;
using System.Threading.Tasks;

namespace Luthetus.Ide.Photino;

Expand All @@ -23,23 +15,13 @@ static void Main(string[] args)

appBuilder.Services.AddLogging();

appBuilder.Services.AddLuthetusIdeRazorLibServices(options => options with
{
IsNativeApplication = true,
});

appBuilder.Services.AddLuthetusIdePhotino();
var hostingInformation = new LuthetusHostingInformation(LuthetusHostingKind.Photino);
appBuilder.Services.AddLuthetusIdeRazorLibServices(hostingInformation);

appBuilder.RootComponents.Add<App>("app");

var app = appBuilder.Build();

var backgroundTasksCancellationTokenSource = new CancellationTokenSource();

var cancellationToken = backgroundTasksCancellationTokenSource.Token;

InvokeWorkers(app.Services, cancellationToken);

// customize window
app.MainWindow
.SetIconFile("favicon.ico")
Expand All @@ -53,25 +35,9 @@ static void Main(string[] args)

AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
{
backgroundTasksCancellationTokenSource.Cancel();
app.MainWindow.ShowMessage("Fatal exception", error.ExceptionObject.ToString());
};

app.Run();
}

private static void InvokeWorkers(IServiceProvider serviceProvider, CancellationToken cancellationToken)
{
var commonQueuedHostedService = serviceProvider.GetRequiredService<LuthetusCommonBackgroundTaskServiceWorker>();
var textEditorQueuedHostedService = serviceProvider.GetRequiredService<LuthetusTextEditorTextEditorBackgroundTaskServiceWorker>();
var compilerServiceQueuedHostedService = serviceProvider.GetRequiredService<LuthetusTextEditorCompilerServiceBackgroundTaskServiceWorker>();
var fileSystemQueuedHostedService = serviceProvider.GetRequiredService<LuthetusIdeFileSystemBackgroundTaskServiceWorker>();
var terminalQueuedHostedService = serviceProvider.GetRequiredService<LuthetusIdeTerminalBackgroundTaskServiceWorker>();

_ = Task.Run(async () => await commonQueuedHostedService.StartAsync(cancellationToken));
_ = Task.Run(async () => await textEditorQueuedHostedService.StartAsync(cancellationToken));
_ = Task.Run(async () => await compilerServiceQueuedHostedService.StartAsync(cancellationToken));
_ = Task.Run(async () => await fileSystemQueuedHostedService.StartAsync(cancellationToken));
_ = Task.Run(async () => await terminalQueuedHostedService.StartAsync(cancellationToken));
}
}
27 changes: 0 additions & 27 deletions Source/Host/Luthetus.Ide.Photino/ServiceCollectionExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Luthetus.Common.RazorLib.BackgroundTaskCase.BaseTypes;
using Luthetus.Common.RazorLib.BackgroundTaskCase.Usage;
using Luthetus.Ide.ClassLib.HostedServiceCase.FileSystem;
using Luthetus.Ide.ClassLib.HostedServiceCase.Terminal;
using Luthetus.TextEditor.RazorLib.HostedServiceCase.CompilerServiceCase;
using Luthetus.TextEditor.RazorLib.HostedServiceCase.TextEditorCase;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;

namespace Luthetus.Ide.RazorLib.BackgroundServiceCase;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Fluxor;
using Fluxor.Blazor.Web.Components;
using Luthetus.Common.RazorLib;
using Luthetus.Common.RazorLib.ComponentRenderers;
using Luthetus.Common.RazorLib.ComponentRenderers.Types;
using Luthetus.Common.RazorLib.Dialog;
Expand Down Expand Up @@ -44,6 +45,8 @@ public partial class CSharpProjectFormDisplay : FluxorComponent
private LuthetusIdeOptions LuthetusIdeOptions { get; set; } = null!;
[Inject]
private ITextEditorService TextEditorService { get; set; } = null!;
[Inject]
private LuthetusHostingInformation LuthetusHostingInformation { get; set; } = null!;

[CascadingParameter]
public DialogRecord DialogRecord { get; set; } = null!;
Expand Down Expand Up @@ -137,7 +140,7 @@ private void RequestInputFileForParentDirectory(string message)

private async Task ReadProjectTemplates()
{
if (!LuthetusIdeOptions.IsNativeApplication)
if (LuthetusHostingInformation.LuthetusHostingKind != LuthetusHostingKind.Photino)
await HackForWebsite_ReadProjectTemplates();
else
await FormatDotNetNewListAsync();
Expand Down Expand Up @@ -406,7 +409,7 @@ private async Task StartNewCSharpProjectCommandOnClick()
return;
}

if (!LuthetusIdeOptions.IsNativeApplication)
if (LuthetusHostingInformation.LuthetusHostingKind != LuthetusHostingKind.Photino)
{
await HackForWebsite_StartNewCSharpProjectCommandOnClick(
localProjectTemplateShortName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Fluxor;
using Fluxor.Blazor.Web.Components;
using Luthetus.Common.RazorLib;
using Luthetus.Common.RazorLib.ComponentRenderers;
using Luthetus.Common.RazorLib.ComponentRenderers.Types;
using Luthetus.Common.RazorLib.Dialog;
Expand Down Expand Up @@ -33,6 +34,8 @@ public partial class DotNetSolutionFormDisplay : FluxorComponent
private LuthetusIdeOptions LuthetusIdeOptions { get; set; } = null!;
[Inject]
private ILuthetusCommonComponentRenderers LuthetusCommonComponentRenderers { get; set; } = null!;
[Inject]
private LuthetusHostingInformation LuthetusHostingInformation { get; set; } = null!;

[CascadingParameter]
public DialogRecord DialogRecord { get; set; } = null!;
Expand Down Expand Up @@ -93,7 +96,7 @@ private async Task StartNewDotNetSolutionCommandOnClick()
return;
}

if (!LuthetusIdeOptions.IsNativeApplication)
if (LuthetusHostingInformation.LuthetusHostingKind != LuthetusHostingKind.Photino)
{
await HackForWebsite_StartNewDotNetSolutionCommandOnClick(
localSolutionName,
Expand Down
14 changes: 14 additions & 0 deletions Source/Lib/Luthetus.Ide.RazorLib/LuthetusIdeInitializer.razor.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Fluxor;
using Luthetus.Common.RazorLib;
using Luthetus.Common.RazorLib.ComponentRenderers;
using Luthetus.Common.RazorLib.FileSystem.Interfaces;
using Luthetus.Common.RazorLib.Icons.Codicon;
using Luthetus.Common.RazorLib.Store.ThemeCase;
using Luthetus.Ide.ClassLib.HostedServiceCase.FileSystem;
using Luthetus.Ide.ClassLib.HostedServiceCase.Terminal;
using Luthetus.Ide.ClassLib.Panel;
using Luthetus.Ide.ClassLib.Store.PanelCase;
Expand Down Expand Up @@ -33,9 +35,21 @@ public partial class LuthetusIdeInitializer : ComponentBase
private ILuthetusIdeTerminalBackgroundTaskService TerminalBackgroundTaskQueue { get; set; } = null!;
[Inject]
private ILuthetusCommonComponentRenderers LuthetusCommonComponentRenderers { get; set; } = null!;
[Inject]
private LuthetusHostingInformation LuthetusHostingInformation { get; set; } = null!;
[Inject]
private LuthetusIdeFileSystemBackgroundTaskServiceWorker LuthetusIdeFileSystemBackgroundTaskServiceWorker { get; set; } = null!;
[Inject]
private LuthetusIdeTerminalBackgroundTaskServiceWorker LuthetusIdeTerminalBackgroundTaskServiceWorker { get; set; } = null!;

protected override void OnInitialized()
{
if (LuthetusHostingInformation.LuthetusHostingKind != LuthetusHostingKind.ServerSide)
{
_ = Task.Run(async () => await LuthetusIdeFileSystemBackgroundTaskServiceWorker.StartAsync(CancellationToken.None));
_ = Task.Run(async () => await LuthetusIdeTerminalBackgroundTaskServiceWorker.StartAsync(CancellationToken.None));
}

if (LuthetusTextEditorOptions.CustomThemeRecords is not null)
{
foreach (var themeRecord in LuthetusTextEditorOptions.CustomThemeRecords)
Expand Down
1 change: 0 additions & 1 deletion Source/Lib/Luthetus.Ide.RazorLib/LuthetusIdeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

public record LuthetusIdeOptions
{
public bool IsNativeApplication { get; init; }
/// <summary>Default value is <see cref="true"/>. If one wishes to configure Luthetus.TextEditor themselves, then set this to false, and invoke <see cref="Luthetus.TextEditor.RazorLib.ServiceCollectionExtensions.AddLuthetusTextEditor(Microsoft.Extensions.DependencyInjection.IServiceCollection, Func{TextEditor.RazorLib.LuthetusTextEditorOptions, TextEditor.RazorLib.LuthetusTextEditorOptions}?)"/> prior to invoking Luthetus.TextEditor's</summary>
public bool AddLuthetusTextEditor { get; init; } = true;
}
20 changes: 17 additions & 3 deletions Source/Lib/Luthetus.Ide.RazorLib/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
using Luthetus.Common.RazorLib.FileSystem.Interfaces;
using Luthetus.Common.RazorLib.FileSystem.Classes.Local;
using Luthetus.Common.RazorLib.FileSystem.Classes.InMemoryFileSystem;
using Luthetus.Common.RazorLib;
using Luthetus.Ide.ClassLib.HostedServiceCase.FileSystem;
using Luthetus.Ide.ClassLib.HostedServiceCase.Terminal;

namespace Luthetus.Ide.RazorLib;

public static class ServiceCollectionExtensions
{
public static IServiceCollection AddLuthetusIdeRazorLibServices(
this IServiceCollection services,
LuthetusHostingInformation hostingInformation,
Func<LuthetusIdeOptions, LuthetusIdeOptions>? configure = null)
{
var ideOptions = new LuthetusIdeOptions();
Expand All @@ -28,28 +32,38 @@ public static IServiceCollection AddLuthetusIdeRazorLibServices(

if (ideOptions.AddLuthetusTextEditor)
{
services.AddLuthetusTextEditor(inTextEditorOptions => inTextEditorOptions with
services.AddLuthetusTextEditor(hostingInformation, inTextEditorOptions => inTextEditorOptions with
{
CustomThemeRecords = LuthetusTextEditorCustomThemeFacts.AllCustomThemes,
InitialThemeKey = LuthetusTextEditorCustomThemeFacts.DarkTheme.ThemeKey,
});
}

if (hostingInformation.LuthetusHostingKind == LuthetusHostingKind.ServerSide)
{
services
.AddHostedService(sp => sp.GetRequiredService<LuthetusIdeFileSystemBackgroundTaskServiceWorker>())
.AddHostedService(sp => sp.GetRequiredService<LuthetusIdeTerminalBackgroundTaskServiceWorker>());
}

return services
.AddSingleton(ideOptions)
.AddSingleton<LuthetusIdeFileSystemBackgroundTaskServiceWorker>()
.AddSingleton<LuthetusIdeTerminalBackgroundTaskServiceWorker>()
.AddSingleton<ILuthetusIdeComponentRenderers>(_ideComponentRenderers)
.AddLuthetusIdeFileSystem(ideOptions)
.AddLuthetusIdeFileSystem(hostingInformation, ideOptions)
.AddLuthetusIdeClassLibServices();
}

private static IServiceCollection AddLuthetusIdeFileSystem(
this IServiceCollection services,
LuthetusHostingInformation hostingInformation,
LuthetusIdeOptions ideOptions)
{
Func<IServiceProvider, IEnvironmentProvider> environmentProviderFactory;
Func<IServiceProvider, IFileSystemProvider> fileSystemProviderFactory;

if (ideOptions.IsNativeApplication)
if (hostingInformation.LuthetusHostingKind == LuthetusHostingKind.Photino)
{
environmentProviderFactory = _ => new LocalEnvironmentProvider();
fileSystemProviderFactory = _ => new LocalFileSystemProvider();
Expand Down
11 changes: 4 additions & 7 deletions Source/Lib/Luthetus.Ide.RazorLib/Shared/IdeMainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
@using Luthetus.TextEditor.RazorLib
@using Luthetus.Common.RazorLib.Drag
@using Luthetus.Common.RazorLib.Dialog
@using Luthetus.Common.RazorLib
@using Luthetus.TextEditor.RazorLib
@using Luthetus.Common.RazorLib.Dimensions
@using Luthetus.Common.RazorLib.Notification
@using Luthetus.Common.RazorLib.Resize
@using Luthetus.Ide.ClassLib.Context
@using Luthetus.Ide.RazorLib.ContextCase
Expand All @@ -18,9 +16,8 @@
StyleCssString="@($"{AppOptionsService.FontSizeCssStyleString} {AppOptionsService.FontFamilyCssStyleString}")">

<ShouldRenderBoundary>
<DragInitializer/>
<DialogInitializer/>
<NotificationInitializer/>
<LuthetusCommonInitializer/>
<LuthetusTextEditorInitializer/>
<LuthetusIdeInitializer/>

<IdeHeader/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public LuthetusFileSystemTestingBase()

services.AddScoped<IJSRuntime>(_ => new DoNothingJsRuntime());

services.AddLuthetusCommonServices(commonOptions =>
var hostingInformation = new LuthetusHostingInformation(LuthetusHostingKind.UnitTest);

services.AddLuthetusCommonServices(hostingInformation, commonOptions =>
{
var outLuthetusCommonFactories = commonOptions.LuthetusCommonFactories with
{
Expand All @@ -41,7 +43,7 @@ public LuthetusFileSystemTestingBase()
};
});

services.AddLuthetusTextEditor(inTextEditorOptions => inTextEditorOptions with
services.AddLuthetusTextEditor(hostingInformation, inTextEditorOptions => inTextEditorOptions with
{
AddLuthetusCommon = false
});
Expand Down

0 comments on commit 36a51ca

Please sign in to comment.