Skip to content

Commit 97b1804

Browse files
authored
Merge pull request #48 from IvanHanloth/dev
V2.0.1.0版本发布
2 parents e2826bc + 35ffd19 commit 97b1804

9 files changed

Lines changed: 129 additions & 50 deletions

File tree

.github/workflows/build-test.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
name: Buildup Test
22

33
on:
4+
pull_request:
5+
branches:
6+
- main
47
workflow_dispatch: # 允许手动触发工作流
58

69
jobs:
7-
build-and-release:
10+
build-main-files:
811
runs-on: windows-latest # 使用最新的 Windows 运行器
912

1013
steps:
@@ -55,9 +58,27 @@ jobs:
5558
path: |
5659
out/Boss-Key.dist
5760
61+
deploy-test:
62+
environment:
63+
name: buildup-test
64+
runs-on: windows-2022
65+
needs: build-main-files
66+
steps:
67+
- name: Download artifact
68+
uses: actions/download-artifact@v4
69+
with:
70+
name: Build-Test-Build
71+
path: ./test
72+
73+
- name: Test Main Files
74+
run: |
75+
cd ./test
76+
dir
77+
./Boss-Key.exe
78+
5879
compile-to-installer:
5980
runs-on: windows-latest
60-
needs: build-and-release
81+
needs: deploy-test
6182
steps:
6283
- name: Checkout code
6384
uses: actions/checkout@v2
@@ -78,11 +99,11 @@ jobs:
7899
- name: Compile Installer
79100
run: |
80101
dir
81-
.\ISCC.exe /DMyAppVersion='v2.0.0.0' Boss-Key.iss
102+
.\ISCC.exe /DMyAppVersion='Build-Test' Boss-Key.iss
82103
working-directory: .github/inno-script
83104

84105
- name: Upload Installer
85106
uses: actions/upload-artifact@v4
86107
with:
87108
name: Boss-Key-Installer
88-
path: .github/inno-script/output/Boss-Key-v2.0.0.0-Installer.exe
109+
path: .github/inno-script/output/Boss-Key-Build-Test-Installer.exe

.github/workflows/jekyll-gh-pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Release Info Workflow and Deploy Jekyll with GitHub Pages
1+
name: Update Releases and Pages
22

33
on:
44
push:

.github/workflows/tag-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Release on Tag
1+
name: Release New Version
22

33
on:
44
push:

main/Boss-Key.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@ def __init__(self):
2929
self.SetAppName(Config.AppName)
3030
self.SetAppDisplayName(Config.AppName)
3131
self.SetVendorName(Config.AppAuthor)
32-
if self.is_already_running(os.path.join(os.path.dirname(sys.argv[0]),"Boss-Key.lock")):
33-
wx.MessageBox( "Boss Key is already running","Boss Key", wx.OK | wx.ICON_INFORMATION)
34-
sys.exit(0)
32+
lock=os.path.join(os.path.dirname(sys.argv[0]),"Boss-Key.lock")
33+
if self.is_already_running(lock):
34+
ask=wx.MessageBox("Boss Key 可能已在运行\n点击“确定”继续运行新的Boss-Key程序\n点击“取消”直接关闭此窗口","Boss Key", wx.OK | wx.ICON_INFORMATION | wx.CANCEL | wx.CANCEL_DEFAULT)
35+
if ask==wx.OK:
36+
os.remove(lock)
37+
self.is_already_running(lock)
38+
else:
39+
sys.exit(0)
3540

3641
def write_pid(self,name):
3742
with open(name, "w") as f:
@@ -47,7 +52,12 @@ def is_already_running(self,name):
4752
try:
4853
process=psutil.Process(int(pid))
4954
if process.is_running():
50-
return True
55+
this_name=psutil.Process(psutil.Process().pid).name() #获取当前进程名
56+
if this_name==process.name():
57+
return True
58+
else:
59+
self.write_pid(name)
60+
return False
5161
else:
5262
self.write_pid(name)
5363
return False

main/GUI/setting.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def OnSave(self,e):
177177
Config.send_before_hide = self.send_before_hide_checkbox.GetValue()
178178
Config.hide_current = self.hide_current_checkbox.GetValue()
179179
Config.click_to_hide = self.click_to_hide_checkbox.GetValue()
180+
Config.HotkeyListener.ShowWindows()
180181

