@@ -60,6 +60,7 @@ def __init__(self, parent=None):
6060 "local_pumping_shortcut_key" : "" ,
6161 "local_reward_shortcut_key" : "" ,
6262 "main_window_side_switch" : False ,
63+ "show_startup_window_switch" : True ,
6364 "floating_icon_mode" : 0 ,
6465 "custom_retract_time" : 5 ,
6566 "custom_display_mode" : 1 ,
@@ -79,13 +80,12 @@ def __init__(self, parent=None):
7980 self .self_starting_switch .setOnText ("开启" )
8081 self .self_starting_switch .setOffText ("关闭" )
8182 self .self_starting_switch .setFont (QFont (load_custom_font (), 12 ))
82- self .self_starting_switch .checkedChanged .connect (self .on_pumping_floating_switch_changed )
8383 self .self_starting_switch .checkedChanged .connect (self .setting_startup )
8484
8585 # 浮窗显示/隐藏按钮
8686 self .pumping_floating_switch .setOnText ("显示" )
8787 self .pumping_floating_switch .setOffText ("隐藏" )
88- self .pumping_floating_switch .checkedChanged .connect (self .on_pumping_floating_switch_changed )
88+ self .pumping_floating_switch .checkedChanged .connect (self .save_settings )
8989 self .pumping_floating_switch .setFont (QFont (load_custom_font (), 12 ))
9090
9191 # 抽人选项侧边栏位置设置
@@ -266,6 +266,13 @@ def __init__(self, parent=None):
266266 self .url_protocol_switch .setFont (QFont (load_custom_font (), 12 ))
267267 self .url_protocol_switch .checkedChanged .connect (self .toggle_url_protocol )
268268
269+ # 设置是否显示启动窗口
270+ self .show_startup_window_switch = SwitchButton ()
271+ self .show_startup_window_switch .setOnText ("开启" )
272+ self .show_startup_window_switch .setOffText ("关闭" )
273+ self .show_startup_window_switch .setFont (QFont (load_custom_font (), 12 ))
274+ self .show_startup_window_switch .checkedChanged .connect (self .save_settings )
275+
269276 # 快捷键设置功能
270277 # 全局快捷键开关
271278 self .global_shortcut_switch = SwitchButton ()
@@ -368,6 +375,9 @@ def __init__(self, parent=None):
368375 self .addGroup (get_theme_icon ("ic_fluent_branch_compare_20_filled" ), "开机自启" , "系统开机时自动运行SecRandom(启用后将默认隐藏主窗口)" , self .self_starting_switch )
369376 self .addGroup (get_theme_icon ("ic_fluent_branch_fork_link_20_filled" ), "URL协议注册" , "注册SecRandom协议,支持通过URL链接快速启动特定功能" , self .url_protocol_switch )
370377
378+ # 显示启动窗口
379+ self .addGroup (get_theme_icon ("ic_fluent_branch_fork_link_20_filled" ), "显示启动窗口" , "系统开机时自动运行SecRandom(启用后将默认隐藏主窗口)" , self .show_startup_window_switch )
380+
371381 # 快捷键设置
372382 self .addGroup (get_theme_icon ("ic_fluent_window_ad_20_filled" ), "全局快捷键" , "启用全局快捷键功能,快速访问指定界面" , self .global_shortcut_switch )
373383 self .addGroup (get_theme_icon ("ic_fluent_window_ad_20_filled" ), "快捷键目标" , "选择全局快捷键触发时打开的界面" , self .global_shortcut_target_comboBox )
@@ -469,6 +479,8 @@ def setting_startup(self):
469479 logger .error ("无法获取可执行文件路径" )
470480 return
471481
482+ self .save_settings ()
483+
472484 try :
473485 # 读取设置文件
474486 from app .common .path_utils import path_manager
@@ -478,7 +490,7 @@ def setting_startup(self):
478490 foundation_settings = settings .get ('foundation' , {})
479491 self_starting_enabled = foundation_settings .get ('self_starting_enabled' , False )
480492
481- # 处理不同平台的启动文件夹操作
493+ # 处理Windows系统的启动文件夹操作
482494 if platform .system () == 'Windows' :
483495 # Windows系统:使用启动文件夹快捷方式
484496 startup_folder = os .path .join (
@@ -510,48 +522,6 @@ def setting_startup(self):
510522 logger .info ("开机自启动项不存在,无需取消" )
511523 except Exception as e :
512524 logger .error (f"删除快捷方式失败: { e } " )
513-
514- elif platform .system () == 'Linux' :
515- # Linux系统:使用~/.config/autostart/目录下的.desktop文件
516- home_dir = os .path .expanduser ('~' )
517- autostart_dir = os .path .join (home_dir , '.config' , 'autostart' )
518- desktop_file_path = os .path .join (autostart_dir , 'SecRandom.desktop' )
519-
520- if self_starting_enabled :
521- try :
522- # 确保autostart目录存在
523- os .makedirs (autostart_dir , exist_ok = True )
524-
525- # 创建.desktop文件内容
526- desktop_content = f"""[Desktop Entry]
527- Type=Application
528- Name=SecRandom
529- Comment=SecRandom Application
530- Exec={ executable }
531- Icon={ os .path .join (os .path .dirname (executable ), 'app' , 'resources' , 'icon.png' )}
532- Terminal=false
533- Categories=Utility;
534- StartupNotify=true
535- """
536-
537- # 写入.desktop文件
538- with open_file (desktop_file_path , 'w' , encoding = 'utf-8' ) as f :
539- f .write (desktop_content )
540-
541- # 设置文件权限为可执行
542- os .chmod (desktop_file_path , 0o644 )
543- logger .success ("Linux开机自启动设置成功" )
544- except Exception as e :
545- logger .error (f"创建.desktop文件失败: { e } " )
546- else :
547- try :
548- if path_manager .file_exists (desktop_file_path ):
549- os .remove (desktop_file_path )
550- logger .success ("Linux开机自启动取消成功" )
551- else :
552- logger .info ("Linux开机自启动项不存在,无需取消" )
553- except Exception as e :
554- logger .error (f"删除.desktop文件失败: { e } " )
555525 else :
556526 # 不支持的系统
557527 self .self_starting_switch .setChecked (self .default_settings ["self_starting_enabled" ])
@@ -662,6 +632,9 @@ def load_settings(self):
662632 if custom_display_mode < 0 or custom_display_mode >= self .custom_display_mode_comboBox .count ():
663633 # 如果索引值无效,则使用默认值
664634 custom_display_mode = self .default_settings ["custom_display_mode" ]
635+
636+ # 显示启动窗口
637+ show_startup_window_switch = foundation_settings .get ("show_startup_window_switch" , self .default_settings ["show_startup_window_switch" ])
665638
666639 self .self_starting_switch .setChecked (self_starting_enabled )
667640 self .pumping_floating_switch .setChecked (pumping_floating_enabled )
@@ -684,6 +657,7 @@ def load_settings(self):
684657 self .main_window_side_switch .setChecked (main_window_side_switch )
685658 self .floating_icon_mode_comboBox .setCurrentIndex (floating_icon_mode )
686659 self .flash_window_side_switch .setChecked (flash_window_side_switch )
660+ self .show_startup_window_switch .setChecked (show_startup_window_switch )
687661
688662 # 设置自定义选项
689663 self .custom_retract_time_spinBox .setValue (custom_retract_time )
@@ -723,6 +697,7 @@ def load_settings(self):
723697 self .main_window_side_switch .setChecked (self .default_settings ["main_window_side_switch" ])
724698 self .floating_icon_mode_comboBox .setCurrentIndex (self .default_settings ["floating_icon_mode" ])
725699 self .flash_window_side_switch .setChecked (self .default_settings ["flash_window_side_switch" ])
700+ self .show_startup_window_switch .setChecked (self .default_settings ["show_startup_window_switch" ])
726701
727702 # 设置自定义选项的默认值
728703 self .custom_retract_time_spinBox .setValue (self .default_settings ["custom_retract_time" ])
@@ -758,6 +733,7 @@ def load_settings(self):
758733 self .main_window_side_switch .setChecked (self .default_settings ["main_window_side_switch" ])
759734 self .floating_icon_mode_comboBox .setCurrentIndex (self .default_settings ["floating_icon_mode" ])
760735 self .flash_window_side_switch .setChecked (self .default_settings ["flash_window_side_switch" ])
736+ self .show_startup_window_switch .setChecked (self .default_settings ["show_startup_window_switch" ])
761737
762738 # 设置自定义选项的默认值
763739 self .custom_retract_time_spinBox .setValue (self .default_settings ["custom_retract_time" ])
@@ -813,7 +789,9 @@ def save_settings(self):
813789 foundation_settings ["main_window_side_switch" ] = self .main_window_side_switch .isChecked ()
814790 foundation_settings ["floating_icon_mode" ] = self .floating_icon_mode_comboBox .currentIndex ()
815791 foundation_settings ["flash_window_side_switch" ] = self .flash_window_side_switch .isChecked ()
816-
792+ # 显示启动窗口
793+ foundation_settings ["show_startup_window_switch" ] = self .show_startup_window_switch .isChecked ()
794+
817795 # 保存自定义设置
818796 foundation_settings ["custom_retract_time" ] = self .custom_retract_time_spinBox .value ()
819797 foundation_settings ["custom_display_mode" ] = self .custom_display_mode_comboBox .currentIndex ()
@@ -1506,15 +1484,44 @@ def toggle_url_protocol(self, enabled):
15061484 else :
15071485 self .url_protocol_switch .setChecked (False )
15081486 logger .error ("URL协议注册失败" )
1509- InfoBar .error (
1510- title = '注册失败' ,
1511- content = 'URL协议注册失败,请检查权限设置' ,
1512- orient = Qt .Horizontal ,
1513- isClosable = True ,
1514- position = InfoBarPosition .TOP ,
1515- duration = 3000 ,
1516- parent = self
1517- )
1487+
1488+ # 检查是否是权限问题
1489+ try :
1490+ import ctypes
1491+ if not ctypes .windll .shell32 .IsUserAnAdmin ():
1492+ # 不是管理员,提供更具体的错误信息
1493+ InfoBar .warning (
1494+ title = '权限不足' ,
1495+ content = 'URL协议注册需要管理员权限,请以管理员身份运行程序' ,
1496+ orient = Qt .Horizontal ,
1497+ isClosable = True ,
1498+ position = InfoBarPosition .TOP ,
1499+ duration = 5000 ,
1500+ parent = self
1501+ )
1502+ else :
1503+ # 已经是管理员但仍然失败
1504+ InfoBar .error (
1505+ title = '注册失败' ,
1506+ content = 'URL协议注册失败,即使以管理员权限运行也无法完成' ,
1507+ orient = Qt .Horizontal ,
1508+ isClosable = True ,
1509+ position = InfoBarPosition .TOP ,
1510+ duration = 5000 ,
1511+ parent = self
1512+ )
1513+ except Exception :
1514+ # 无法检查管理员权限
1515+ InfoBar .error (
1516+ title = '注册失败' ,
1517+ content = 'URL协议注册失败,请检查权限设置' ,
1518+ orient = Qt .Horizontal ,
1519+ isClosable = True ,
1520+ position = InfoBarPosition .TOP ,
1521+ duration = 3000 ,
1522+ parent = self
1523+ )
1524+
15181525 self .url_protocol_switch .setChecked (False )
15191526 self .save_settings ()
15201527 else :
@@ -1574,21 +1581,42 @@ def register_url_protocol(self):
15741581 # 注册URL协议到注册表
15751582 protocol_key = "secrandom"
15761583
1577- # 创建协议主键
1578- with winreg .CreateKey (winreg .HKEY_CLASSES_ROOT , protocol_key ) as key :
1579- winreg .SetValue (key , None , winreg .REG_SZ , "URL:SecRandom Protocol" )
1580- winreg .SetValueEx (key , "URL Protocol" , 0 , winreg .REG_SZ , "" )
1581-
1582- # 创建默认图标
1583- with winreg .CreateKey (winreg .HKEY_CLASSES_ROOT , f"{ protocol_key } \\ DefaultIcon" ) as key :
1584- winreg .SetValue (key , None , winreg .REG_SZ , executable )
1585-
1586- # 创建shell\open\command
1587- with winreg .CreateKey (winreg .HKEY_CLASSES_ROOT , f"{ protocol_key } \\ shell\\ open\\ command" ) as key :
1588- winreg .SetValue (key , None , winreg .REG_SZ , command )
1589-
1590- logger .info (f"URL协议注册成功: { protocol_key } " )
1591- return True
1584+ # 尝试以管理员权限注册URL协议
1585+ try :
1586+ # 创建协议主键
1587+ with winreg .CreateKey (winreg .HKEY_CLASSES_ROOT , protocol_key ) as key :
1588+ winreg .SetValue (key , None , winreg .REG_SZ , "URL:SecRandom Protocol" )
1589+ winreg .SetValueEx (key , "URL Protocol" , 0 , winreg .REG_SZ , "" )
1590+
1591+ # 创建默认图标
1592+ with winreg .CreateKey (winreg .HKEY_CLASSES_ROOT , f"{ protocol_key } \\ DefaultIcon" ) as key :
1593+ winreg .SetValue (key , None , winreg .REG_SZ , executable )
1594+
1595+ # 创建shell\open\command
1596+ with winreg .CreateKey (winreg .HKEY_CLASSES_ROOT , f"{ protocol_key } \\ shell\\ open\\ command" ) as key :
1597+ winreg .SetValue (key , None , winreg .REG_SZ , command )
1598+
1599+ logger .info (f"URL协议注册成功: { protocol_key } " )
1600+ return True
1601+ except PermissionError as e :
1602+ logger .error (f"权限不足,无法注册URL协议: { str (e )} " )
1603+ # 提示用户需要管理员权限
1604+ try :
1605+ import ctypes
1606+ if ctypes .windll .shell32 .IsUserAnAdmin ():
1607+ # 已经是管理员,但仍然失败
1608+ logger .error ("即使以管理员权限运行,URL协议注册仍然失败" )
1609+ return False
1610+ else :
1611+ # 不是管理员,提示用户
1612+ logger .warning ("需要管理员权限才能注册URL协议" )
1613+ return False
1614+ except Exception :
1615+ logger .error ("无法检查管理员权限" )
1616+ return False
1617+ except Exception as e :
1618+ logger .error (f"注册URL协议时发生未知错误: { str (e )} " )
1619+ return False
15921620
15931621 else :
15941622 # Linux平台使用.desktop文件和MIME类型
0 commit comments