// 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.Threading.Tasks; using Stylet; using StyletIoC; namespace MeoAsstGui { public class RootViewModel : Conductor.Collection.OneActive { private readonly IContainer _container; private readonly IWindowManager _windowManager; public RootViewModel(IContainer container, IWindowManager windowManager) { _container = container; _windowManager = windowManager; } protected override void OnViewLoaded() { CheckAndUpdateNow(); InitProxy(); InitViewModels(); 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(); Items.Add(tvm); Items.Add(rvm); //Items.Add(ivm); 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) { _windowManager.ShowWindow(vuvm); } else { var task = Task.Run(() => { if (!vuvm.CheckAndDownloadUpdate()) { vuvm.ResourceOTA(); } }); await task; } } } }