181182
Config.hide_binding = self.getAllItems(self.right_listctrl)
182183

main/GUI/taskbar.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,37 @@ def BindEVT(self):
2626
self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.onLeftClick)
2727

2828
def CreatePopupMenu(self):
29-
menu = wx.Menu()
30-
menu.Append(self.MENU_SETTING, '设置')
31-
menu.Append(self.MENU_STARTUP, '开机自启', kind=wx.ITEM_CHECK)
32-
menu.Check(self.MENU_STARTUP, tool.checkStartup("Boss Key Application",Config.file_path))
33-
menu.AppendSeparator()
34-
menu.Append(self.MENU_UPDATE, '检查更新')
35-
menu.Append(wx.ID_ABOUT, '关于')
36-
menu.AppendSeparator()
37-
menu.Append(self.MENU_EXIT, '退出')
38-
return menu
29+
self.menu = wx.Menu()
30+
self.menu.Append(self.MENU_SETTING, '设置')
31+
self.menu.Append(self.MENU_STARTUP, '开机自启', kind=wx.ITEM_CHECK)
32+
self.menu.Check(self.MENU_STARTUP, tool.checkStartup("Boss Key Application",Config.file_path))
33+
self.menu.AppendSeparator()
34+
self.menu.Append(self.MENU_UPDATE, '检查更新')
35+
self.menu.Append(wx.ID_ABOUT, '关于')
36+
self.menu.AppendSeparator()
37+
self.menu.Append(self.MENU_EXIT, '退出')
38+
return self.menu
3939

4040
def onLeftClick(self,e=''):
4141
if Config.click_to_hide:
4242
if Config.HotkeyListener!="":
4343
Config.HotkeyListener.onHide()
4444

4545
def onStartup(self,e):
46-
try:
47-
res = tool.modifyStartup("Boss Key Application",file_path=Config.file_path)
48-
if res == "Added":
49-
tool.sendNotify(title="开机自启状态变化",message="Boss Key开机自启已开启")
50-
elif res == "Removed":
46+
if tool.checkStartup("Boss Key Application",Config.file_path):
47+
if tool.removeStartup("Boss Key Application"):
5148
tool.sendNotify(title="开机自启状态变化",message="Boss Key开机自启已关闭")
49+
self.menu.Check(self.MENU_STARTUP,False)
50+
else:
51+
tool.sendNotify(title="开机自启状态变化",message="Boss Key开机自启关闭失败")
52+
self.menu.Check(self.MENU_STARTUP,True)
53+
else:
54+
if tool.addStartup("Boss Key Application",Config.file_path):
55+
tool.sendNotify(title="开机自启状态变化",message="Boss Key开机自启已开启")
56+
self.menu.Check(self.MENU_STARTUP,True)
5257
else:
53-
tool.sendNotify(title="开机自启状态变化",message="Boss Key开机自启状态未知")
54-
except:
55-
tool.sendNotify(title="程序运行出错",message=f"Boss Key程序运行出错,请尝试重启程序")
58+
tool.sendNotify(title="开机自启状态变化",message="Boss Key开机自启开启失败")
59+
self.menu.Check(self.MENU_STARTUP,False)
5660

5761
def onSetting(self,e):
5862
Config.SettingWindow.RefreshLeftList()

main/core/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
class Config:
99
AppName = "Boss Key"
10-
AppVersion = "v2.0.0.1"
11-
AppReleaseDate = "2025-1-5"
10+
AppVersion = "v2.0.1.0"
11+
AppReleaseDate = "2025-1-17"
1212
AppAuthor = "IvanHanloth"
1313
AppDescription = "老板来了?快用Boss-Key一键隐藏静音当前窗口!上班摸鱼必备神器"
1414
AppCopyRight = "Copyright © 2022-2025 Ivan Hanloth All Rights Reserved."

main/core/listener.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,18 @@ def HideWindows(self):
7979
inner=windows
8080

8181
for i in outer:
82-
flag=0
8382
for j in inner:
8483
if tool.isSameWindow(i,j,False):
85-
flag=1
84+
if outer==Config.hide_binding: # 此时i是绑定的元素,j是窗口元素,需要隐藏j
85+
needHide.append(j['hwnd'])
86+
else:
87+
needHide.append(i['hwnd'])
8688
break
87-
if flag:
88-
needHide.append(i['hwnd'])
8989

