diff --git a/Ninjacrab.PersistentWindows.Solution/Common/HotKeyWindow.cs b/Ninjacrab.PersistentWindows.Solution/Common/HotKeyWindow.cs index 0a1c38c..71712a0 100644 --- a/Ninjacrab.PersistentWindows.Solution/Common/HotKeyWindow.cs +++ b/Ninjacrab.PersistentWindows.Solution/Common/HotKeyWindow.cs @@ -276,7 +276,7 @@ namespace PersistentWindows.Common StartAliveTimer(1); } - bool IsBrowserWindow(IntPtr hwnd) + private bool IsBrowserWindow(IntPtr hwnd) { return PersistentWindowProcessor.IsBrowserWindow(hwnd); } @@ -1109,7 +1109,7 @@ namespace PersistentWindows.Common User32.SetForegroundWindow(Handle); } - private static IntPtr GetForegroundWindow(bool strict = false) + public static IntPtr GetForegroundWindow(bool strict = false) { return PersistentWindowProcessor.GetForegroundWindow(strict); } diff --git a/Ninjacrab.PersistentWindows.Solution/Common/PersistentWindowProcessor.cs b/Ninjacrab.PersistentWindows.Solution/Common/PersistentWindowProcessor.cs index c846f3c..cff4896 100644 --- a/Ninjacrab.PersistentWindows.Solution/Common/PersistentWindowProcessor.cs +++ b/Ninjacrab.PersistentWindows.Solution/Common/PersistentWindowProcessor.cs @@ -4177,7 +4177,7 @@ namespace PersistentWindows.Common } - private string GetProcExePath(uint proc_id) + public static string GetProcExePath(uint proc_id) { IntPtr hProcess = Kernel32.OpenProcess(Kernel32.ProcessAccessFlags.QueryInformation, false, proc_id); string pathToExe = string.Empty; diff --git a/Ninjacrab.PersistentWindows.Solution/SystrayShell/HotKey.cs b/Ninjacrab.PersistentWindows.Solution/SystrayShell/HotKey.cs index 4327c5d..b541206 100644 --- a/Ninjacrab.PersistentWindows.Solution/SystrayShell/HotKey.cs +++ b/Ninjacrab.PersistentWindows.Solution/SystrayShell/HotKey.cs @@ -63,8 +63,9 @@ namespace PersistentWindows.SystrayShell User32.KeyModifier modifier = (User32.KeyModifier)((int)m.LParam & 0xFFFF); // The modifier of the hotkey that was pressed. int id = m.WParam.ToInt32(); // The id of the hotkey that was pressed. + IntPtr fgWnd = PersistentWindowProcessor.GetForegroundWindow(strict : true); hkwin.HotKeyPressed(from_menu : false); - if (HotKeyWindow.invokedFromBrowser) + if (PersistentWindowProcessor.IsBrowserWindow(fgWnd)) { Program.HideRestoreTip(false); //hide icon Program.HideRestoreTip(); //show icon @@ -73,12 +74,28 @@ namespace PersistentWindows.SystrayShell { init = false; string webpage_commander_notification = Path.Combine(Program.AppdataFolder, "webpage_commander_notification"); - if (!File.Exists(webpage_commander_notification)) + if (File.Exists(webpage_commander_notification)) { - File.Create(webpage_commander_notification); - Process.Start(Program.ProjectUrl + "/blob/master/webpage_commander.md"); + Program.systrayForm.notifyIconMain.ShowBalloonTip(8000, "webpage commander is invoked via hotkey", "Press the hotkey (Alt + W) again to revoke", ToolTipIcon.Info); + } + else + { + try + { + File.Create(webpage_commander_notification); + + uint processId; + User32.GetWindowThreadProcessId(fgWnd, out processId); + string procPath = PersistentWindowProcessor.GetProcExePath(processId); + Process.Start(procPath, Program.ProjectUrl + "/blob/master/webpage_commander.md"); + } + catch (Exception ex) + { + Log.Error(ex.ToString()); + Program.systrayForm.notifyIconMain.ShowBalloonTip(8000, "webpage commander is invoked via hotkey", "Press the hotkey (Alt + W) again to revoke", ToolTipIcon.Info); + Process.Start(Program.ProjectUrl + "/blob/master/webpage_commander.md"); + } } - Program.systrayForm.notifyIconMain.ShowBalloonTip(8000, "webpage commander is invoked via hotkey", "Press the hotkey (Alt + W) again to revoke", ToolTipIcon.Info); } } diff --git a/Ninjacrab.PersistentWindows.Solution/SystrayShell/Program.cs b/Ninjacrab.PersistentWindows.Solution/SystrayShell/Program.cs index 044ce08..8dbb07b 100644 --- a/Ninjacrab.PersistentWindows.Solution/SystrayShell/Program.cs +++ b/Ninjacrab.PersistentWindows.Solution/SystrayShell/Program.cs @@ -29,7 +29,7 @@ namespace PersistentWindows.SystrayShell private const int MaxSnapshots = 38; // 0-9, a-z, ` and final one for undo - static PersistentWindowProcessor pwp = null; + public static PersistentWindowProcessor pwp = null; public static SystrayForm systrayForm = null; static bool silent = false; //suppress all balloon tip & sound prompt static bool notification = false; //pop balloon when auto restore