88using Flow . Launcher . Core ;
99using ChefKeys ;
1010using System . Globalization ;
11+ using Flow . Launcher . Infrastructure . Logger ;
1112
1213namespace Flow . Launcher . Helper ;
1314
@@ -39,38 +40,49 @@ internal static void OnToggleHotkeyWithChefKeys()
3940
4041 private static void SetHotkey ( string hotkeyStr , EventHandler < HotkeyEventArgs > action )
4142 {
42- if ( hotkeyStr == "LWin" || hotkeyStr == "RWin" )
43- {
44- SetWithChefKeys ( hotkeyStr ) ;
45- return ;
46- }
47-
4843 var hotkey = new HotkeyModel ( hotkeyStr ) ;
4944 SetHotkey ( hotkey , action ) ;
5045 }
5146
5247 private static void SetWithChefKeys ( string hotkeyStr )
5348 {
54- ChefKeysManager . RegisterHotkey ( hotkeyStr , hotkeyStr , OnToggleHotkeyWithChefKeys ) ;
55- ChefKeysManager . Start ( ) ;
49+ try
50+ {
51+ ChefKeysManager . RegisterHotkey ( hotkeyStr , hotkeyStr , OnToggleHotkeyWithChefKeys ) ;
52+ ChefKeysManager . Start ( ) ;
53+ }
54+ catch ( Exception e )
55+ {
56+ Log . Error (
57+ string . Format ( "|HotkeyMapper.SetWithChefKeys|Error registering hotkey: {0} \n StackTrace:{1}" ,
58+ e . Message ,
59+ e . StackTrace ) ) ;
60+ string errorMsg = string . Format ( InternationalizationManager . Instance . GetTranslation ( "registerHotkeyFailed" ) , hotkeyStr ) ;
61+ string errorMsgTitle = InternationalizationManager . Instance . GetTranslation ( "MessageBoxTitle" ) ;
62+ MessageBoxEx . Show ( errorMsg , errorMsgTitle ) ;
63+ }
5664 }
5765
5866 internal static void SetHotkey ( HotkeyModel hotkey , EventHandler < HotkeyEventArgs > action )
5967 {
6068 string hotkeyStr = hotkey . ToString ( ) ;
61-
62- if ( hotkeyStr == "LWin" || hotkeyStr == "RWin" )
63- {
64- SetWithChefKeys ( hotkeyStr ) ;
65- return ;
66- }
67-
6869 try
6970 {
71+ if ( hotkeyStr == "LWin" || hotkeyStr == "RWin" )
72+ {
73+ SetWithChefKeys ( hotkeyStr ) ;
74+ return ;
75+ }
76+
7077 HotkeyManager . Current . AddOrReplace ( hotkeyStr , hotkey . CharKey , hotkey . ModifierKeys , action ) ;
7178 }
72- catch ( Exception )
79+ catch ( Exception e )
7380 {
81+ Log . Error (
82+ string . Format ( "|HotkeyMapper.SetHotkey|Error registering hotkey {2}: {0} \n StackTrace:{1}" ,
83+ e . Message ,
84+ e . StackTrace ,
85+ hotkeyStr ) ) ;
7486 string errorMsg = string . Format ( InternationalizationManager . Instance . GetTranslation ( "registerHotkeyFailed" ) , hotkeyStr ) ;
7587 string errorMsgTitle = InternationalizationManager . Instance . GetTranslation ( "MessageBoxTitle" ) ;
7688 MessageBoxEx . Show ( errorMsg , errorMsgTitle ) ;
@@ -79,15 +91,26 @@ internal static void SetHotkey(HotkeyModel hotkey, EventHandler<HotkeyEventArgs>
7991
8092 internal static void RemoveHotkey ( string hotkeyStr )
8193 {
82- if ( hotkeyStr == "LWin" || hotkeyStr == "RWin" )
94+ try
8395 {
84- RemoveWithChefKeys ( hotkeyStr ) ;
85- return ;
86- }
96+ if ( hotkeyStr == "LWin" || hotkeyStr == "RWin" )
97+ {
98+ RemoveWithChefKeys ( hotkeyStr ) ;
99+ return ;
100+ }
87101
88- if ( ! string . IsNullOrEmpty ( hotkeyStr ) )
102+ if ( ! string . IsNullOrEmpty ( hotkeyStr ) )
103+ HotkeyManager . Current . Remove ( hotkeyStr ) ;
104+ }
105+ catch ( Exception e )
89106 {
90- HotkeyManager . Current . Remove ( hotkeyStr ) ;
107+ Log . Error (
108+ string . Format ( "|HotkeyMapper.RemoveHotkey|Error removing hotkey: {0} \n StackTrace:{1}" ,
109+ e . Message ,
110+ e . StackTrace ) ) ;
111+ string errorMsg = string . Format ( InternationalizationManager . Instance . GetTranslation ( "unregisterHotkeyFailed" ) , hotkeyStr ) ;
112+ string errorMsgTitle = InternationalizationManager . Instance . GetTranslation ( "MessageBoxTitle" ) ;
113+ MessageBoxEx . Show ( errorMsg , errorMsgTitle ) ;
91114 }
92115 }
93116
0 commit comments