Skip to content

Commit

Permalink
Merge branch 'main' into evan/task25
Browse files Browse the repository at this point in the history
  • Loading branch information
BeepBeepBopBop committed Nov 25, 2024
2 parents d4c62cf + 4e4593a commit 9bc658c
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 86 deletions.
9 changes: 3 additions & 6 deletions LM-Kit-Maestro/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Majorsoft.Blazor.Components.Common.JsInterop;
using Mopups.Hosting;
using Mopups.Services;
using CommunityToolkit.Maui.Storage;

namespace LMKit.Maestro
{
Expand Down Expand Up @@ -93,18 +94,14 @@ private static void RegisterServices(this MauiAppBuilder builder)
builder.Services.AddSingleton<ILLMFileManager, LLMFileManager>();
builder.Services.AddSingleton<IAppSettingsService, AppSettingsService>();
builder.Services.AddSingleton<IPopupService, Services.PopupService>();
builder.Services.AddSingleton<Services.ILauncher, Services.Launcher>();
builder.Services.AddSingleton<INavigationService, NavigationService>();
builder.Services.AddSingleton<IMainThread, Services.MainThread>();
builder.Services
.AddSingleton<CommunityToolkit.Maui.Core.IPopupService, CommunityToolkit.Maui.PopupService>();

#if WINDOWS
builder.Services.AddSingleton<IFolderPicker, WinUI.FolderPicker>();
#elif MACCATALYST
builder.Services.AddSingleton<IFolderPicker, LMKit.Maestro.MacFolderPicker>();
#endif
builder.Services.AddSingleton<IFolderPicker>(FolderPicker.Default);

builder.Services.AddSingleton(Launcher.Default);
builder.Services.AddSingleton(Preferences.Default);
builder.Services.AddSingleton<LMKitService>();
builder.Services.AddSingleton<LLMFileManager>();
Expand Down
7 changes: 6 additions & 1 deletion LM-Kit-Maestro/Platforms/MacCatalyst/Entitlements.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<!-- When App Sandbox is enabled, this value is required to open outgoing network connections. -->
<key>com.apple.security.network.client</key>
<true/>

<!-- The entitlements below are mandatory to use CommunityToolkit FolderPicker service on Mac. -->
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
</dict>
</plist>

7 changes: 7 additions & 0 deletions LM-Kit-Maestro/Platforms/MacCatalyst/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,12 @@
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/appicon.appiconset</string>

<!--Mandatory to use CommunityToolkit Launcher service-->
<key>LSApplicationQueriesSchemes</key>
<array>
<string>lyft</string>
<string>fb</string>
</array>
</dict>
</plist>
11 changes: 0 additions & 11 deletions LM-Kit-Maestro/Platforms/MacCatalyst/MacFolderPicker.cs

This file was deleted.

14 changes: 0 additions & 14 deletions LM-Kit-Maestro/Platforms/Windows/FolderPicker.cs

This file was deleted.

17 changes: 0 additions & 17 deletions LM-Kit-Maestro/Services/FolderPickerResult.cs

This file was deleted.

6 changes: 0 additions & 6 deletions LM-Kit-Maestro/Services/Interfaces/IFolderPicker.cs

This file was deleted.

6 changes: 0 additions & 6 deletions LM-Kit-Maestro/Services/Interfaces/ILauncher.cs

This file was deleted.

9 changes: 0 additions & 9 deletions LM-Kit-Maestro/Services/Launcher.cs

This file was deleted.

37 changes: 21 additions & 16 deletions LM-Kit-Maestro/ViewModels/Pages/ModelsPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,34 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Mopups.Interfaces;
using CommunityToolkit.Maui.Storage;

namespace LMKit.Maestro.ViewModels;

public partial class ModelsPageViewModel : PageViewModelBase
{
private readonly IFolderPicker _folderPicker;
private readonly IPopupService _popupService;
private readonly Services.ILauncher _launcher;
private readonly ILauncher _launcher;
private readonly LMKitService _lmKitService;
private readonly IMainThread _mainThread;

public ILLMFileManager FileManager { get; }
public IAppSettingsService AppSettingsService { get; }
public ModelListViewModel ModelListViewModel { get; }

[ObservableProperty]
long _totalModelSize;
[ObservableProperty] long _totalModelSize;

public ModelsPageViewModel(INavigationService navigationService, IFolderPicker folderPicker, Services.ILauncher launcher,
IPopupService popupService, IPopupNavigation popupNavigation, ILLMFileManager llmFileManager, LMKitService lmKitService,
IAppSettingsService appSettingsService, ModelListViewModel modelListViewModel) : base(navigationService, popupService, popupNavigation)
public ModelsPageViewModel(INavigationService navigationService, IFolderPicker folderPicker,
ILauncher launcher, IMainThread mainThread,
IPopupService popupService, IPopupNavigation popupNavigation, ILLMFileManager llmFileManager,
LMKitService lmKitService,
IAppSettingsService appSettingsService, ModelListViewModel modelListViewModel) : base(navigationService,
popupService, popupNavigation)
{
_folderPicker = folderPicker;
_launcher = launcher;
_mainThread = mainThread;
_lmKitService = lmKitService;
_popupService = popupService;
FileManager = llmFileManager;
Expand All @@ -42,7 +47,8 @@ public ModelsPageViewModel(INavigationService navigationService, IFolderPicker f
public void DownloadModel(ModelInfoViewModel modelInfoViewModel)
{
modelInfoViewModel.DownloadInfo.Status = DownloadStatus.Downloading;
modelInfoViewModel.ModelInfo.Metadata.FileUri = FileHelpers.GetModelFileUri(modelInfoViewModel.ModelInfo, AppSettingsService.ModelsFolderPath);
modelInfoViewModel.ModelInfo.Metadata.FileUri =
FileHelpers.GetModelFileUri(modelInfoViewModel.ModelInfo, AppSettingsService.ModelsFolderPath);

FileManager.DownloadModel(modelInfoViewModel.ModelInfo);
}
Expand Down Expand Up @@ -81,25 +87,26 @@ public void DeleteModel(ModelInfoViewModel modelInfoViewModel)
}
catch (Exception ex)
{
_popupService.DisplayAlert("Failure to delete model file", $"The model file could not be deleted:\n {ex.Message}", "OK");
_popupService.DisplayAlert("Failure to delete model file",
$"The model file could not be deleted:\n {ex.Message}", "OK");
}
}

[RelayCommand]
public void PickModelsFolder()
private void PickModelsFolder()
{
Task.Run(async () =>
_mainThread.BeginInvokeOnMainThread(async () =>
{
var result = await _folderPicker.PickAsync(AppSettingsService.ModelsFolderPath);
if (result.Success)
if (result.IsSuccessful)
{
if (_lmKitService.ModelLoadingState != LMKitModelLoadingState.Unloaded)
{
_lmKitService.UnloadModel();
}
AppSettingsService.ModelsFolderPath = result.FolderPath!;
AppSettingsService.ModelsFolderPath = result.Folder.Path!;
}
});
}
Expand All @@ -109,11 +116,10 @@ public async Task OpenModelsFolder()
{
try
{
await _launcher.OpenAsync(new Uri(AppSettingsService.ModelsFolderPath));
await _launcher.OpenAsync(new Uri($"file://{AppSettingsService.ModelsFolderPath}"));
}
catch
catch (Exception exception)
{

}
}

Expand All @@ -126,7 +132,6 @@ public async Task OpenHuggingFaceLink()
}
catch
{

}
}

Expand Down

0 comments on commit 9bc658c

Please sign in to comment.