9090
if Config.hide_current: # 插入当前窗口的句柄
9191
needHide.append(GetForegroundWindow())
9292

93+
needHide=tool.remove_duplicates(needHide) # 去重
9394
for i in needHide:
9495
if Config.send_before_hide:
9596
time.sleep(0.2)

main/core/tools.py

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from winreg import OpenKey,HKEY_CURRENT_USER,QueryValueEx,DeleteValue,CloseKey,KEY_ALL_ACCESS,SetValueEx,REG_SZ
1+
import winreg
22
import wx.adv
33
from pycaw.pycaw import AudioUtilities, ISimpleAudioVolume
44
from core.config import Config
@@ -30,31 +30,58 @@ def check_update():
3030

3131
return latest_release
3232

33-
def modifyStartup(name: str, file_path: str):
34-
key = OpenKey(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", 0, KEY_ALL_ACCESS)
33+
def addStartup(program_name, program_path):
34+
"""
35+
将程序添加到开机自启动
36+
37+
:param program_name: 注册表中的程序名称
38+
:param program_path: 程序的完整路径
39+
"""
40+
# 打开注册表中的自启动项
41+
key = winreg.HKEY_CURRENT_USER
42+
key_path = r"Software\Microsoft\Windows\CurrentVersion\Run"
43+
3544
try:
36-
existing_value, _ = QueryValueEx(key, name)
45+
# 打开注册表键
46+
registry_key = winreg.OpenKey(key, key_path, 0, winreg.KEY_WRITE)
47+
# 设置注册表项
48+
winreg.SetValueEx(registry_key, program_name, 0, winreg.REG_SZ, program_path)
49+
# 关闭注册表键
50+
winreg.CloseKey(registry_key)
51+
return True
52+
except WindowsError as e:
53+
return False
3754

38-
if existing_value == file_path:
39-
DeleteValue(key, name)
40-
CloseKey(key)
41-
return "Removed"
42-
else:
43-
SetValueEx(key, name, 0, REG_SZ, file_path)
44-
return "Added"
45-
except WindowsError:
46-
SetValueEx(key, name, 0, REG_SZ, file_path)
47-
return "Added"
55+
def removeStartup(program_name):
56+
"""
57+
从开机自启动中移除程序
58+
59+
:param program_name: 注册表中的程序名称
60+
"""
61+
# 打开注册表中的自启动项
62+
key = winreg.HKEY_CURRENT_USER
63+
key_path = r"Software\Microsoft\Windows\CurrentVersion\Run"
64+
65+
try:
66+
# 打开注册表键
67+
registry_key = winreg.OpenKey(key, key_path, 0, winreg.KEY_WRITE)
68+
# 删除注册表项
69+
winreg.DeleteValue(registry_key, program_name)
70+
# 关闭注册表键
71+
winreg.CloseKey(registry_key)
72+
return True
73+
except WindowsError as e:
74+
return False
4875

4976
def checkStartup(name: str, file_path: str):
5077
"""
5178
Check if the startup key exists and if it points to the correct file path
5279
5380
returns True if the key exists and points to the correct file path
5481
"""
55-
key = OpenKey(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", 0, KEY_ALL_ACCESS)
82+
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", 0, winreg.KEY_READ)
5683
try:
57-
existing_value, _ = QueryValueEx(key, name)
84+
existing_value, _ = winreg.QueryValueEx(key, name)
5885

5986
if existing_value == file_path:
6087
return True
@@ -79,6 +106,21 @@ def changeMute(hwnd,flag=1):
79106
except:
80107
pass
81108

109+
def remove_duplicates(input_list: list):
110+
"""
111+
Remove duplicates from a list while preserving the order.
112+
113+
input_list: list, the list from which to remove duplicates
114+
returns: list, the list without duplicates
115+
"""
116+
seen = set()
117+
output_list = []
118+
for item in input_list:
119+
if item not in seen:
120+
seen.add(item)
121+
output_list.append(item)
122+
return output_list
123+
82124
def hwnd2processName(hwnd):
83125
"""
84126
从窗口句柄获取进程名称

0 commit comments

Comments
 (0)