diff --git a/Knossos.NET/App.axaml.cs b/Knossos.NET/App.axaml.cs index af828745..ad208605 100644 --- a/Knossos.NET/App.axaml.cs +++ b/Knossos.NET/App.axaml.cs @@ -21,53 +21,20 @@ namespace Knossos.NET public partial class App : Application { TrayIcon? trayIcon = null; - bool minimizeToTray = false; + bool trayMode = false; + private MainWindowViewModel? mainVM = null; public override void Initialize() { AvaloniaXamlLoader.Load(this); } - public void DisableMinimizeToTrayRuntime() - { - minimizeToTray = false; - } - - public void EnableMinimizeToTrayRuntime() - { - if (!minimizeToTray && ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) - { - if (desktop.MainWindow != null) - { - desktop.MainWindow.PropertyChanged += (v, __) => - { - if (minimizeToTray && v is MainWindow view && view.WindowState == WindowState.Minimized) - { - desktop.MainWindow.Hide(); - desktop.MainWindow.WindowState = WindowState.Normal; - StartTrayIcon(); - trayIcon!.IsVisible = true; - } - }; - desktop.MainWindow.Closing += (_, __) => - { - if (trayIcon != null) - { - trayIcon.IsVisible = false; - trayIcon = null; - } - }; - minimizeToTray = true; - } - } - } - public override void OnFrameworkInitializationCompleted() { if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - minimizeToTray = Environment.GetCommandLineArgs().FirstOrDefault(x => x.ToLower() == "-traymode") != null; - if (minimizeToTray) + trayMode = Environment.GetCommandLineArgs().FirstOrDefault(x => x.ToLower() == "-traymode") != null; + if (trayMode) { desktop.ShutdownMode = ShutdownMode.OnExplicitShutdown; Knossos.StartUp(false, false); @@ -75,72 +42,71 @@ public override void OnFrameworkInitializationCompleted() } else { - desktop.MainWindow = new MainWindow - { - DataContext = new MainWindowViewModel() - }; + CreateMainWindow(desktop); } } base.OnFrameworkInitializationCompleted(); } - - private async void StartTrayIcon() + private void CreateMainWindow(IClassicDesktopStyleApplicationLifetime desktop) { - if (trayIcon == null) + if(mainVM == null) + { + mainVM = new MainWindowViewModel(); + } + + desktop.MainWindow = new MainWindow + { + DataContext = mainVM + }; + + desktop.MainWindow.Closing += (_, __) => { - trayIcon = new TrayIcon + if (Knossos.globalSettings.closeToTray || trayMode) { - IsVisible = true, - ToolTipText = "Knossos.NET v" + Knossos.AppVersion, - Icon = new WindowIcon(new Bitmap(AssetLoader.Open(new Uri("avares://Knossos.NET/Assets/knossos-icon.ico")))), - Menu = new NativeMenu() { new NativeMenuItem("Loading...") } - }; + desktop.ShutdownMode = ShutdownMode.OnExplicitShutdown; + StartTrayIcon(); + } + }; + + desktop.MainWindow.Show(); + } - while (!Knossos.initIsComplete) { await Task.Delay(10); } - } - trayIcon.Menu = new NativeMenu(); + private async void StartTrayIcon() + { + trayIcon?.Dispose(); + trayIcon = new TrayIcon + { + IsVisible = true, + ToolTipText = "Knossos.NET v" + Knossos.AppVersion, + Icon = new WindowIcon(new Bitmap(AssetLoader.Open(new Uri("avares://Knossos.NET/Assets/knossos-icon.ico")))), + Menu = new NativeMenu() { new NativeMenuItem("Loading...") } + }; + + while (!Knossos.initIsComplete) { await Task.Delay(10); } + trayIcon.Menu?.Items.Clear(); + /*****************************OPEN***********************************/ + var open = new NativeMenuItem("Open"); open.Click += (s, _) => { if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - if (desktop.MainWindow == null) + CreateMainWindow(desktop); + desktop.ShutdownMode = ShutdownMode.OnLastWindowClose; + if (CustomLauncher.IsCustomMode && CustomLauncher.MenuTaskButtonAtTheEnd) { - desktop.MainWindow = new MainWindow - { - DataContext = new MainWindowViewModel() - }; - desktop.MainWindow.PropertyChanged += (v, __) => - { - if (v is MainWindow view && view.WindowState == WindowState.Minimized) - { - desktop.MainWindow.Hide(); - desktop.MainWindow.WindowState = WindowState.Normal; - StartTrayIcon(); - trayIcon.IsVisible = true; - } - }; - desktop.MainWindow.Closing += (_, __) => - { - if (trayIcon != null) - { - trayIcon.IsVisible = false; - trayIcon = null; - } - }; - desktop.ShutdownMode = ShutdownMode.OnLastWindowClose; + MainWindow.instance?.FixMarginButtomTasks(); } - desktop.MainWindow?.Show(); - trayIcon.IsVisible = false; + trayIcon?.Dispose(); GC.Collect(); } }; - trayIcon.Menu.Add(open); - trayIcon.Menu.Add(new NativeMenuItemSeparator()); + trayIcon.Menu?.Add(open); + trayIcon.Menu?.Add(new NativeMenuItemSeparator()); try { @@ -151,6 +117,11 @@ private async void StartTrayIcon() var filters = ModTags.GetListAllFilters(); foreach (var filter in filters) { + if( string.Compare(filter, ModTags.Filters.Dependency.ToString(),true) == 0 || + string.Compare(filter, ModTags.Filters.Utility.ToString(), true) == 0 ) + { + continue; //skip dependency and utility mods + } TextInfo myTI = new CultureInfo("en-US", false).TextInfo; var displayName = myTI.ToTitleCase(filter.Replace("_", " ")); var filterItem = new NativeMenuItem(displayName) { Menu = new NativeMenu() }; @@ -165,23 +136,7 @@ private async void StartTrayIcon() var m = mods.Where(x => x.id == mod.id)?.MaxBy(x => new SemanticVersion(x.version)); if (m != null) { - var modItem = new NativeMenuItem(m.ToString()) { Menu = new NativeMenu() }; - /*************************************MOD SUB BUTTONS*************************************/ - modItem.Menu.Add(CreateLaunchFSOButton(m, FsoExecType.Release)); - modItem.Menu.Add(CreateLaunchFSOButton(m, FsoExecType.Debug)); - modItem.Menu.Add(CreateLaunchFSOButton(m, FsoExecType.Fred2)); - modItem.Menu.Add(CreateLaunchFSOButton(m, FsoExecType.Fred2Debug)); - modItem.Menu.Add(CreateLaunchFSOButton(m, FsoExecType.QtFred)); - modItem.Menu.Add(CreateLaunchFSOButton(m, FsoExecType.QtFredDebug)); - var settings = new NativeMenuItem("Settings"); - settings.Click += (s, e) => { - var dialog = new ModSettingsView(); - dialog.DataContext = new ModSettingsViewModel(m); - dialog.Show(); - }; - modItem.Menu.Add(settings); - /*****************************************************************************************/ - filterItem.Menu.Add(modItem); + filterItem.Menu.Add(CreateModMenuItem(m)); addedIds.Add(mod.id); } } @@ -190,7 +145,7 @@ private async void StartTrayIcon() } } if(play.Menu.Any()) - trayIcon.Menu.Add(play); + trayIcon.Menu?.Add(play); /*****************************DEVELOP***********************************/ var dev = new NativeMenuItem("Develop") { Menu = new NativeMenu(), Icon = new Bitmap(AssetLoader.Open(new Uri("avares://Knossos.NET/Assets/general/menu_develop.png"))) }; var devMods = mods.Where(x => x.devMode); @@ -204,30 +159,14 @@ private async void StartTrayIcon() var m = mods.Where(x => x.id == devMod.id)?.MaxBy(x => new SemanticVersion(x.version)); if(m != null) { - var modItem = new NativeMenuItem(m.ToString()) { Menu = new NativeMenu() }; - /*************************************MOD SUB BUTTONS*************************************/ - modItem.Menu.Add(CreateLaunchFSOButton(m, FsoExecType.Release)); - modItem.Menu.Add(CreateLaunchFSOButton(m, FsoExecType.Debug)); - modItem.Menu.Add(CreateLaunchFSOButton(m, FsoExecType.Fred2)); - modItem.Menu.Add(CreateLaunchFSOButton(m, FsoExecType.Fred2Debug)); - modItem.Menu.Add(CreateLaunchFSOButton(m, FsoExecType.QtFred)); - modItem.Menu.Add(CreateLaunchFSOButton(m, FsoExecType.QtFredDebug)); - var settings = new NativeMenuItem("Settings"); - settings.Click += (s, e) => { - var dialog = new ModSettingsView(); - dialog.DataContext = new ModSettingsViewModel(m); - dialog.Show(); - }; - modItem.Menu.Add(settings); - /*****************************************************************************************/ - dev.Menu.Add(modItem); + dev.Menu.Add(CreateModMenuItem(m)); addedIds.Add(devMod.id); } } } } if(dev.Menu.Any()) - trayIcon.Menu.Add(dev); + trayIcon.Menu?.Add(dev); /*****************************TOOLS*************************************/ var toolsItem = new NativeMenuItem("Tools") { Menu = new NativeMenu(), Icon = new Bitmap(AssetLoader.Open(new Uri("avares://Knossos.NET/Assets/general/custom-config-icon.png"))) }; var tools = Knossos.GetTools(); @@ -244,7 +183,7 @@ private async void StartTrayIcon() } } if (toolsItem.Menu.Any()) - trayIcon.Menu.Add(toolsItem); + trayIcon.Menu?.Add(toolsItem); /*****************************DEBUG*************************************/ var debug = new NativeMenuItem("Debug") { Menu = new NativeMenu(), Icon = new Bitmap(AssetLoader.Open(new Uri("avares://Knossos.NET/Assets/general/menu_debug.png"))) }; var openFs2Log = new NativeMenuItem("Open fs2_open.log"); @@ -257,7 +196,7 @@ private async void StartTrayIcon() OpenLog(); }; debug.Menu.Add(openLog); - trayIcon.Menu.Add(debug); + trayIcon.Menu?.Add(debug); } catch (Exception ex) { @@ -265,26 +204,57 @@ private async void StartTrayIcon() } /*****************************CLOSE***********************************/ - trayIcon.Menu.Add(new NativeMenuItemSeparator()); + trayIcon.Menu?.Add(new NativeMenuItemSeparator()); var close = new NativeMenuItem("Exit Knossos.NET"); close.Click += (s, e) => { if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { + trayIcon?.Dispose(); desktop.Shutdown(); } - if(trayIcon != null) - { - trayIcon.IsVisible = false; - trayIcon = null; - } }; - trayIcon.Menu.Add(close); + trayIcon.Menu?.Add(close); GC.Collect(); } + private NativeMenuItem CreateModMenuItem(Mod mod) + { + var modItem = new NativeMenuItem(mod.ToString()) { Menu = new NativeMenu() }; + /*************************************MOD SUB BUTTONS*************************************/ + modItem.Menu.Add(CreateLaunchFSOButton(mod, FsoExecType.Release)); + + var advItem = new NativeMenuItem("Advanced") { Menu = new NativeMenu() }; + if (mod.devMode) + { + modItem.Menu.Add(CreateLaunchFSOButton(mod, FsoExecType.Fred2)); + } + else + { + advItem.Menu.Add(CreateLaunchFSOButton(mod, FsoExecType.Fred2)); + } + + advItem.Menu.Add(CreateLaunchFSOButton(mod, FsoExecType.Debug)); + advItem.Menu.Add(CreateLaunchFSOButton(mod, FsoExecType.Fred2Debug)); + advItem.Menu.Add(CreateLaunchFSOButton(mod, FsoExecType.QtFred)); + advItem.Menu.Add(CreateLaunchFSOButton(mod, FsoExecType.QtFredDebug)); + + modItem.Menu.Add(advItem); + + var settings = new NativeMenuItem("Settings"); + settings.Click += (s, e) => { + var dialog = new ModSettingsView(); + dialog.DataContext = new ModSettingsViewModel(mod); + dialog.Show(); + }; + modItem.Menu.Add(settings); + /*****************************************************************************************/ + return modItem; + } + private NativeMenuItem CreateLaunchFSOButton(Mod mod, FsoExecType fsoExecType) { - var item = new NativeMenuItem(fsoExecType.ToString()); + var name = fsoExecType != FsoExecType.Release ? fsoExecType.ToString() : "Play"; + var item = new NativeMenuItem(name); item.Click += (s, e) => { Knossos.PlayMod(mod, fsoExecType); }; diff --git a/Knossos.NET/Models/GlobalSettings.cs b/Knossos.NET/Models/GlobalSettings.cs index d6ebf275..23604de3 100644 --- a/Knossos.NET/Models/GlobalSettings.cs +++ b/Knossos.NET/Models/GlobalSettings.cs @@ -122,24 +122,13 @@ public AutoUpdateFsoBuilds(bool stable = false, bool rc = false, bool nightly = [JsonPropertyName("warn_new_settings_system")] public bool warnNewSettingsSystem { get; set; } = true; [JsonIgnore] - public bool _minimizeToTray { get; set; } = false; - [JsonPropertyName("minimize_to_tray")] - public bool minimizeToTray { - get { return _minimizeToTray; } - set { if (_minimizeToTray != value) { - _minimizeToTray = value; + private bool _closeToTray { get; set; } = false; + [JsonPropertyName("close_to_tray")] + public bool closeToTray { + get { return _closeToTray; } + set { if (_closeToTray != value) { + _closeToTray = value; pendingChangesOnAppClose = true; - if (Avalonia.Application.Current is App app) - { - if (_minimizeToTray) - { - app.EnableMinimizeToTrayRuntime(); - } - else - { - app.DisableMinimizeToTrayRuntime(); - } - } } } } @@ -695,7 +684,7 @@ public void Load() mainMenuOpen = tempSettings.mainMenuOpen; sortType = tempSettings.sortType; portableFsoPreferences = tempSettings.portableFsoPreferences; - minimizeToTray = tempSettings.minimizeToTray; + closeToTray = tempSettings.closeToTray; ignoredLauncherUpdates = tempSettings.ignoredLauncherUpdates; ReadFS2IniValues(); diff --git a/Knossos.NET/ViewModels/GlobalSettingsViewModel.cs b/Knossos.NET/ViewModels/GlobalSettingsViewModel.cs index b63ef4a4..3347211a 100644 --- a/Knossos.NET/ViewModels/GlobalSettingsViewModel.cs +++ b/Knossos.NET/ViewModels/GlobalSettingsViewModel.cs @@ -198,11 +198,11 @@ internal bool ShowDevOptions } /* This change is applied right away */ - private bool minimizeToTray = false; - internal bool MinimizeToTray + private bool closeToTray = false; + internal bool CloseToTray { - get { return minimizeToTray; } - set { if (minimizeToTray != value) { this.SetProperty(ref minimizeToTray, value); Knossos.globalSettings.minimizeToTray = value ; UnCommitedChanges = true; } } + get { return closeToTray; } + set { if (closeToTray != value) { this.SetProperty(ref closeToTray, value); Knossos.globalSettings.closeToTray = value ; UnCommitedChanges = true; } } } /*VIDEO*/ @@ -668,7 +668,7 @@ public void LoadData() PrefixCMD = Knossos.globalSettings.prefixCMD; EnvVars = Knossos.globalSettings.envVars; ShowDevOptions = Knossos.globalSettings.showDevOptions || NoSystemCMD; - MinimizeToTray = Knossos.globalSettings.minimizeToTray; + CloseToTray = Knossos.globalSettings.closeToTray; /* VIDEO SETTINGS */ //RESOLUTION @@ -1248,7 +1248,7 @@ internal void SaveCommand() Knossos.globalSettings.prefixCMD = PrefixCMD; Knossos.globalSettings.envVars = EnvVars; Knossos.globalSettings.showDevOptions = ShowDevOptions; - Knossos.globalSettings.minimizeToTray = MinimizeToTray; + Knossos.globalSettings.closeToTray = CloseToTray; /* VIDEO */ //Resolution diff --git a/Knossos.NET/ViewModels/Windows/MainWindowViewModel.cs b/Knossos.NET/ViewModels/Windows/MainWindowViewModel.cs index cfd8049f..a4eb084f 100644 --- a/Knossos.NET/ViewModels/Windows/MainWindowViewModel.cs +++ b/Knossos.NET/ViewModels/Windows/MainWindowViewModel.cs @@ -44,13 +44,13 @@ public partial class MainWindowViewModel : ViewModelBase [ObservableProperty] internal string appTitle = "Knossos.NET v" + Knossos.AppVersion; [ObservableProperty] - internal int? windowWidth = null; + internal int windowWidth = 1200; [ObservableProperty] - internal int? windowHeight = null; + internal int windowHeight = 700; [ObservableProperty] - internal int? minWindowWidth = null; + internal int minWindowWidth = 900; [ObservableProperty] - internal int? minWindowHeight = null; + internal int minWindowHeight = 500; [ObservableProperty] internal ModListViewModel? installedModsView; [ObservableProperty] @@ -107,8 +107,6 @@ public MainWindowViewModel() } if (!CustomLauncher.IsCustomMode) { - MinWindowWidth = 900; - MinWindowHeight = 500; placeholderTileImage = new Bitmap(AssetLoader.Open(new Uri("avares://Knossos.NET/Assets/general/NebulaDefault.png"))); InstalledModsView = new ModListViewModel(); NebulaModsView = new NebulaModListViewModel(); @@ -125,10 +123,10 @@ public MainWindowViewModel() //Apply customization for Single TC Mode Knossos.globalSettings.mainMenuOpen = CustomLauncher.MenuOpenFirstTime; AppTitle = CustomLauncher.WindowTitle + " v" + Knossos.AppVersion; - WindowHeight = CustomLauncher.WindowHeight; - WindowWidth = CustomLauncher.WindowWidth; - MinWindowWidth = CustomLauncher.MinWindowWidth; - MinWindowHeight = CustomLauncher.MinWindowHeight; + WindowHeight = CustomLauncher.WindowHeight.HasValue ? CustomLauncher.WindowHeight.Value : 1200; + WindowWidth = CustomLauncher.WindowWidth.HasValue ? CustomLauncher.WindowWidth.Value : 700; + MinWindowWidth = CustomLauncher.MinWindowWidth.HasValue ? CustomLauncher.MinWindowWidth.Value : 900; + MinWindowHeight = CustomLauncher.MinWindowHeight.HasValue ? CustomLauncher.MinWindowHeight.Value : 500; CustomHomeVM = new CustomHomeViewModel(); if (CustomLauncher.MenuDisplayEngineEntry) FsoBuildsView = new FsoBuildsViewModel(); diff --git a/Knossos.NET/Views/GlobalSettingsView.axaml b/Knossos.NET/Views/GlobalSettingsView.axaml index 7066eba6..ce376365 100644 --- a/Knossos.NET/Views/GlobalSettingsView.axaml +++ b/Knossos.NET/Views/GlobalSettingsView.axaml @@ -60,10 +60,10 @@ - + - - + +