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/ViewModels/DashboardViewModel.cs | 168 ++++++++++++++++++++++++++++-
1 file changed, 163 insertions(+), 5 deletions(-)
(limited to 'JVDesktop/ViewModels')
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();
}
}
--
cgit