From df7fa83eefcdb1ee3c9e0545409fddaac13bfe90 Mon Sep 17 00:00:00 2001 From: Lixkote <95425619+Lixkote@users.noreply.github.com> Date: Mon, 5 Aug 2024 19:42:26 +0200 Subject: [PATCH] 0.2 - Better explained error messages - Fully automatic generation of required config files - Ability to define start button tooltip name manually in Settings.cfg - Added Segoe Fluent Icons missing notice --- BackEnd/App.xaml.cs | 40 ++-- BackEnd/Helpers/WinButtonHook.cs | 29 ++- BackEnd/StartMenuVariants/StartMenu10.xaml | 22 --- BackEnd/StartMenuVariants/StartMenu10.xaml.cs | 187 ------------------ BackEnd/StartMenuVariants/StartMenu11.xaml.cs | 50 ++++- .../Interface/StartMenu10/Pages/AppList.xaml | 14 -- .../StartMenu10/Pages/AppList.xaml.cs | 30 --- .../Interface/StartMenu10/Pages/Tiles.xaml | 14 -- .../Interface/StartMenu10/Pages/Tiles.xaml.cs | 30 --- .../StartMenu10/Pages/TilesAppList.xaml | 14 -- .../StartMenu10/Pages/TilesAppList.xaml.cs | 30 --- FrontEnd/Interface/StartMenu10/StartMenu.xaml | 131 ------------ .../Interface/StartMenu10/StartMenu.xaml.cs | 31 --- FrontEnd/Interface/StartMenu11/StartMenu.xaml | 6 +- FrontEnd/StartifyFrontend.csproj | 32 +-- README.md | 28 ++- STInstallerBuilder/EULA.rtf | Bin 1040 -> 1040 bytes STInstallerBuilder/setup.iss | 3 +- tempfix.png | Bin 0 -> 30977 bytes 19 files changed, 109 insertions(+), 582 deletions(-) delete mode 100644 BackEnd/StartMenuVariants/StartMenu10.xaml delete mode 100644 BackEnd/StartMenuVariants/StartMenu10.xaml.cs delete mode 100644 FrontEnd/Interface/StartMenu10/Pages/AppList.xaml delete mode 100644 FrontEnd/Interface/StartMenu10/Pages/AppList.xaml.cs delete mode 100644 FrontEnd/Interface/StartMenu10/Pages/Tiles.xaml delete mode 100644 FrontEnd/Interface/StartMenu10/Pages/Tiles.xaml.cs delete mode 100644 FrontEnd/Interface/StartMenu10/Pages/TilesAppList.xaml delete mode 100644 FrontEnd/Interface/StartMenu10/Pages/TilesAppList.xaml.cs delete mode 100644 FrontEnd/Interface/StartMenu10/StartMenu.xaml delete mode 100644 FrontEnd/Interface/StartMenu10/StartMenu.xaml.cs create mode 100644 tempfix.png diff --git a/BackEnd/App.xaml.cs b/BackEnd/App.xaml.cs index 98ee21b..f4e020c 100644 --- a/BackEnd/App.xaml.cs +++ b/BackEnd/App.xaml.cs @@ -14,6 +14,8 @@ using System.Threading.Tasks; using System.Windows.Input; using WPF.Views; +using System.Windows.Media; +using System.Drawing; namespace WPF { @@ -128,24 +130,30 @@ public async Task LockAsync() } - + private bool IsFontInstalled(string fontName) + { + using (var testFont = new Font(fontName, 8)) + { + return 0 == string.Compare( + fontName, + testFont.Name, + StringComparison.InvariantCultureIgnoreCase); + } + } public void Application_Startup(object sender, StartupEventArgs e) { + if (!IsFontInstalled("Segoe Fluent Icons")) + { + ModernWpf.MessageBox.Show("We detected that you are missing the Segoe Fluent Icons font. Please download and install it to make icons display correctly.", "Warning", MessageBoxButton.OK, SymbolGlyph.Font, MessageBoxResult.OK); + } + + // Create the startup window + StartMenu11 menuwindow = new StartMenu11(); + menuwindow.Show(); ///////////////////////////////////////////// /// Here we load the main configuration file and set the hooking method from it. ///////////////////////////////////////////// - - try - { - StartListener = new WinButtonHook(); - StartListener.StartTriggered += OnStartTriggered; - StartListener.FindAndActivateWindow(); - } - catch (Exception ex) - { - MessageBox.Show("Error reading configuration file: " + ex.Message); - } StartListener = new WinButtonHook(); StartListener.StartTriggered += OnStartTriggered; StartListener.FindAndActivateWindow(); @@ -161,10 +169,6 @@ public void Application_Startup(object sender, StartupEventArgs e) ThemeListener.Start(); TileAppHelper.CouldNotLoadTiles += FailedToLoadTiles; - - // Create the startup window - StartMenu11 menuwindow = new StartMenu11(); - menuwindow.Show(); } public void OnStartTriggered(object sender, EventArgs e) @@ -198,7 +202,7 @@ public async void ShowStolenTiles() new ToastContentBuilder() .AddInlineImage(new Uri(uriString)) .AddText("Tiles disabled.") - .AddText("We could not find or load the tiles layout file.") + .AddText("Tiles were disabled, could not find or load the tiles layout file.") .Show(); } @@ -228,7 +232,7 @@ public async void ShowNotification() new ToastContentBuilder() .AddInlineImage(new Uri(uriString)) .AddText("Welcome to Startify") - .AddText("Check it out by clicking the Windows Start button!") + .AddText("Open it by clicking the Windows Start button!") .Show(); } diff --git a/BackEnd/Helpers/WinButtonHook.cs b/BackEnd/Helpers/WinButtonHook.cs index 10b03a7..1fd524a 100644 --- a/BackEnd/Helpers/WinButtonHook.cs +++ b/BackEnd/Helpers/WinButtonHook.cs @@ -74,10 +74,29 @@ public static IntPtr FindWindowByCaptionAndClass(string caption, string classNam return IntPtr.Zero; // Window not found } + private static string GetConfigFileEntry(string filePath, string entry) + { + ///////////////////////////////////////////// + /// Config file helper. + ///////////////////////////////////////////// + foreach (string line in System.IO.File.ReadLines(filePath)) + { + string[] keyValue = line.Split('='); + if (keyValue.Length == 2 && keyValue[0].Trim() == entry) + { + return keyValue[1].Trim(); + } + } + + return string.Empty; + } + + public string configFilePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Startify", "Settings.cfg"); + public void FindAndActivateWindow() { - string caption = "Start"; - string className = "Start"; + string caption = GetConfigFileEntry(configFilePath, "TooltipCaption"); + string className = GetConfigFileEntry(configFilePath, "TooltipName"); IntPtr windowHandle = FindWindowByCaptionAndClass(caption, className); @@ -91,7 +110,7 @@ public void FindAndActivateWindow() } else { - ModernWpf.MessageBox.Show("Startify had an issue hooking the windows start button, and might not work properly.", "Startify Standard Hooking Error", MessageBoxButton.OK, SymbolGlyph.Error, MessageBoxResult.OK); + ModernWpf.MessageBox.Show("Startify could not find the start button tooltip to hook into. Verify you have set the tooltip name correctly in the Settings.cfg file.", "Warning", MessageBoxButton.OK, SymbolGlyph.Warning, MessageBoxResult.OK); } } @@ -114,7 +133,7 @@ public void FindAndCloseW11StartWindow() { if (shownerrorbefore == false) { - ModernWpf.MessageBox.Show("Startify had an issue closing the windows start menu, and might not work properly. This might also mean that user is using another Windows 11 Shell replacement app like StartAllBack or ExplorerPatcher.", "Startify Standard Hooking Warning", MessageBoxButton.OK, SymbolGlyph.Warning, MessageBoxResult.OK); + ModernWpf.MessageBox.Show("Startify could not find the Windows 11 Start menu host window. This might be caused by using another shell replacement app like StartAllBack or ExplorerPatcher. If you are using StartAllBack, change the start menu type to default in its settings. If you are using ExplorerPatcher, please change the start menu type to Windows 11 in its settings.", "Warning", MessageBoxButton.OK, SymbolGlyph.Warning, MessageBoxResult.OK); } } } @@ -142,7 +161,7 @@ public int MouseEvents(int code, IntPtr wParam, IntPtr lParam, EventHandler star GetClassName(win, className, className.Capacity); string win32ClassName = className.ToString(); - if (win32ClassName == "Start") + if (win32ClassName == GetConfigFileEntry(configFilePath, "TooltipName")) { StartTriggered(this, null); return 1; diff --git a/BackEnd/StartMenuVariants/StartMenu10.xaml b/BackEnd/StartMenuVariants/StartMenu10.xaml deleted file mode 100644 index 428cc7b..0000000 --- a/BackEnd/StartMenuVariants/StartMenu10.xaml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - diff --git a/BackEnd/StartMenuVariants/StartMenu10.xaml.cs b/BackEnd/StartMenuVariants/StartMenu10.xaml.cs deleted file mode 100644 index a4bab11..0000000 --- a/BackEnd/StartMenuVariants/StartMenu10.xaml.cs +++ /dev/null @@ -1,187 +0,0 @@ -using Microsoft.Win32; -using ModernWpf; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Security.Policy; -using System.Text.RegularExpressions; -using System.Threading; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Forms; -using System.Windows.Input; -using System.Windows.Media.Animation; -using System.Windows.Media.Effects; -using System.Xml; -using Windows.ApplicationModel; -using Windows.ApplicationModel.Core; -using Windows.Management.Deployment; -using Windows.System; -using Windows.UI.Notifications; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Media; -using WPF.Helpers; -using static System.Windows.Forms.LinkLabel; -using static System.Windows.Forms.VisualStyles.VisualStyleElement; -using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window; -using File = System.IO.File; -using MessageBox = ModernWpf.MessageBox; -using Tile = WPF.Helpers.Tile; -using Window = System.Windows.Window; - -namespace WPF.Views -{ - - public partial class StartMenu10 : Window - { - Helpers.WinButtonHook StartListener; - Helpers.RegistryMonitor AccentListener; - Helpers.RegistryMonitor ThemeListener; - public bool applistwasloaded = false; - - ObservableCollection Programs = new ObservableCollection(); - ObservableCollection Pinned = new ObservableCollection(); - - - private static string GetHookingMethod(string filePath) - { - foreach (string line in System.IO.File.ReadLines(filePath)) - { - string[] keyValue = line.Split('='); - if (keyValue.Length == 2 && keyValue[0].Trim() == "HookingMethod") - { - return keyValue[1].Trim(); - } - } - - return string.Empty; - } - private async void StartMenuActivated(object sender, EventArgs e) - { - Show(); - // var startPlaceholder = StartMenuIslandhCompact.Child as Shell.Interface.StartMenuCompact.StartMenuCompact; - // Task animationTask = startPlaceholder.StartOpenStartAnimation(); - // await animationTask; // wait for the animation task to finish - this.Focus(); - } - - private async void StartMenuDeactivated(object sender, EventArgs e) - { - // var startPlaceholder = StartMenuIslandhCompact.Child as Shell.Interface.StartMenuCompact.StartMenuCompact; - // Task animationTask = startPlaceholder.StartCloseStartAnimation(); - // await animationTask; // wait for the animation task to finish - Hide(); - } - public void AlignStartifyWithTaskbar(Window window) - { - try - { - //Align the start menu with taskbar alignment (center or left) - RegistryKey alignkey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"); - - int alignvalue = (int)alignkey.GetValue("TaskbarAl"); - - if (alignvalue.ToString() == "0") - { - var desktopWorkingArea = SystemParameters.WorkArea; - window.Left = 0; - window.Top = desktopWorkingArea.Bottom - window.Height; - } - else if (alignvalue.ToString() == "1") - { - // Calculate the screen center coordinates - double screenWidth = SystemParameters.PrimaryScreenWidth; - double screenHeight = SystemParameters.PrimaryScreenHeight; - var desktopWorkingArea = SystemParameters.WorkArea; - double windowWidth = window.Width; - double windowHeight = window.Height; - - double left = (screenWidth - windowWidth) / 2; - - // Set the window position to the center of the screen - window.Left = left; - window.Top = desktopWorkingArea.Bottom - window.Height; - } - } - catch (Exception ex) - { - ModernWpf.MessageBox.Show("Startify has issues reading the taskbar alignment registry key. The default(left) alignment will be used. Error code: " + ex.ToString(), "Startify Backend Error", MessageBoxButton.OK, SymbolGlyph.Error, MessageBoxResult.OK); - } - } - public StartMenu10() - { - // Initialize Startify - InitializeComponent(); - string configFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Startify", "settings.cfg"); - - try - { - if (File.Exists(configFilePath)) - { - string hookingMethod = GetHookingMethod(configFilePath); - - switch (hookingMethod.ToUpperInvariant()) - { - case "AHK": - ModernWpf.MessageBox.Show("AutoHotKey Start Button Hooking Method Selected. Note: This mode is prototype and might misbehave or not work at all. Check Startify Documentation before using this.", "Startify Prototype Features", MessageBoxButton.OK, SymbolGlyph.Construction, MessageBoxResult.OK); - break; - - case "Standard": - StartListener = new WinButtonHook(); - StartListener.StartTriggered += OnStartTriggered; - StartListener.FindAndActivateWindow(); - break; - - default: - ModernWpf.MessageBox.Show("Invalid Start Button hooking method specified. Default(Standard) type will be used.", "Startify Misconfiguration Detected", MessageBoxButton.OK, SymbolGlyph.Warning, MessageBoxResult.OK); - StartListener = new WinButtonHook(); - StartListener.StartTriggered += OnStartTriggered; - StartListener.FindAndActivateWindow(); - break; - } - } - else - { - MessageBox.Show("Configuration file not found: " + configFilePath); - } - } - catch (Exception ex) - { - MessageBox.Show("Error reading configuration file: " + ex.Message); - } - async void OnStartTriggered(object sender, EventArgs e) - { - var newVisibility = Visibility == Visibility.Visible ? Visibility.Hidden : Visibility.Visible; - - if (newVisibility == Visibility.Hidden) - { - var startPlaceholder = StartMenuIslandhCompact.Child as Shell.Interface.StartMenuCompact.StartMenuCompact; - // Task animationTask = startPlaceholder.StartCloseStartAnimation(); - // await animationTask; // Wait for the animation task to finish - Hide(); // Hide the window - } - - Visibility = newVisibility; - - if (Visibility == Visibility.Visible) - { - Show(); - WindowActivator.ActivateWindow(new System.Windows.Interop.WindowInteropHelper(StartMenu10Host).Handle); - this.Focus(); - } - } - // Do this so the app wont wait for user start button press on startup. - Show(); - Hide(); - AlignStartifyWithTaskbar(this); - } - } -} diff --git a/BackEnd/StartMenuVariants/StartMenu11.xaml.cs b/BackEnd/StartMenuVariants/StartMenu11.xaml.cs index 43d3229..9951ceb 100644 --- a/BackEnd/StartMenuVariants/StartMenu11.xaml.cs +++ b/BackEnd/StartMenuVariants/StartMenu11.xaml.cs @@ -65,12 +65,13 @@ public partial class StartMenu11 : System.Windows.Window [DllImport("user32.dll")] static extern byte MapVirtualKey(byte wCode, int wMap); App Engine = App.Current as App; + string configFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Startify", "Settings.cfg"); //////////////////////////////////////////////////////////////////////////// // Custom Items under this comment, specific for this start menu type // So like, this start menu uses tiles, so here will be the tile specific stuff //////////////////////////////////////////////////////////////////////////// - + private void DisableTiles(object sender, EventArgs e) { var startPlaceholder = StartMenuIslandh.Child as Shell.Interface.StartMenu11.StartMenu; @@ -250,9 +251,53 @@ group p by char.IsDigit(p.Alph[0]) ? "#" : p.Alph into g LoadTiles(); ThemingSetup(); Engine.ShowNotification(); - ApplySettings(startPlaceholder); + if (!File.Exists(configFilePath)) + { + try + { + // Ensure the directory exists + string directoryPath = Path.GetDirectoryName(configFilePath); + if (!Directory.Exists(directoryPath)) + { + Directory.CreateDirectory(directoryPath); + } + + // Template content + string templateContent = "DockedDesign=false\n" + + "DisplayTiles=true\n" + + "ShowSettingsButton=true\n" + + "ShowExplorerButton=true\n" + + "ShowDocumentsButton=true\n" + + "ShowDownloadsButton=true\n" + + "ShowMusicButton=false\n" + + "ShowPicturesButton=false\n" + + "ShowMoviesButton=false\n" + + "ShowNetworkButton=false\n" + + "ShowPersonalFolderButton=false\n" + + "TooltipCaption=Start\n" + + "TooltipName=Start"; + + // Write the template content to the file + File.WriteAllText(configFilePath, templateContent); + + // Update the status + ModernWpf.MessageBox.Show("Config file created successfully. Press OK to continue.", "Startify first run completed", MessageBoxButton.OK, SymbolGlyph.Info, MessageBoxResult.OK); + ApplySettings(startPlaceholder); + } + catch (Exception ex) + { + ModernWpf.MessageBox.Show("More information: \n" + ex.ToString(), "Startify first run failed", MessageBoxButton.OK, SymbolGlyph.Info, MessageBoxResult.OK); + } + } + else + { + // Config file already exists + ApplySettings(startPlaceholder); + } } + + private static void SetButtonVisibility(string configFilePath, string settingName, string buttonName, Shell.Interface.StartMenu11.StartMenu startPlaceholder) { string settingValue = GetConfigFileEntry(configFilePath, settingName); @@ -274,7 +319,6 @@ private static void SetButtonVisibility(string configFilePath, string settingNam public void ApplySettings(Shell.Interface.StartMenu11.StartMenu startPlaceholder) { - string configFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Startify", "Settings.cfg"); // Handle DockedDesign separately as it has a unique action string dockedDesignSetting = GetConfigFileEntry(configFilePath, "DockedDesign"); diff --git a/FrontEnd/Interface/StartMenu10/Pages/AppList.xaml b/FrontEnd/Interface/StartMenu10/Pages/AppList.xaml deleted file mode 100644 index 8447736..0000000 --- a/FrontEnd/Interface/StartMenu10/Pages/AppList.xaml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - diff --git a/FrontEnd/Interface/StartMenu10/Pages/AppList.xaml.cs b/FrontEnd/Interface/StartMenu10/Pages/AppList.xaml.cs deleted file mode 100644 index 5b41371..0000000 --- a/FrontEnd/Interface/StartMenu10/Pages/AppList.xaml.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using Windows.Foundation; -using Windows.Foundation.Collections; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Controls.Primitives; -using Windows.UI.Xaml.Data; -using Windows.UI.Xaml.Input; -using Windows.UI.Xaml.Media; -using Windows.UI.Xaml.Navigation; - -//Szablon elementu Pusta strona jest udokumentowany na stronie https://go.microsoft.com/fwlink/?LinkId=234238 - -namespace Shell.Interface.StartMenu10.Pages -{ - /// - /// Pusta strona, która może być używana samodzielnie lub do której można nawigować wewnątrz ramki. - /// - public sealed partial class AppList : Page - { - public AppList() - { - this.InitializeComponent(); - } - } -} diff --git a/FrontEnd/Interface/StartMenu10/Pages/Tiles.xaml b/FrontEnd/Interface/StartMenu10/Pages/Tiles.xaml deleted file mode 100644 index a07ad26..0000000 --- a/FrontEnd/Interface/StartMenu10/Pages/Tiles.xaml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - diff --git a/FrontEnd/Interface/StartMenu10/Pages/Tiles.xaml.cs b/FrontEnd/Interface/StartMenu10/Pages/Tiles.xaml.cs deleted file mode 100644 index 4f518fb..0000000 --- a/FrontEnd/Interface/StartMenu10/Pages/Tiles.xaml.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using Windows.Foundation; -using Windows.Foundation.Collections; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Controls.Primitives; -using Windows.UI.Xaml.Data; -using Windows.UI.Xaml.Input; -using Windows.UI.Xaml.Media; -using Windows.UI.Xaml.Navigation; - -//Szablon elementu Pusta strona jest udokumentowany na stronie https://go.microsoft.com/fwlink/?LinkId=234238 - -namespace Shell.Interface.StartMenu10.Pages -{ - /// - /// Pusta strona, która może być używana samodzielnie lub do której można nawigować wewnątrz ramki. - /// - public sealed partial class Tiles : Page - { - public Tiles() - { - this.InitializeComponent(); - } - } -} diff --git a/FrontEnd/Interface/StartMenu10/Pages/TilesAppList.xaml b/FrontEnd/Interface/StartMenu10/Pages/TilesAppList.xaml deleted file mode 100644 index 5ce2824..0000000 --- a/FrontEnd/Interface/StartMenu10/Pages/TilesAppList.xaml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - diff --git a/FrontEnd/Interface/StartMenu10/Pages/TilesAppList.xaml.cs b/FrontEnd/Interface/StartMenu10/Pages/TilesAppList.xaml.cs deleted file mode 100644 index 95f4458..0000000 --- a/FrontEnd/Interface/StartMenu10/Pages/TilesAppList.xaml.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using Windows.Foundation; -using Windows.Foundation.Collections; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Controls.Primitives; -using Windows.UI.Xaml.Data; -using Windows.UI.Xaml.Input; -using Windows.UI.Xaml.Media; -using Windows.UI.Xaml.Navigation; - -//Szablon elementu Pusta strona jest udokumentowany na stronie https://go.microsoft.com/fwlink/?LinkId=234238 - -namespace Shell.Interface.StartMenu10.Pages -{ - /// - /// Pusta strona, która może być używana samodzielnie lub do której można nawigować wewnątrz ramki. - /// - public sealed partial class TilesAppList : Page - { - public TilesAppList() - { - this.InitializeComponent(); - } - } -} diff --git a/FrontEnd/Interface/StartMenu10/StartMenu.xaml b/FrontEnd/Interface/StartMenu10/StartMenu.xaml deleted file mode 100644 index 3fa6980..0000000 --- a/FrontEnd/Interface/StartMenu10/StartMenu.xaml +++ /dev/null @@ -1,131 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Pinned - - - - -