diff --git a/EverythingToolbar.Launcher/Launcher.cs b/EverythingToolbar.Launcher/Launcher.cs index deae71c01..41baa538d 100644 --- a/EverythingToolbar.Launcher/Launcher.cs +++ b/EverythingToolbar.Launcher/Launcher.cs @@ -7,6 +7,7 @@ using System.Windows; using System.Windows.Forms; using System.Windows.Input; +using System.Windows.Shell; using EverythingToolbar.Helpers; using Microsoft.Xaml.Behaviors; using NHotkey; @@ -19,10 +20,12 @@ namespace EverythingToolbar.Launcher { internal static class Launcher { - private const string EventName = "EverythingToolbarToggleEvent"; + private const string ToggleEventName = "EverythingToolbarToggleEvent"; + private const string StartSetupAssistantEventName = "StartSetupAssistantEvent"; private const string MutexName = "EverythingToolbar.Launcher"; private static bool _searchWindowRecentlyClosed; private static Timer _searchWindowRecentlyClosedTimer; + private static NotifyIcon notifyIcon; private class LauncherWindow : Window { @@ -30,6 +33,9 @@ public LauncherWindow(NotifyIcon icon) { ToolbarLogger.Initialize("Launcher"); + notifyIcon = icon; + SetupJumpList(); + _searchWindowRecentlyClosedTimer = new Timer(500); _searchWindowRecentlyClosedTimer.AutoReset = false; _searchWindowRecentlyClosedTimer.Elapsed += (s, e) => { _searchWindowRecentlyClosed = false; }; @@ -48,7 +54,7 @@ public LauncherWindow(NotifyIcon icon) StartToggleListener(); - if (!File.Exists(Utils.GetTaskbarShortcutPath())) + if (!ToolbarSettings.User.IsSetupAssistantDisabled && !File.Exists(Utils.GetTaskbarShortcutPath())) new SetupAssistant(icon).Show(); if (!ShortcutManager.Instance.AddOrReplace("FocusSearchBox", @@ -70,6 +76,19 @@ public LauncherWindow(NotifyIcon icon) SearchWindow.Instance.Hiding += OnSearchWindowHiding; } + private void SetupJumpList() + { + JumpList jumpList = new JumpList(); + jumpList.JumpItems.Add(new JumpTask + { + Title = Properties.Resources.ContextMenuRunSetupAssistant, + Description = Properties.Resources.ContextMenuRunSetupAssistant, + ApplicationPath = System.Reflection.Assembly.GetEntryAssembly().Location, + Arguments = "--run-setup-assistant" + }); + JumpList.SetJumpList(Application.Current, jumpList); + } + private static void OnSearchWindowHiding(object sender, EventArgs e) { _searchWindowRecentlyClosed = true; @@ -85,13 +104,22 @@ private void StartToggleListener() { Task.Factory.StartNew(() => { - var wh = new EventWaitHandle(false, EventResetMode.AutoReset, EventName); + var wh = new EventWaitHandle(false, EventResetMode.AutoReset, ToggleEventName); while (true) { wh.WaitOne(); ToggleWindow(); } }); + Task.Factory.StartNew(() => + { + var wh = new EventWaitHandle(false, EventResetMode.AutoReset, StartSetupAssistantEventName); + while (true) + { + wh.WaitOne(); + OpenSetupAssistant(); + } + }); } private void ToggleWindow() @@ -105,6 +133,14 @@ private void ToggleWindow() SearchWindow.Instance.Toggle(); }); } + + private void OpenSetupAssistant() + { + Dispatcher?.Invoke(() => + { + new SetupAssistant(notifyIcon).Show(); + }); + } } private static string GetIconPath() @@ -118,7 +154,7 @@ private static string GetIconPath() } [STAThread] - private static void Main() + private static void Main(string[] args) { using (new Mutex(false, MutexName, out var createdNew)) { @@ -128,11 +164,11 @@ private static void Main() { var app = new Application(); trayIcon.Icon = Icon.ExtractAssociatedIcon(GetIconPath()); - trayIcon.ContextMenu = new ContextMenu(new [] { + trayIcon.ContextMenu = new ContextMenu(new[] { new MenuItem(Resources.ContextMenuRunSetupAssistant, (s, e) => { new SetupAssistant(trayIcon).Show(); }), new MenuItem(Resources.ContextMenuQuit, (s, e) => { app.Shutdown(); }) }); - trayIcon.Visible = true; + trayIcon.Visible = ToolbarSettings.User.IsTrayIconEnabled; app.Run(new LauncherWindow(trayIcon)); } } @@ -140,7 +176,14 @@ private static void Main() { try { - EventWaitHandle.OpenExisting(EventName).Set(); + if (args.Length > 0 && args[0] == "--run-setup-assistant") + { + EventWaitHandle.OpenExisting(StartSetupAssistantEventName).Set(); + } + else + { + EventWaitHandle.OpenExisting(ToggleEventName).Set(); + } } catch (Exception ex) { diff --git a/EverythingToolbar.Launcher/Properties/Resources.Designer.cs b/EverythingToolbar.Launcher/Properties/Resources.Designer.cs index b1bb80590..13a9a1936 100644 --- a/EverythingToolbar.Launcher/Properties/Resources.Designer.cs +++ b/EverythingToolbar.Launcher/Properties/Resources.Designer.cs @@ -105,6 +105,42 @@ public static string ContextMenuRunSetupAssistant { } } + /// + /// Looks up a localized string similar to Are you sure you want to exit the setup assistant? EverythingToolbar will only be accessible using the keyboard shortcut. You can access the setup assistant again via the system tray icon to pin the search icon to the taskbar.. + /// + public static string SetupAssistantDisableWarningText { + get { + return ResourceManager.GetString("SetupAssistantDisableWarningText", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Exit Setup Assistant. + /// + public static string SetupAssistantDisableWarningTitle { + get { + return ResourceManager.GetString("SetupAssistantDisableWarningTitle", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to By enabling the system tray icon you can quit the EverythingToolbar background process at any time. Without it, EverythingToolbar can always be quit via the task manager.. + /// + public static string SetupAssistantFifthStepText { + get { + return ResourceManager.GetString("SetupAssistantFifthStepText", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 5. Configure system tray icon. + /// + public static string SetupAssistantFifthStepTitle { + get { + return ResourceManager.GetString("SetupAssistantFifthStepTitle", resourceCulture); + } + } + /// /// Looks up a localized string similar to Select one of the following taskbar icons:. /// diff --git a/EverythingToolbar.Launcher/Properties/Resources.resx b/EverythingToolbar.Launcher/Properties/Resources.resx index 6acee00ef..6aa3b3adc 100644 --- a/EverythingToolbar.Launcher/Properties/Resources.resx +++ b/EverythingToolbar.Launcher/Properties/Resources.resx @@ -165,4 +165,16 @@ 1. Taskbar icon + + By enabling the system tray icon you can quit the EverythingToolbar background process at any time. Without it, EverythingToolbar can always be quit via the task manager. + + + 5. Configure system tray icon + + + Are you sure you want to exit the setup assistant? EverythingToolbar will only be accessible using the keyboard shortcut. You can access the setup assistant again via the system tray icon to pin the search icon to the taskbar. + + + Exit Setup Assistant + \ No newline at end of file diff --git a/EverythingToolbar.Launcher/SetupAssistant.xaml b/EverythingToolbar.Launcher/SetupAssistant.xaml index 0c0ca77f4..13145c0f3 100644 --- a/EverythingToolbar.Launcher/SetupAssistant.xaml +++ b/EverythingToolbar.Launcher/SetupAssistant.xaml @@ -5,11 +5,12 @@ xmlns:b="clr-namespace:EverythingToolbar.Behaviors;assembly=EverythingToolbar" xmlns:properties="clr-namespace:EverythingToolbar.Launcher.Properties" WindowStartupLocation="CenterScreen" - Height="410" + Height="450" Background="Transparent" WindowStyle="ToolWindow" Title="{x:Static properties:Resources.SetupAssistantTitle}" Closed="OnClosed" + Closing="OnClosing" Foreground="White" Width="575"> @@ -203,6 +204,25 @@ Unchecked="AutostartChanged" /> + + + + + + + diff --git a/EverythingToolbar.Launcher/SetupAssistant.xaml.cs b/EverythingToolbar.Launcher/SetupAssistant.xaml.cs index 780047f97..e66e3646b 100644 --- a/EverythingToolbar.Launcher/SetupAssistant.xaml.cs +++ b/EverythingToolbar.Launcher/SetupAssistant.xaml.cs @@ -28,6 +28,7 @@ public SetupAssistant(NotifyIcon icon) AutostartCheckBox.IsChecked = Utils.GetAutostartState(); HideWindowsSearchCheckBox.IsChecked = !Utils.GetWindowsSearchEnabledState(); + TrayIconCheckBox.IsChecked = ToolbarSettings.User.IsTrayIconEnabled; CreateFileWatcher(_taskbarShortcutPath); @@ -51,6 +52,10 @@ private void OnLoaded(object sender, RoutedEventArgs e) } _iconHasChanged = false; + + // Bring to front + Topmost = true; + Topmost = false; } private void CreateFileWatcher(string taskbarShortcutPath) @@ -101,6 +106,31 @@ private void AutostartChanged(object sender, RoutedEventArgs e) Utils.SetAutostartState(AutostartCheckBox.IsChecked != null && (bool)AutostartCheckBox.IsChecked); } + private void TrayIconChanged(object sender, RoutedEventArgs e) + { + ToolbarSettings.User.IsTrayIconEnabled = TrayIconCheckBox.IsChecked != null && (bool)TrayIconCheckBox.IsChecked; + } + + private void OnClosing(object sender, System.ComponentModel.CancelEventArgs e) + { + if (_unlockedPages == TotalPages) + return; + + var disableSetupAssistant = MessageBox.Show( + Properties.Resources.SetupAssistantDisableWarningText, + Properties.Resources.SetupAssistantDisableWarningTitle, + MessageBoxButton.YesNo, + MessageBoxImage.Exclamation + ) == MessageBoxResult.Yes; + if (disableSetupAssistant) + { + ToolbarSettings.User.IsSetupAssistantDisabled = disableSetupAssistant; + // Ensuring the user can access the setup assistant + ToolbarSettings.User.IsTrayIconEnabled = disableSetupAssistant; + } + e.Cancel = !disableSetupAssistant; + } + private void OnCloseClicked(object sender, RoutedEventArgs e) { Close(); @@ -108,7 +138,7 @@ private void OnCloseClicked(object sender, RoutedEventArgs e) private void OnClosed(object sender, EventArgs e) { - _icon.Visible = true; + _icon.Visible = ToolbarSettings.User.IsTrayIconEnabled; if (_watcher != null) { diff --git a/EverythingToolbar/ToolbarSettings.cs b/EverythingToolbar/ToolbarSettings.cs index 02a250523..e910bbcb1 100644 --- a/EverythingToolbar/ToolbarSettings.cs +++ b/EverythingToolbar/ToolbarSettings.cs @@ -92,6 +92,12 @@ public interface IToolbarSettings [Option(DefaultValue = true)] bool IsUpdateNotificationsEnabled { get; set; } + [Option(DefaultValue = false)] + bool IsSetupAssistantDisabled { get; set; } + + [Option(DefaultValue = false)] + bool IsTrayIconEnabled { get; set; } + [Option(DefaultValue = true)] bool IsAutoSelectFirstResult { get; set; } @@ -485,6 +491,32 @@ public bool IsUpdateNotificationsEnabled } } + public bool IsSetupAssistantDisabled + { + get => _settings.IsSetupAssistantDisabled; + set + { + if (_settings.IsSetupAssistantDisabled != value) + { + _settings.IsSetupAssistantDisabled = value; + OnPropertyChanged(); + } + } + } + + public bool IsTrayIconEnabled + { + get => _settings.IsTrayIconEnabled; + set + { + if (_settings.IsTrayIconEnabled != value) + { + _settings.IsTrayIconEnabled = value; + OnPropertyChanged(); + } + } + } + public bool IsAutoSelectFirstResult { get => _settings.IsAutoSelectFirstResult;