// MeoAsstGui - A part of the MeoAssistantArknights project // Copyright (C) 2021 MistEO and Contributors // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY using System; using System.Threading.Tasks; using Stylet; using StyletIoC; namespace MeoAsstGui { public class RootViewModel : Conductor.Collection.OneActive { private TrayIcon _trayIcon; private readonly IContainer _container; private readonly IWindowManager _windowManager; public RootViewModel(IContainer container, IWindowManager windowManager) { _container = container; _windowManager = windowManager; } protected override void OnViewLoaded() { _trayIcon = new TrayIcon(); CheckAndUpdateNow(); InitViewModels(); InitProxy(); ShowUpdateOrDownload(); } private async void InitProxy() { var task = Task.Run(() => { var p = _container.Get(); p.Init(); }); await task; } private void InitViewModels() { var tvm = _container.Get(); var rvm = _container.Get(); //var ivm = _container.Get(); var svm = _container.Get(); var cvm = _container.Get(); Items.Add(tvm); Items.Add(rvm); //Items.Add(ivm); Items.Add(cvm); Items.Add(svm); svm.UpdateWindowTitle(); // 在标题栏上显示模拟器和IP端口 必须在 Items.Add(svm)之后执行。 ActiveItem = tvm; } private bool CheckAndUpdateNow() { var vuvm = _container.Get(); return vuvm.CheckAndUpdateNow(); } private async void ShowUpdateOrDownload() { var vuvm = _container.Get(); if (vuvm.IsFirstBootAfterUpdate) { vuvm.IsFirstBootAfterUpdate = false; _windowManager.ShowWindow(vuvm); } else { var task = Task.Run(() => { vuvm.CheckAndDownloadUpdate(); }); await task; } } private string _windowTitle = "MaaAssistantArknights"; public string WindowTitle { get => _windowTitle; set => SetAndNotify(ref _windowTitle, value); } protected override void OnClose() { System.Windows.Application.Current.Shutdown(); } } }