Skip to content

Commit

Permalink
0.2
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Lixkote committed Aug 5, 2024
1 parent 0ae1e0d commit df7fa83
Show file tree
Hide file tree
Showing 19 changed files with 109 additions and 582 deletions.
40 changes: 22 additions & 18 deletions BackEnd/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using System.Threading.Tasks;
using System.Windows.Input;
using WPF.Views;
using System.Windows.Media;
using System.Drawing;

namespace WPF
{
Expand Down Expand Up @@ -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();
Expand All @@ -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)
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down
29 changes: 24 additions & 5 deletions BackEnd/Helpers/WinButtonHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 0 additions & 22 deletions BackEnd/StartMenuVariants/StartMenu10.xaml

This file was deleted.

187 changes: 0 additions & 187 deletions BackEnd/StartMenuVariants/StartMenu10.xaml.cs

This file was deleted.

Loading

0 comments on commit df7fa83

Please sign in to comment.