using ReactiveUI; using ReactiveUI.Fody.Helpers; using System.Application.Services; using System.Application.Settings; using System.Application.UI.Resx; using System.Collections.Generic; using System.Linq; using System.Properties; using System.Reactive; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; // ReSharper disable once CheckNamespace namespace System.Application.UI.ViewModels { public partial class MainWindowViewModel : WindowViewModel { #region 更改通知 //[Reactive] //public bool Topmost { get; set; } [Reactive] public ViewModelBase? SelectedItem { get; set; } [Reactive] public bool IsOpenUserMenu { get; set; } //public ReactiveCommand? OpenUserMenu { get; } #endregion public StartPageViewModel StartPage => GetTabItemVM(); public CommunityProxyPageViewModel CommunityProxyPage => GetTabItemVM(); public ProxyScriptManagePageViewModel ProxyScriptPage => GetTabItemVM(); public SteamAccountPageViewModel SteamAccountPage => GetTabItemVM(); public GameListPageViewModel GameListPage => GetTabItemVM(); public LocalAuthPageViewModel LocalAuthPage => GetTabItemVM(); public SteamIdlePageViewModel SteamIdlePage => GetTabItemVM(); public ArchiSteamFarmPlusPageViewModel ASFPage => GetTabItemVM(); public GameRelatedPageViewModel GameRelatedPage => GetTabItemVM(); public OtherPlatformPageViewModel OtherPlatformPage => GetTabItemVM(); protected static readonly IPlatformService platformService = IPlatformService.Instance; public MainWindowViewModel() { if (IApplication.IsDesktopPlatform) { var adminTag = platformService.IsAdministrator ? (OperatingSystem2.IsWindows() ? " (Administrator)" : " (Root)") : string.Empty; var title = $"{ThisAssembly.DisplayTrademark} {RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant()} v{ThisAssembly.VersionDisplay} for {DeviceInfo2.OSName()}{adminTag}"; #if DEBUG title = $"[Debug] {title}"; #endif Title = title; IUserManager.Instance.OnSignOut += () => { IsOpenUserMenu = false; }; //OpenUserMenu = ReactiveCommand.Create(() => //{ // IsOpenUserMenu = UserService.Current.IsAuthenticated; // if (!IsOpenUserMenu) // { // UserService.Current.ShowWindow(CustomWindow.LoginOrRegister); // } //}); } #region InitTabItems //AddTabItem(); if (R.IsChineseSimplified || !IApplication.IsDesktopPlatform) { // Android 目前底部菜单实现要隐藏需要改多个地方 // 主要是初始化时不依赖 TabItems,两边逻辑暂不能同步一套代码 AddTabItem(); } if (IApplication.IsDesktopPlatform) { if (R.IsChineseSimplified) { AddTabItem(); } AddTabItem(); AddTabItem(); } AddTabItem(); AddTabItem(); //AddTabItem(); #if !TRAY_INDEPENDENT_PROGRAM if (OperatingSystem2.IsWindows()) AddTabItem(); #endif //AddTabItem(); //AddTabItem(); //#if !TRAY_INDEPENDENT_PROGRAM && DEBUG // if (IApplication.EnableDevtools && IApplication.IsDesktopPlatform) // { // AddTabItem(); // //FooterTabItems.Add(new DebugPageViewModel().AddTo(this)); // //if (AppHelper.IsSystemWebViewAvailable) // //{ // // AddTabItem(); // //} // } //#endif #endregion SelectedItem = TabItems.First(); R.Subscribe(() => { foreach (var item in CurrentAllTabItems) { item.RaisePropertyChanged(nameof(TabItemViewModelBase.Name)); } }).AddTo(this); //this.WhenAnyValue(x => x.SelectedItem) // .Subscribe(x => // { // if (x != null) // FrameContent = x; // }).AddTo(this); //this.WhenAnyValue(x => x.FrameContent) // .Subscribe(x => // { // if (x != SelectedItem) // SelectedItem = null; // }).AddTo(this); } public override void Initialize() { Task.Run(() => { Thread.CurrentThread.IsBackground = true; if (!IsInitialized) { Task.Run(async () => { if (R.IsChineseSimplified) { await ProxyService.Current.Initialize(); } if (ASFSettings.AutoRunArchiSteamFarm.Value) { if (platformService.UsePlatformForegroundService) { await platformService.StartOrStopForegroundServiceAsync(nameof(ASFService), true); } else { await ASFService.Current.InitASF(); } } }); if (IApplication.IsDesktopPlatform) { SteamConnectService.Current.Initialize(); SteamConnectService.Current.RefreshSteamUsers(); } Parallel.ForEach(TabItems, item => { item.Initialize(); //Task.Run(item.Initialize).ForgetAndDispose(); }); IsInitialized = true; } }).ForgetAndDispose(); } //public async override void Activation() //{ // if (IsFirstActivation) // { // if (UISettings.DoNotShowMessageBoxs.Value?.Contains(MessageBox.DontPromptType.Donate) == false) // { // //INotificationService.Instance.Notify("如果你觉得 Watt Toolkit 好用,你可以考虑给我们一些捐助以支持我们继续开发,谢谢!", NotificationType.Message); // await MessageBox.ShowAsync("如果你觉得 Watt Toolkit 好用,你可以考虑给我们一些捐助以支持我们继续开发,谢谢!", button: MessageBox.Button.OK, // rememberChooseKey: MessageBox.DontPromptType.Donate); // } // } // base.Activation(); //} } }