From 5d8b29664c13e6e5c6292d79973980182ece1441 Mon Sep 17 00:00:00 2001
From: 魏曹先生 <1992414357@qq.com>
Date: Tue, 13 Jan 2026 08:22:09 +0800
Subject: Add data loading from wrapper to view model
---
JVDesktop/JVDesktop.csproj | 3 +-
JVDesktop/Program.cs | 4 +-
JVDesktop/ViewModels/DashboardViewModel.cs | 168 ++++++++++++++++++++++++++++-
JVDesktop/Views/DashboardView.axaml | 4 +-
JVDesktop/Views/DashboardView.axaml.cs | 41 +++++++
5 files changed, 210 insertions(+), 10 deletions(-)
(limited to 'JVDesktop')
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 @@
true
..\.Temp\Debug\
- $(OutputPath)
+ ..\.Temp\Debug\
false
All
+
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()
.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()
+ ///
+ /// Workspace object
+ ///
+ [ObservableProperty]
+ private JVCSWorkspace? _workspace;
+
+ ///
+ /// If the workspace object exists, it proves the workspace is initialized
+ ///
+ public bool WorkspaceInitialized => Workspace != null;
+
+ ///
+ /// Current workspace directory
+ ///
+ [ObservableProperty]
+ private string _currentWorkspaceDirectory = "";
+
+ ///
+ /// Currently used account
+ ///
+ [ObservableProperty]
+ private string _currentAccount = "unknown";
+
+ ///
+ /// Whether HOST mode is currently enabled
+ ///
+ [ObservableProperty]
+ private bool? _hostMode;
+
+ ///
+ /// Currently used structure sheet (empty means no sheet is used)
+ ///
+ [ObservableProperty]
+ private string? _currentSheet;
+
+ ///
+ /// Upstream of the current workspace
+ ///
+ [ObservableProperty]
+ private string _currentUpstream = "127.0.0.1";
+
+ ///
+ /// Result from the last alignment check
+ ///
+ [ObservableProperty]
+ private AlignResult? _alignResult;
+
+ ///
+ /// Result from the last current directory information collection
+ ///
+ [ObservableProperty]
+ private HereResult? _hereResult;
+
+ ///
+ /// Result from the last change status collection
+ ///
+ [ObservableProperty]
+ private StatusResult? _statusResult;
+
+ ///
+ /// Result from the last sheet detection
+ ///
+ [ObservableProperty]
+ private SheetListResult? _sheetListResult;
+
+ ///
+ /// Result from the last account detection
+ ///
+ [ObservableProperty]
+ private AccountListResult? _accountListResult;
+
+ ///
+ /// Triggered when the workspace changes
+ ///
+ 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);
+ }
+
+ ///
+ /// Clear status
+ ///
+ private void StatusClean()
+ {
+ CurrentWorkspaceDirectory = "";
+ CurrentAccount = "unknown";
+ HostMode = null;
+ CurrentSheet = null;
+ CurrentUpstream = "127.0.0.1";
+ AlignResult = null;
+ HereResult = null;
+ StatusResult = null;
+ SheetListResult = null;
+ }
+
+ ///
+ /// Load status from the workspace object
+ ///
+ /// Workspace
+ 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;
+ }
+
+ ///
+ /// Initializes all getters if they are null.
+ ///
+ /// Workspace
+ 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 @@
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);
}
+
+ ///
+ /// Select and setup workspace
+ ///
+ 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;
+ }
+ }
+ }
+ }
}
--
cgit