8
8
using Flow . Launcher . Core ;
9
9
using ChefKeys ;
10
10
using System . Globalization ;
11
+ using Flow . Launcher . Infrastructure . Logger ;
11
12
12
13
namespace Flow . Launcher . Helper ;
13
14
@@ -39,38 +40,49 @@ internal static void OnToggleHotkeyWithChefKeys()
39
40
40
41
private static void SetHotkey ( string hotkeyStr , EventHandler < HotkeyEventArgs > action )
41
42
{
42
- if ( hotkeyStr == "LWin" || hotkeyStr == "RWin" )
43
- {
44
- SetWithChefKeys ( hotkeyStr ) ;
45
- return ;
46
- }
47
-
48
43
var hotkey = new HotkeyModel ( hotkeyStr ) ;
49
44
SetHotkey ( hotkey , action ) ;
50
45
}
51
46
52
47
private static void SetWithChefKeys ( string hotkeyStr )
53
48
{
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
+ }
56
64
}
57
65
58
66
internal static void SetHotkey ( HotkeyModel hotkey , EventHandler < HotkeyEventArgs > action )
59
67
{
60
68
string hotkeyStr = hotkey . ToString ( ) ;
61
-
62
- if ( hotkeyStr == "LWin" || hotkeyStr == "RWin" )
63
- {
64
- SetWithChefKeys ( hotkeyStr ) ;
65
- return ;
66
- }
67
-
68
69
try
69
70
{
71
+ if ( hotkeyStr == "LWin" || hotkeyStr == "RWin" )
72
+ {
73
+ SetWithChefKeys ( hotkeyStr ) ;
74
+ return ;
75
+ }
76
+
70
77
HotkeyManager . Current . AddOrReplace ( hotkeyStr , hotkey . CharKey , hotkey . ModifierKeys , action ) ;
71
78
}
72
- catch ( Exception )
79
+ catch ( Exception e )
73
80
{
81
+ Log . Error (
82
+ string . Format ( "|HotkeyMapper.SetHotkey|Error registering hotkey {2}: {0} \n StackTrace:{1}" ,
83
+ e . Message ,
84
+ e . StackTrace ,
85
+ hotkeyStr ) ) ;
74
86
string errorMsg = string . Format ( InternationalizationManager . Instance . GetTranslation ( "registerHotkeyFailed" ) , hotkeyStr ) ;
75
87
string errorMsgTitle = InternationalizationManager . Instance . GetTranslation ( "MessageBoxTitle" ) ;
76
88
MessageBoxEx . Show ( errorMsg , errorMsgTitle ) ;
@@ -79,15 +91,26 @@ internal static void SetHotkey(HotkeyModel hotkey, EventHandler<HotkeyEventArgs>
79
91
80
92
internal static void RemoveHotkey ( string hotkeyStr )
81
93
{
82
- if ( hotkeyStr == "LWin" || hotkeyStr == "RWin" )
94
+ try
83
95
{
84
- RemoveWithChefKeys ( hotkeyStr ) ;
85
- return ;
86
- }
96
+ if ( hotkeyStr == "LWin" || hotkeyStr == "RWin" )
97
+ {
98
+ RemoveWithChefKeys ( hotkeyStr ) ;
99
+ return ;
100
+ }
87
101
88
- if ( ! string . IsNullOrEmpty ( hotkeyStr ) )
102
+ if ( ! string . IsNullOrEmpty ( hotkeyStr ) )
103
+ HotkeyManager . Current . Remove ( hotkeyStr ) ;
104
+ }
105
+ catch ( Exception e )
89
106
{
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 ) ;
91
114
}
92
115
}
93
116
0 commit comments