public static void Main(string[] args) { Logging.Configure(); _trayIcon = new TrayIcon((s, a) => Close()); try { TerminalProcess.OnExit(() => Close()); _toggler = new Toggler(); // Transparency Settings.Get(s => { TransparentWindow.SetTransparent(TerminalProcess.Get(), s.Opacity); }); var hks = string.Join(" or ", Settings.Instance.Hotkeys.Select(hk => $"{hk.Modifiers}+{hk.Key}")); _trayIcon.Notify(ToolTipIcon.Info, $"Windows Terminal Quake is running, press {hks} to toggle."); } catch (Exception ex) { Log.Logger.Warning(ex, $"Error: {ex.Message}"); _trayIcon.Notify(ToolTipIcon.Error, $"Cannot start: '{ex.Message}'."); Close(); } }
private static void Close() { _toggler?.Dispose(); _toggler = null; _trayIcon?.Dispose(); _trayIcon = null; }
private static void Close() { exited = true; lock_obj.Release(); _toggler?.Dispose(); _toggler = null; _trayIcon?.Dispose(); _trayIcon = null; }
public static void Main(string[] args) { Logging.Configure(); _trayIcon = new TrayIcon((s, a) => Close()); try { Process process = Process.GetProcessesByName("WindowsTerminal").FirstOrDefault(); if (process == null) { process = new Process { StartInfo = new ProcessStartInfo { FileName = "wt", UseShellExecute = false, RedirectStandardOutput = true, WindowStyle = ProcessWindowStyle.Maximized } }; process.Start(); } process.EnableRaisingEvents = true; process.Exited += (sender, e) => { Close(); }; _toggler = new Toggler(process); // Transparency Settings.Get(s => { TransparentWindow.SetTransparent(process, s.Opacity); }); var hks = string.Join(" or ", Settings.Instance.Hotkeys.Select(hk => $"{hk.Modifiers}+{hk.Key}")); _trayIcon.Notify(ToolTipIcon.Info, $"Windows Terminal Quake is running, press {hks} to toggle."); } catch (Exception ex) { _trayIcon.Notify(ToolTipIcon.Error, $"Cannot start: '{ex.Message}'."); Close(); } }
public static void Main(string[] args) { _trayIcon = new TrayIcon((s, a) => Close()); try { _toggler = new Toggler(); _trayIcon.Notify(ToolTipIcon.Info, $"Windows Terminal Quake is running, press CTRL+~ or CTRL+Q to toggle."); } catch (Exception ex) { _trayIcon.Notify(ToolTipIcon.Error, $"Error: '{ex.Message}'."); Close(); } }
private static void Close() { _config.Save(); if (_mousehook != IntPtr.Zero) { User32.UnhookWindowsHookEx(_mousehook); } _toggler?.Dispose(); _toggler = null; _trayIcon?.Dispose(); _trayIcon = null; _closed = true; }
public static void Main(string[] args) { _trayIcon = new TrayIcon((s, a) => Close()); try { Process process = Process.GetProcessesByName("WindowsTerminal").FirstOrDefault(); if (process == null) { process = new Process { StartInfo = new ProcessStartInfo { FileName = "wt", UseShellExecute = false, RedirectStandardOutput = true, WindowStyle = ProcessWindowStyle.Maximized } }; process.Start(); } process.EnableRaisingEvents = true; process.Exited += (sender, e) => { Close(); }; _toggler = new Toggler(process); _trayIcon.Notify(ToolTipIcon.Info, $"Windows Terminal Quake is running, press CTRL+~ or CTRL+Q or CTRL+µ to toggle."); } catch (Exception ex) { _trayIcon.Notify(ToolTipIcon.Error, $"Cannot start: '{ex.Message}'."); Close(); } }
public static void Main(string[] args) { _config = new Config(); _config.Reload(); if (_config.Width < 200 || _config.Height < 40) { _config.Width = 0; _config.Height = 0; } // don't allow more than one instance to be running simultaneously var existingProcesses = Process.GetProcessesByName("windows-terminal-quake"); if (existingProcesses.Count() > 1) { try { var process = GetWindowsTerminalProcess(); if (process != null) { User32.SetForegroundWindow(process.MainWindowHandle); } } catch (Exception) { } return; } Application.ApplicationExit += (sender, e) => { Close(); }; _trayIcon = new TrayIcon((s, a) => Close()); try { var process = GetWindowsTerminalProcess(); if (process == null) { process = CreateWindowsTerminalProcess(); } _toggler = new Toggler(process, _config); _trayIcon.Notify(ToolTipIcon.Info, $"Windows Terminal Quake is running, press CTRL+~ or CTRL+Q to toggle."); // capture mouse click event - can't seem to make this work // we want to be able to handle mouse-up event to make resizing seamless // //_mousehook = User32.SetWindowsHookEx( // User32.HookType.WH_MOUSE, // new User32.CBTProc(WinMouseEvent), // IntPtr.Zero, // User32.GetCurrentThreadId() // ); // capture window resize event _winEventHookDispatcher = new DebounceDispatcher(); User32.SetWinEventHook( User32.EVENT_OBJECT_LOCATIONCHANGE, User32.EVENT_OBJECT_LOCATIONCHANGE, //0x8000, //0x8FFF, System.IntPtr.Zero, WinEventProc, (uint)process.Id, (uint)0, User32.WINEVENT_OUTOFCONTEXT ); User32.MSG msg; while (!_closed) { int result = User32.GetMessage(out msg, IntPtr.Zero, 0, 0); if (result == 0) { break; } if (result == -1) { throw new Exception(); } User32.TranslateMessage(msg); User32.DispatchMessage(msg); } } catch (Exception ex) { _trayIcon.Notify(ToolTipIcon.Error, $"Cannot start: '{ex.Message}'."); Close(); } }
public static void Main(string[] args) { Mutex mutex = new Mutex(true, "windows-terminal-quake"); _trayIcon = new TrayIcon((s, a) => Close()); if (!mutex.WaitOne(TimeSpan.Zero, true)) { _trayIcon.Notify(ToolTipIcon.Info, "Only one instance allowed"); exited = true; _trayIcon?.Dispose(); } Logging.Configure(); var first_run = true; try { while (!exited) { lock_obj.WaitOne(); if (exited) { continue; } Process process = Process.GetProcessesByName("WindowsTerminal").FirstOrDefault(); if (process == null || process.MainWindowHandle == IntPtr.Zero) { process = new Process { StartInfo = new ProcessStartInfo { FileName = "wt", UseShellExecute = false, RedirectStandardOutput = true, WindowStyle = ProcessWindowStyle.Maximized } }; process.Start(); process.WaitForExit(); process = Process.GetProcessesByName("WindowsTerminal").FirstOrDefault(); if (process == null) { throw new ApplicationException("Wrapper was unable to start Windows Terminal"); } Thread.Sleep(500); } process.EnableRaisingEvents = true; process.Exited += (sender, e) => { if (Settings.Instance.Restart) { _toggler?.Dispose(); _toggler = null; process = null; lock_obj.Release(); } else { Close(); } }; _toggler = new Toggler(process); if (first_run) { var hks = string.Join(" or ", Settings.Instance.Hotkeys.Select(hk => $"{hk.Modifiers}+{hk.Key}")); _trayIcon.Notify(ToolTipIcon.Info, $"Windows Terminal Quake is running, press {hks} to toggle."); first_run = false; } } } catch (Exception ex) { _trayIcon.Notify(ToolTipIcon.Error, $"Cannot start: '{ex.Message}'."); Close(); } }