Initial TaskbarLauncher release baseline

This commit is contained in:
Ray Berezowski
2026-06-02 17:28:25 -04:00
commit e8c0721c39
18 changed files with 2566 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
using System.IO;
namespace TaskbarLauncher.Services;
public static class StartupService
{
private const string ShortcutName = "TaskbarLauncher.lnk";
public static string StartupFolder => Environment.GetFolderPath(Environment.SpecialFolder.Startup);
public static string ShortcutPath => Path.Combine(StartupFolder, ShortcutName);
public static bool IsEnabled()
{
return File.Exists(ShortcutPath);
}
public static void SetEnabled(bool enabled)
{
if (enabled)
{
CreateShortcut();
}
else
{
RemoveShortcut();
}
}
public static string? GetShortcutTarget()
{
if (!File.Exists(ShortcutPath))
{
return null;
}
Type shellType = Type.GetTypeFromProgID("WScript.Shell")
?? throw new InvalidOperationException("Windows Script Host is not available.");
dynamic shell = Activator.CreateInstance(shellType)
?? throw new InvalidOperationException("Could not create Windows Script Host shell.");
dynamic shortcut = shell.CreateShortcut(ShortcutPath);
return shortcut.TargetPath;
}
private static void CreateShortcut()
{
Directory.CreateDirectory(StartupFolder);
string executablePath = Environment.ProcessPath ?? Path.Combine(ConfigService.AppFolder, "TaskbarLauncher.exe");
Type shellType = Type.GetTypeFromProgID("WScript.Shell")
?? throw new InvalidOperationException("Windows Script Host is not available.");
dynamic shell = Activator.CreateInstance(shellType)
?? throw new InvalidOperationException("Could not create Windows Script Host shell.");
dynamic shortcut = shell.CreateShortcut(ShortcutPath);
shortcut.TargetPath = executablePath;
shortcut.WorkingDirectory = ConfigService.AppFolder;
shortcut.Description = "Start Taskbar Launcher";
shortcut.Save();
}
private static void RemoveShortcut()
{
if (File.Exists(ShortcutPath))
{
File.Delete(ShortcutPath);
}
}
}