mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
UI - Rewrote screen activation logic
UI - Changed autorun method to shortcut in startup folder to avoid permission issues UI - Properly added Robot Mono font and use it in the exception dialog
This commit is contained in:
1 parent
757ac68ea2
commit
a8e311ed98
8 files changed
+145
-59
No files matched your search
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
@@ -15,6 +16,7 @@ using Artemis.UI.Screens.Settings.Tabs.Devices;
|
||||
using Artemis.UI.Screens.Settings.Tabs.Plugins;
|
||||
using Artemis.UI.Shared.Services.Interfaces;
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
using Artemis.UI.Utilities;
|
||||
using Microsoft.Win32;
|
||||
using Ninject;
|
||||
using Serilog.Events;
|
||||
@@ -152,14 +154,28 @@ namespace Artemis.UI.Screens.Settings
|
||||
_windowManager.ShowWindow(_kernel.Get<DebugViewModel>());
|
||||
}
|
||||
|
||||
public void ShowLogsFolder()
|
||||
public async Task ShowLogsFolder()
|
||||
{
|
||||
Process.Start(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs"));
|
||||
try
|
||||
{
|
||||
Process.Start(Environment.GetEnvironmentVariable("WINDIR") + @"\explorer.exe", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs"));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _dialogService.ShowExceptionDialog("Welp, we couldn\'t open the logs folder for you", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowDataFolder()
|
||||
public async Task ShowDataFolder()
|
||||
{
|
||||
Process.Start(Constants.DataFolder);
|
||||
try
|
||||
{
|
||||
Process.Start(Environment.GetEnvironmentVariable("WINDIR") + @"\explorer.exe", Constants.DataFolder);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _dialogService.ShowExceptionDialog("Welp, we couldn\'t open the data folder for you", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnInitialActivate()
|
||||
@@ -189,14 +205,13 @@ namespace Artemis.UI.Screens.Settings
|
||||
{
|
||||
try
|
||||
{
|
||||
var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
|
||||
if (key == null)
|
||||
key = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
|
||||
var autoRunFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "Artemis.lnk");
|
||||
var executableFile = Process.GetCurrentProcess().MainModule.FileName;
|
||||
|
||||
if (File.Exists(autoRunFile))
|
||||
File.Delete(autoRunFile);
|
||||
if (StartWithWindows)
|
||||
key.SetValue("Artemis", $"\"{Process.GetCurrentProcess().MainModule.FileName}\" -autorun");
|
||||
else
|
||||
key.DeleteValue("Artemis", false);
|
||||
ShortcutUtilities.Create(autoRunFile, executableFile, "-autorun", new FileInfo(executableFile).DirectoryName, "Artemis", "", "");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -5,24 +5,31 @@ using System.Threading.Tasks;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.Home;
|
||||
using Artemis.UI.Screens.News;
|
||||
using Artemis.UI.Screens.Settings;
|
||||
using Artemis.UI.Screens.SurfaceEditor;
|
||||
using Artemis.UI.Screens.Workshop;
|
||||
using MaterialDesignExtensions.Controls;
|
||||
using MaterialDesignExtensions.Model;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Ninject;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public class SidebarViewModel : PropertyChangedBase
|
||||
{
|
||||
private readonly IKernel _kernel;
|
||||
private readonly IModuleVmFactory _moduleVmFactory;
|
||||
private readonly IPluginService _pluginService;
|
||||
|
||||
public SidebarViewModel(List<MainScreenViewModel> defaultSidebarItems, IModuleVmFactory moduleVmFactory, IPluginService pluginService)
|
||||
public SidebarViewModel(IKernel kernel, IModuleVmFactory moduleVmFactory, IPluginService pluginService)
|
||||
{
|
||||
_kernel = kernel;
|
||||
_moduleVmFactory = moduleVmFactory;
|
||||
_pluginService = pluginService;
|
||||
|
||||
DefaultSidebarItems = defaultSidebarItems;
|
||||
SidebarModules = new Dictionary<INavigationItem, Core.Plugins.Abstract.Module>();
|
||||
SidebarItems = new BindableCollection<INavigationItem>();
|
||||
|
||||
@@ -31,7 +38,6 @@ namespace Artemis.UI.Screens.Sidebar
|
||||
_pluginService.PluginDisabled += PluginServiceOnPluginDisabled;
|
||||
}
|
||||
|
||||
public List<MainScreenViewModel> DefaultSidebarItems { get; set; }
|
||||
public BindableCollection<INavigationItem> SidebarItems { get; set; }
|
||||
public Dictionary<INavigationItem, Core.Plugins.Abstract.Module> SidebarModules { get; set; }
|
||||
public IScreen SelectedItem { get; set; }
|
||||
@@ -62,28 +68,49 @@ namespace Artemis.UI.Screens.Sidebar
|
||||
|
||||
private async Task SelectSidebarItem(INavigationItem sidebarItem)
|
||||
{
|
||||
if (SelectedItem != null)
|
||||
{
|
||||
var canClose = await SelectedItem.CanCloseAsync();
|
||||
if (!canClose)
|
||||
return;
|
||||
SelectedItem.Close();
|
||||
}
|
||||
|
||||
// A module was selected if the dictionary contains the selected item
|
||||
if (SidebarModules.ContainsKey(sidebarItem))
|
||||
await ActivateModule(sidebarItem);
|
||||
else if (sidebarItem is FirstLevelNavigationItem navigationItem)
|
||||
{
|
||||
SelectedItem = _moduleVmFactory.Create(SidebarModules[sidebarItem]);
|
||||
if (navigationItem.Label == "Home")
|
||||
await ActivateViewModel<HomeViewModel>();
|
||||
else if (navigationItem.Label == "News")
|
||||
await ActivateViewModel<NewsViewModel>();
|
||||
else if (navigationItem.Label == "Workshop")
|
||||
await ActivateViewModel<WorkshopViewModel>();
|
||||
else if (navigationItem.Label == "Surface Editor")
|
||||
await ActivateViewModel<SurfaceEditorViewModel>();
|
||||
else if (navigationItem.Label == "Settings")
|
||||
await ActivateViewModel<SettingsViewModel>();
|
||||
}
|
||||
else
|
||||
{
|
||||
else if (await CloseCurrentItem())
|
||||
SelectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove this bad boy, just testing
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
private async Task<bool> CloseCurrentItem()
|
||||
{
|
||||
if (SelectedItem == null)
|
||||
return true;
|
||||
|
||||
var canClose = await SelectedItem.CanCloseAsync();
|
||||
if (!canClose)
|
||||
return false;
|
||||
|
||||
SelectedItem.Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task ActivateViewModel<T>()
|
||||
{
|
||||
if (await CloseCurrentItem())
|
||||
SelectedItem = (IScreen) _kernel.Get<T>();
|
||||
}
|
||||
|
||||
private async Task ActivateModule(INavigationItem sidebarItem)
|
||||
{
|
||||
if (await CloseCurrentItem())
|
||||
SelectedItem = SidebarModules.ContainsKey(sidebarItem) ? _moduleVmFactory.Create(SidebarModules[sidebarItem]) : null;
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMember.Global - Called by view
|
||||
|
||||
Reference in new issue
Block a user