summaryrefslogtreecommitdiff
path: root/JVDesktop
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-01-13 08:22:09 +0800
committer魏曹先生 <1992414357@qq.com>2026-01-13 08:22:09 +0800
commit5d8b29664c13e6e5c6292d79973980182ece1441 (patch)
treeced2f67c82ce0748dbd0090f0fde6b921329d259 /JVDesktop
parent7d59c15b0efd2aa5a27aef356a265f850a2e7e2f (diff)
Add data loading from wrapper to view modelHEADmain
Diffstat (limited to 'JVDesktop')
-rw-r--r--JVDesktop/JVDesktop.csproj3
-rw-r--r--JVDesktop/Program.cs4
-rw-r--r--JVDesktop/ViewModels/DashboardViewModel.cs168
-rw-r--r--JVDesktop/Views/DashboardView.axaml4
-rw-r--r--JVDesktop/Views/DashboardView.axaml.cs41
5 files changed, 210 insertions, 10 deletions
diff --git a/JVDesktop/JVDesktop.csproj b/JVDesktop/JVDesktop.csproj
index 2940b03..67d341c 100644
--- a/JVDesktop/JVDesktop.csproj
+++ b/JVDesktop/JVDesktop.csproj
@@ -8,7 +8,7 @@
<AvaloniaUseCompiledBindingsByDefault
>true</AvaloniaUseCompiledBindingsByDefault>
<BaseOutputPath>..\.Temp\Debug\</BaseOutputPath>
- <OutDir>$(OutputPath)</OutDir>
+ <OutputPath>..\.Temp\Debug\</OutputPath>
<AppendTargetFrameworkToOutputPath
>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath
@@ -33,6 +33,7 @@
>All</PrivateAssets>
</PackageReference>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
+ <PackageReference Include="ReactiveUI" Version="22.3.1" />
</ItemGroup>
<ItemGroup>
diff --git a/JVDesktop/Program.cs b/JVDesktop/Program.cs
index 850598c..75068c2 100644
--- a/JVDesktop/Program.cs
+++ b/JVDesktop/Program.cs
@@ -3,13 +3,13 @@ using System;
namespace JVDesktop;
-sealed class Program
+static class Program
{
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
- public static AppBuilder BuildAvaloniaApp()
+ private static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
diff --git a/JVDesktop/ViewModels/DashboardViewModel.cs b/JVDesktop/ViewModels/DashboardViewModel.cs
index 5ae7d95..9371ddd 100644
--- a/JVDesktop/ViewModels/DashboardViewModel.cs
+++ b/JVDesktop/ViewModels/DashboardViewModel.cs
@@ -1,15 +1,173 @@
-using System;
+using System.IO;
+using System.Threading.Tasks;
+using CommandLineWrapper;
+using CommandLineWrapper.JsonResults.Implements;
+using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace JVDesktop.ViewModels;
public partial class DashboardViewModel : ViewModel
{
- public string Greeting => "Welcome to Avalonia!";
+ // Getters
+ private StatusResultGetter? _statusResultGetter;
+ private InfoResultGetter? _infoResultGetter;
+ private AccountListResultGetter? _accountListResultGetter;
+ private HereResultGetter? _hereResultGetter;
+ private ShareListResultGetter? _shareListResultGetter;
+ private ShareSeeResultGetter? _shareSeeResultGetter;
+ private SheetAlignTasksResultGetter? _sheetAlignTasksResultGetter;
+ private SheetListResultGetter? _sheetListResultGetter;
- [RelayCommand]
- private void ButtonClick()
+ /// <summary>
+ /// Workspace object
+ /// </summary>
+ [ObservableProperty]
+ private JVCSWorkspace? _workspace;
+
+ /// <summary>
+ /// If the workspace object exists, it proves the workspace is initialized
+ /// </summary>
+ public bool WorkspaceInitialized => Workspace != null;
+
+ /// <summary>
+ /// Current workspace directory
+ /// </summary>
+ [ObservableProperty]
+ private string _currentWorkspaceDirectory = "";
+
+ /// <summary>
+ /// Currently used account
+ /// </summary>
+ [ObservableProperty]
+ private string _currentAccount = "unknown";
+
+ /// <summary>
+ /// Whether HOST mode is currently enabled
+ /// </summary>
+ [ObservableProperty]
+ private bool? _hostMode;
+
+ /// <summary>
+ /// Currently used structure sheet (empty means no sheet is used)
+ /// </summary>
+ [ObservableProperty]
+ private string? _currentSheet;
+
+ /// <summary>
+ /// Upstream of the current workspace
+ /// </summary>
+ [ObservableProperty]
+ private string _currentUpstream = "127.0.0.1";
+
+ /// <summary>
+ /// Result from the last alignment check
+ /// </summary>
+ [ObservableProperty]
+ private AlignResult? _alignResult;
+
+ /// <summary>
+ /// Result from the last current directory information collection
+ /// </summary>
+ [ObservableProperty]
+ private HereResult? _hereResult;
+
+ /// <summary>
+ /// Result from the last change status collection
+ /// </summary>
+ [ObservableProperty]
+ private StatusResult? _statusResult;
+
+ /// <summary>
+ /// Result from the last sheet detection
+ /// </summary>
+ [ObservableProperty]
+ private SheetListResult? _sheetListResult;
+
+ /// <summary>
+ /// Result from the last account detection
+ /// </summary>
+ [ObservableProperty]
+ private AccountListResult? _accountListResult;
+
+ /// <summary>
+ /// Triggered when the workspace changes
+ /// </summary>
+ partial void OnWorkspaceChanged(JVCSWorkspace? value)
{
- Console.WriteLine("Button clicked");
+ // Update workspace initialization status
+ OnPropertyChanged(nameof(WorkspaceInitialized));
+
+ // Clear status
+ if (value == null)
+ {
+ StatusClean();
+ return;
+ }
+
+ // Initial load
+ _ = ReloadFromWorkspace(value);
+ }
+
+ /// <summary>
+ /// Clear status
+ /// </summary>
+ private void StatusClean()
+ {
+ CurrentWorkspaceDirectory = "";
+ CurrentAccount = "unknown";
+ HostMode = null;
+ CurrentSheet = null;
+ CurrentUpstream = "127.0.0.1";
+ AlignResult = null;
+ HereResult = null;
+ StatusResult = null;
+ SheetListResult = null;
+ }
+
+ /// <summary>
+ /// Load status from the workspace object
+ /// </summary>
+ /// <param name="workspace"> Workspace </param>
+ private async Task ReloadFromWorkspace(JVCSWorkspace workspace)
+ {
+ InitializeGetters(workspace);
+
+ var alignTask = _sheetAlignTasksResultGetter?.Get(workspace)!;
+ var hereTask = _hereResultGetter?.Get(workspace)!;
+ var statusTask = _statusResultGetter?.Get(workspace)!;
+ var sheetListTask = _sheetListResultGetter?.Get(workspace)!;
+ var accountListTask = _accountListResultGetter?.Get(workspace)!;
+
+ await Task.WhenAll(alignTask, hereTask, statusTask, sheetListTask, accountListTask);
+
+ AlignResult = await alignTask;
+ HereResult = await hereTask;
+ StatusResult = await statusTask;
+ SheetListResult = await sheetListTask;
+ AccountListResult = await accountListTask;
+ }
+
+ /// <summary>
+ /// Initializes all getters if they are null.
+ /// </summary>
+ /// <param name="workspace"> Workspace </param>
+ private void InitializeGetters(JVCSWorkspace workspace)
+ {
+ if (Workspace == null)
+ return;
+
+ var workspaceDirectory = "";
+ if (Workspace.SuccessInitialized)
+ workspaceDirectory = Workspace.WorkspaceDirectory;
+
+ _statusResultGetter ??= new StatusResultGetter();
+ _infoResultGetter ??= new InfoResultGetter("");
+ _accountListResultGetter ??= new AccountListResultGetter();
+ _hereResultGetter ??= new HereResultGetter(new DirectoryInfo(workspaceDirectory));
+ _shareListResultGetter ??= new ShareListResultGetter();
+ _shareSeeResultGetter ??= new ShareSeeResultGetter("");
+ _sheetAlignTasksResultGetter ??= new SheetAlignTasksResultGetter();
+ _sheetListResultGetter ??= new SheetListResultGetter();
}
}
diff --git a/JVDesktop/Views/DashboardView.axaml b/JVDesktop/Views/DashboardView.axaml
index 553754f..1f0a0c4 100644
--- a/JVDesktop/Views/DashboardView.axaml
+++ b/JVDesktop/Views/DashboardView.axaml
@@ -38,13 +38,13 @@
<Border Grid.Row="1" Background="Black">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock
- Text="{Binding Greeting}"
+ Text="{Binding WorkspaceInitialized}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
/>
<Button
Content="Click"
- Command="{Binding ButtonClickCommand}"
+ Click="SetupWorkspace"
Margin="0,10,0,0"
/>
</StackPanel>
diff --git a/JVDesktop/Views/DashboardView.axaml.cs b/JVDesktop/Views/DashboardView.axaml.cs
index ae58263..42e65f9 100644
--- a/JVDesktop/Views/DashboardView.axaml.cs
+++ b/JVDesktop/Views/DashboardView.axaml.cs
@@ -1,5 +1,12 @@
+using System;
+using System.IO;
+using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Input;
+using Avalonia.Interactivity;
+using Avalonia.Platform.Storage;
+using CommandLineWrapper;
+using JVDesktop.ViewModels;
namespace JVDesktop.Views;
@@ -12,4 +19,38 @@ public partial class DashboardView : Window
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
BeginMoveDrag(e);
}
+
+ /// <summary>
+ /// Select and setup workspace
+ /// </summary>
+ private async void SetupWorkspace(object? sender, RoutedEventArgs routedEventArgs)
+ {
+ var topLevel = GetTopLevel(this);
+ if (topLevel == null) return;
+
+ var storageProvider = topLevel.StorageProvider;
+
+ var result = await storageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
+ {
+ Title = "Select JustEnoughVCS Workspace",
+ AllowMultiple = false
+ });
+
+ if (result.Count > 0)
+ {
+ var selectedFolder = result[0];
+ var folderPath = selectedFolder.Path.LocalPath;
+
+ if (Directory.Exists(folderPath))
+ {
+ var workspace = new JVCSWorkspace();
+ await workspace.InitializeAsync(folderPath);
+ if (workspace.SuccessInitialized)
+ {
+ if (DataContext is DashboardViewModel viewModel)
+ viewModel.Workspace = workspace;
+ }
+ }
+ }
+ }
}