diff --git a/src/Artemis.Core/Constants.cs b/src/Artemis.Core/Constants.cs index 69208acb3..849d62b17 100644 --- a/src/Artemis.Core/Constants.cs +++ b/src/Artemis.Core/Constants.cs @@ -33,7 +33,9 @@ namespace Artemis.Core /// /// The base path for Artemis application data folder /// - public static readonly string BaseFolder = Environment.GetFolderPath(OperatingSystem.IsWindows() ? Environment.SpecialFolder.CommonApplicationData : Environment.SpecialFolder.LocalApplicationData); + public static readonly string BaseFolder = Environment.GetFolderPath(OperatingSystem.IsWindows() + ? Environment.SpecialFolder.CommonApplicationData + : Environment.SpecialFolder.LocalApplicationData); /// /// The full path to the Artemis data folder @@ -54,6 +56,11 @@ namespace Artemis.Core /// The full path to the Artemis user layouts folder /// public static readonly string LayoutsFolder = Path.Combine(DataFolder, "User Layouts"); + + /// + /// The current API version for plugins + /// + public static readonly Version PluginApi = new Version(1, 0); /// /// The plugin info used by core components of Artemis diff --git a/src/Artemis.Core/Plugins/PluginInfo.cs b/src/Artemis.Core/Plugins/PluginInfo.cs index e0850b3a0..a61a21a30 100644 --- a/src/Artemis.Core/Plugins/PluginInfo.cs +++ b/src/Artemis.Core/Plugins/PluginInfo.cs @@ -25,6 +25,7 @@ namespace Artemis.Core private Version _version = null!; private bool _requiresAdmin; private PluginPlatform? _platforms; + private Version? _api; internal PluginInfo() { @@ -150,7 +151,17 @@ namespace Artemis.Core public PluginPlatform? Platforms { get => _platforms; - internal set => _platforms = value; + internal set => SetAndNotify(ref _platforms , value); + } + + /// + /// Gets the API version the plugin was built for + /// + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] + public Version? Api + { + get => _api; + internal set => SetAndNotify(ref _api, value); } /// @@ -176,9 +187,9 @@ namespace Artemis.Core } /// - /// Gets a boolean indicating whether this plugin is compatible with the current operating system + /// Gets a boolean indicating whether this plugin is compatible with the current operating system and API version /// - public bool IsCompatible => Platforms.MatchesCurrentOperatingSystem(); + public bool IsCompatible => Platforms.MatchesCurrentOperatingSystem() && Api != null && Api >= Constants.PluginApi; internal string PreferredPluginDirectory => $"{Main.Split(".dll")[0].Replace("/", "").Replace("\\", "")}-{Guid.ToString().Substring(0, 8)}"; diff --git a/src/Artemis.UI/Screens/Root/RootViewModel.cs b/src/Artemis.UI/Screens/Root/RootViewModel.cs index 72def4022..8aec9c70a 100644 --- a/src/Artemis.UI/Screens/Root/RootViewModel.cs +++ b/src/Artemis.UI/Screens/Root/RootViewModel.cs @@ -127,10 +127,16 @@ namespace Artemis.UI.Screens.Root public void OpenScreen(string displayName) { + // The window will open on the UI thread at some point, respond to that to select the chosen screen + MainWindowOpened += OnEventHandler; OpenMainWindow(); - // At this point there is a sidebar VM because the main window was opened - SidebarViewModel!.SelectedSidebarScreen = SidebarViewModel.SidebarScreens.FirstOrDefault(s => s.DisplayName == displayName); + void OnEventHandler(object? sender, EventArgs args) + { + if (SidebarViewModel != null) + SidebarViewModel.SelectedSidebarScreen = SidebarViewModel.SidebarScreens.FirstOrDefault(s => s.DisplayName == displayName); + MainWindowOpened -= OnEventHandler; + } } public async Task OpenDebugger() @@ -167,7 +173,7 @@ namespace Artemis.UI.Screens.Root _lifeTime.MainWindow.WindowState = WindowState.Normal; _lifeTime.MainWindow.Activate(); - OnMainWindowOpened(); + OnMainWindowOpened(); }); }