@@ -233,16 +233,38 @@ void attachRename(ToolStripMenuItem item, string presetKey) {
233233 bool isBuiltInPreset = ( currentPreset == "PresetExtreme" || currentPreset == "PresetGpuPriority" || currentPreset == "PresetLightUse" ) ;
234234
235235 ToolStripMenuItem fanConfigMenu = new ToolStripMenuItem ( Strings . FanConfig ) ;
236- fanConfigMenu . DropDownItems . Add ( CreateMenuItem ( Strings . FanSilentMode , "fanTableGroup" , ( s , e ) => {
237- fanTable = "silent" ;
238- LoadFanConfig ( "silent.txt" ) ;
239- SaveConfig ( "FanTable" ) ;
240- } , fanTable . Contains ( "silent" ) , Strings . FanSilentTooltip ) ) ;
241- fanConfigMenu . DropDownItems . Add ( CreateMenuItem ( Strings . FanCoolMode , "fanTableGroup" , ( s , e ) => {
242- fanTable = "cool" ;
243- LoadFanConfig ( "cool.txt" ) ;
244- SaveConfig ( "FanTable" ) ;
245- } , fanTable . Contains ( "cool" ) , Strings . FanCoolTooltip ) ) ;
236+ var silentFanItem = new ToolStripMenuItem ( Strings . FanSilentMode ) {
237+ Tag = "fanTableGroup" ,
238+ Checked = fanTable . Contains ( "silent" ) ,
239+ ToolTipText = Strings . FanSilentTooltip
240+ } ;
241+ silentFanItem . MouseUp += ( s , e ) => {
242+ if ( e . Button == MouseButtons . Left ) {
243+ fanTable = "silent" ;
244+ LoadFanConfig ( "silent.txt" ) ;
245+ SaveConfig ( "FanTable" ) ;
246+ UpdateCheckedState ( "fanTableGroup" , null , silentFanItem ) ;
247+ } else if ( e . Button == MouseButtons . Right ) {
248+ ShowFanCurveEditor ( "silent.txt" ) ;
249+ }
250+ } ;
251+ fanConfigMenu . DropDownItems . Add ( silentFanItem ) ;
252+ var coolFanItem = new ToolStripMenuItem ( Strings . FanCoolMode ) {
253+ Tag = "fanTableGroup" ,
254+ Checked = fanTable . Contains ( "cool" ) ,
255+ ToolTipText = Strings . FanCoolTooltip
256+ } ;
257+ coolFanItem . MouseUp += ( s , e ) => {
258+ if ( e . Button == MouseButtons . Left ) {
259+ fanTable = "cool" ;
260+ LoadFanConfig ( "cool.txt" ) ;
261+ SaveConfig ( "FanTable" ) ;
262+ UpdateCheckedState ( "fanTableGroup" , null , coolFanItem ) ;
263+ } else if ( e . Button == MouseButtons . Right ) {
264+ ShowFanCurveEditor ( "cool.txt" ) ;
265+ }
266+ } ;
267+ fanConfigMenu . DropDownItems . Add ( coolFanItem ) ;
246268 var customFanItem = new ToolStripMenuItem ( Strings . FanCustomMode ) {
247269 Tag = "fanTableGroup" ,
248270 Checked = fanTable . Contains ( "custom" ) ,
@@ -253,7 +275,7 @@ void attachRename(ToolStripMenuItem item, string presetKey) {
253275 if ( ApplyCustomFanConfig ( ) )
254276 UpdateCheckedState ( "fanTableGroup" , null , customFanItem ) ;
255277 } else if ( e . Button == MouseButtons . Right ) {
256- ShowCustomFanCurveEditor ( ) ;
278+ ShowFanCurveEditor ( "custom.txt" ) ;
257279 }
258280 } ;
259281 fanConfigMenu . DropDownItems . Add ( customFanItem ) ;
@@ -1241,20 +1263,37 @@ void attachRename(ToolStripMenuItem item, string presetKey) {
12411263 omenKeyMenu . DropDownItems . Add ( omenKeyPresetCandidatesMenu ) ;
12421264 omenKeyMenu . DropDownItems . Add ( new ToolStripSeparator ( ) ) ;
12431265
1244- omenKeyMenu . DropDownItems . Add ( new ToolStripMenuItem ( $ "{ Strings . OmenKeyCurrentApp } : { GetOmenKeyAppDisplayName ( ) } ") { Enabled = false } ) ;
1266+ var currentAppItem = new ToolStripMenuItem ( $ "{ Strings . OmenKeyCurrentApp } : { GetOmenKeyAppDisplayName ( ) } ") { Enabled = false } ;
1267+ var currentShortcutItem = new ToolStripMenuItem ( $ "{ Strings . OmenKeyCurrentShortcut } : { FormatOmenKeyShortcut ( omenKeyShortcut ) } ") { Enabled = false } ;
1268+
1269+ // Refresh display items every time the submenu opens.
1270+ // This covers: (a) initial startup where BuildTrayMenu runs before RestoreConfig loads saved values,
1271+ // and (b) any stale state after actions that don't trigger a full menu rebuild.
1272+ omenKeyMenu . DropDownOpening += ( s , e ) => {
1273+ currentAppItem . Text = $ "{ Strings . OmenKeyCurrentApp } : { GetOmenKeyAppDisplayName ( ) } ";
1274+ currentShortcutItem . Text = $ "{ Strings . OmenKeyCurrentShortcut } : { FormatOmenKeyShortcut ( omenKeyShortcut ) } ";
1275+ } ;
1276+
1277+ omenKeyMenu . DropDownItems . Add ( currentAppItem ) ;
12451278 omenKeyMenu . DropDownItems . Add ( CreateMenuItem ( Strings . OmenKeySelectDesktopApp , null , ( s , e ) => {
1279+ // SelectOmenKeyApp opens an OpenFileDialog which does NOT close the context menu.
1280+ // Avoid RefreshMenu() here — it would rebuild the ContextMenuStrip while this submenu
1281+ // is still visible, causing the root menu to flash and leaving the submenu showing
1282+ // stale "当前应用:" text. Instead, update the display item directly.
12461283 if ( ! SelectOmenKeyApp ( ) ) return ;
12471284 SaveConfig ( "OmenKeyAppPath" ) ;
12481285 SaveConfig ( "OmenKeyAppName" ) ;
12491286 ApplyOmenKeyAction ( OmenKeyActions . App ) ;
1250- RefreshMenu ( ) ;
1287+ currentAppItem . Text = $ "{ Strings . OmenKeyCurrentApp } : { GetOmenKeyAppDisplayName ( ) } ";
1288+ UpdateCheckedState ( "omenKeyGroup" , Strings . OmenKeyLaunchApp ) ;
12511289 } , false ) ) ;
12521290 omenKeyMenu . DropDownItems . Add ( CreateMenuItem ( Strings . OmenKeySelectUwpApp , null , ( s , e ) => {
12531291 if ( ! SelectOmenKeyUwpApp ( ) ) return ;
12541292 SaveConfig ( "OmenKeyAppPath" ) ;
12551293 SaveConfig ( "OmenKeyAppName" ) ;
12561294 ApplyOmenKeyAction ( OmenKeyActions . App ) ;
1257- RefreshMenu ( ) ;
1295+ currentAppItem . Text = $ "{ Strings . OmenKeyCurrentApp } : { GetOmenKeyAppDisplayName ( ) } ";
1296+ UpdateCheckedState ( "omenKeyGroup" , Strings . OmenKeyLaunchApp ) ;
12581297 } , false ) ) ;
12591298 omenKeyMenu . DropDownItems . Add ( CreateMenuItem ( Strings . OmenKeyClearApp , null , ( s , e ) => {
12601299 omenKeyAppPath = "" ;
@@ -1263,24 +1302,27 @@ void attachRename(ToolStripMenuItem item, string presetKey) {
12631302 SaveConfig ( "OmenKeyAppName" ) ;
12641303 if ( omenKey == OmenKeyActions . App ) {
12651304 ApplyOmenKeyAction ( OmenKeyActions . None ) ;
1305+ UpdateCheckedState ( "omenKeyGroup" , Strings . OmenKeyNone ) ;
12661306 }
1267- RefreshMenu ( ) ;
1307+ currentAppItem . Text = $ " { Strings . OmenKeyCurrentApp } : { GetOmenKeyAppDisplayName ( ) } " ;
12681308 } , false ) ) ;
12691309 omenKeyMenu . DropDownItems . Add ( new ToolStripSeparator ( ) ) ;
1270- omenKeyMenu . DropDownItems . Add ( new ToolStripMenuItem ( $ " { Strings . OmenKeyCurrentShortcut } : { FormatOmenKeyShortcut ( omenKeyShortcut ) } " ) { Enabled = false } ) ;
1310+ omenKeyMenu . DropDownItems . Add ( currentShortcutItem ) ;
12711311 omenKeyMenu . DropDownItems . Add ( CreateMenuItem ( Strings . OmenKeySetShortcut , null , ( s , e ) => {
12721312 if ( ! SelectOmenKeyShortcut ( ) ) return ;
12731313 SaveConfig ( "OmenKeyShortcut" ) ;
12741314 ApplyOmenKeyAction ( OmenKeyActions . Shortcut ) ;
1275- RefreshMenu ( ) ;
1315+ currentShortcutItem . Text = $ "{ Strings . OmenKeyCurrentShortcut } : { FormatOmenKeyShortcut ( omenKeyShortcut ) } ";
1316+ UpdateCheckedState ( "omenKeyGroup" , Strings . OmenKeyShortcut ) ;
12761317 } , false ) ) ;
12771318 omenKeyMenu . DropDownItems . Add ( CreateMenuItem ( Strings . OmenKeyClearShortcut , null , ( s , e ) => {
12781319 omenKeyShortcut = "" ;
12791320 SaveConfig ( "OmenKeyShortcut" ) ;
12801321 if ( omenKey == OmenKeyActions . Shortcut ) {
12811322 ApplyOmenKeyAction ( OmenKeyActions . None ) ;
1323+ UpdateCheckedState ( "omenKeyGroup" , Strings . OmenKeyNone ) ;
12821324 }
1283- RefreshMenu ( ) ;
1325+ currentShortcutItem . Text = $ " { Strings . OmenKeyCurrentShortcut } : { FormatOmenKeyShortcut ( omenKeyShortcut ) } " ;
12841326 } , false ) ) ;
12851327 omenKeyMenu . DropDownItems . Add ( new ToolStripSeparator ( ) ) ;
12861328 omenKeyMenu . DropDownItems . Add ( CreateMenuItem ( Strings . OmenKeyNone , "omenKeyGroup" , ( s , e ) => {
@@ -1915,38 +1957,41 @@ static void RefreshMenu() {
19151957 RestoreConfig ( ) ;
19161958 }
19171959
1918- static void ShowCustomFanCurveEditor ( ) {
1960+ // Generalized fan curve editor: handles cool.txt, silent.txt, and custom.txt.
1961+ // "Save & Apply" saves the file, switches fanTable to the corresponding mode, reloads it, and updates checkmarks.
1962+ static void ShowFanCurveEditor ( string fileName ) {
19191963 string baseDirectory = AppDomain . CurrentDomain . BaseDirectory ;
1920- string coolFilePath = Path . Combine ( baseDirectory , "cool.txt" ) ;
1921- string customFilePath = Path . Combine ( baseDirectory , "custom.txt" ) ;
1964+ string filePath = Path . Combine ( baseDirectory , fileName ) ;
1965+ bool isSilent = fileName . IndexOf ( "silent" , StringComparison . OrdinalIgnoreCase ) >= 0 ;
19221966
19231967 try {
19241968 FanCurveProfile initialProfile ;
1925- if ( File . Exists ( customFilePath ) ) {
1926- initialProfile = FanCurveProfile . Load ( customFilePath ) ;
1969+ if ( File . Exists ( filePath ) ) {
1970+ initialProfile = FanCurveProfile . Load ( filePath ) ;
19271971 } else {
1928- if ( ! File . Exists ( coolFilePath ) )
1929- CreateDefaultFanCurveProfile ( false ) . Save ( coolFilePath ) ;
1930- initialProfile = FanCurveProfile . Load ( coolFilePath ) ;
1972+ initialProfile = CreateDefaultFanCurveProfile ( isSilent ) ;
19311973 }
19321974
19331975 int cpuMaximum = maxCPUTemp ?? 100 ;
19341976 int gpuMaximum = maxGPUTemp ?? 90 ;
19351977 int detectedMaximum = platformMaxFanSpeed ?? 5600 ;
19361978 int fanMaximum = Math . Max ( 1000 , ( int ) ( Math . Ceiling ( detectedMaximum * 1.1 / 100D ) * 100D ) ) ;
1937- var editor = new FanCurveForm ( initialProfile , cpuMaximum , gpuMaximum , fanMaximum , customFilePath ) ;
1979+ var editor = new FanCurveForm ( initialProfile , cpuMaximum , gpuMaximum , fanMaximum , filePath ) ;
19381980
1939- // 订阅关闭事件,处理保存和应用
19401981 editor . FormClosed += ( sender , args ) => {
19411982 if ( editor . EditorResult == FanCurveEditorResult . SavedAndApplied ) {
1942- ApplyCustomFanConfig ( ) ;
1943- // 更新菜单勾选状态
1944- var customFanMenuItem = FindMenuItem ( trayIcon . ContextMenuStrip . Items , Strings . FanCustomMode ) ;
1945- if ( customFanMenuItem != null )
1946- UpdateCheckedState ( "fanTableGroup" , null , customFanMenuItem ) ;
1983+ string fanTableKey = System . IO . Path . GetFileNameWithoutExtension ( fileName ) . ToLowerInvariant ( ) ;
1984+ fanTable = fanTableKey ;
1985+ LoadFanConfig ( fileName ) ;
1986+ SaveConfig ( "FanTable" ) ;
1987+ string modeText =
1988+ fanTableKey == "silent" ? Strings . FanSilentMode :
1989+ fanTableKey == "cool" ? Strings . FanCoolMode :
1990+ Strings . FanCustomMode ;
1991+ UpdateCheckedState ( "fanTableGroup" , modeText ) ;
19471992 }
19481993 } ;
1949- editor . Show ( ) ; // 非模态显示
1994+ editor . Show ( ) ;
19501995 } catch ( Exception ex ) when (
19511996 ex is IOException ||
19521997 ex is UnauthorizedAccessException ||
0 commit comments