Skip to content

Commit 984bb92

Browse files
committed
Merge master into main
# Conflicts: # .gitignore
2 parents 86ca75d + 334254c commit 984bb92

12 files changed

Lines changed: 1116 additions & 6 deletions

.gitignore

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Byte-compiled / optimized / DLL files
1+
# Byte-compiled / optimized / DLL files
22
__pycache__/
33
*.py[codz]
44
*$py.class
@@ -96,13 +96,13 @@ ipython_config.py
9696

9797
# UV
9898
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99-
# This is especially recommended for binary packages to ensure reproducibility, and is more
99+
# This is especially recommended for reproducibility, and is more
100100
# commonly ignored for libraries.
101101
# uv.lock
102102

103103
# poetry
104104
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105-
# This is especially recommended for binary packages to ensure reproducibility, and is more
105+
# This is especially recommended for reproducibility, and is more
106106
# commonly ignored for libraries.
107107
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108108
# poetry.lock
@@ -120,8 +120,8 @@ ipython_config.py
120120
# pixi
121121
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122122
# pixi.lock
123-
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124-
# in the .venv directory. It is recommended not to include this directory in version control.
123+
# Pixi creates a virtual environment in the .pixi directory, just like .venv directory creates one
124+
# in version control.
125125
.pixi
126126

127127
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
@@ -186,7 +186,7 @@ cython_debug/
186186
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187187
# and can be added to the global gitignore or merged into this file. For a more nuclear
188188
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
189-
# .idea/
189+
.idea/
190190

191191
# Abstra
192192
# Abstra is an AI-powered process automation framework.
@@ -216,3 +216,8 @@ __marimo__/
216216

217217
# Streamlit
218218
.streamlit/secrets.toml
219+
220+
# Local workspace files
221+
build_log.txt
222+
build_result.txt
223+
.DS_Store

PokiLocker.spec

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
3+
4+
a = Analysis(
5+
['d:\\pokilocker\\main.py'],
6+
pathex=[],
7+
binaries=[],
8+
datas=[('d:\\pokilocker\\pokilocker', 'pokilocker')],
9+
hiddenimports=['qfluentwidgets'],
10+
hookspath=[],
11+
hooksconfig={},
12+
runtime_hooks=[],
13+
excludes=[],
14+
noarchive=False,
15+
optimize=0,
16+
)
17+
pyz = PYZ(a.pure)
18+
19+
exe = EXE(
20+
pyz,
21+
a.scripts,
22+
a.binaries,
23+
a.datas,
24+
[],
25+
name='PokiLocker',
26+
debug=False,
27+
bootloader_ignore_signals=False,
28+
strip=False,
29+
upx=False,
30+
upx_exclude=[],
31+
runtime_tmpdir=None,
32+
console=False,
33+
disable_windowed_traceback=False,
34+
argv_emulation=False,
35+
target_arch=None,
36+
codesign_identity=None,
37+
entitlements_file=None,
38+
)

main.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
PokiLocker - Windows 10 网站访问管理工具
3+
4+
通过修改系统 hosts 文件实现游戏和视频网站的访问阻断。
5+
需要管理员权限才能应用规则。
6+
7+
启动方式:python main.py
8+
"""
9+
import sys
10+
import os
11+
12+
# 确保当前目录在搜索路径
13+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
14+
15+
from pokilocker.app import main
16+
17+
if __name__ == "__main__":
18+
main()

pokilocker/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# pokilocker - 网站锁定工具
2+
__version__ = "1.3.0"
3+
__appname__ = "PokiLocker"

pokilocker/about_dialog.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
关于 — WinUI3 风格
3+
"""
4+
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QLabel, QHBoxLayout, QFrame
5+
from PyQt5.QtCore import Qt
6+
from PyQt5.QtGui import QFont
7+
from qfluentwidgets import PushButton
8+
import pokilocker
9+
10+
11+
class AboutDialog(QDialog):
12+
13+
def __init__(self, parent=None):
14+
super().__init__(parent)
15+
self.setWindowTitle("关于 pokilocker")
16+
self.setFixedSize(380, 280)
17+
self.setWindowFlags(
18+
self.windowFlags() & ~Qt.WindowContextHelpButtonHint)
19+
self._init_ui()
20+
21+
def _init_ui(self):
22+
layout = QVBoxLayout()
23+
layout.setSpacing(10)
24+
layout.setContentsMargins(30, 24, 30, 20)
25+
26+
name = QLabel("pokilocker")
27+
name.setFont(QFont("Segoe UI Variable", 20, QFont.Bold))
28+
name.setAlignment(Qt.AlignCenter)
29+
layout.addWidget(name)
30+
31+
ver = QLabel(f"v{pokilocker.__version__}")
32+
ver.setAlignment(Qt.AlignCenter)
33+
layout.addWidget(ver)
34+
35+
line = QFrame()
36+
line.setFrameShape(QFrame.HLine)
37+
layout.addWidget(line)
38+
39+
desc = QLabel(
40+
"Windows 网站访问管理工具\n"
41+
"made by 鸟语砖家\n"
42+
"一切开德都是反对派,纸老虎")
43+
desc.setAlignment(Qt.AlignCenter)
44+
desc.setWordWrap(True)
45+
layout.addWidget(desc)
46+
47+
layout.addStretch()
48+
49+
btn_layout = QHBoxLayout()
50+
btn_layout.addStretch()
51+
close_btn = PushButton("关闭")
52+
close_btn.clicked.connect(self.accept)
53+
btn_layout.addWidget(close_btn)
54+
btn_layout.addStretch()
55+
layout.addLayout(btn_layout)
56+
57+
self.setLayout(layout)

pokilocker/app.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
pokilocker 应用入口 — WinUI3 风格
3+
"""
4+
import sys
5+
import os
6+
7+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
8+
9+
from PyQt5.QtWidgets import QApplication
10+
from PyQt5.QtCore import Qt
11+
from PyQt5.QtGui import QFont, QFontDatabase
12+
13+
from qfluentwidgets import setTheme, Theme, setThemeColor
14+
15+
from pokilocker.config import ConfigManager
16+
from pokilocker.main_window import MainWindow
17+
18+
19+
def main():
20+
# 高 DPI 支持
21+
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
22+
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)
23+
if hasattr(Qt, "HighDpiScaleFactorRoundingPolicy"):
24+
QApplication.setHighDpiScaleFactorRoundingPolicy(
25+
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough
26+
)
27+
28+
app = QApplication(sys.argv)
29+
app.setApplicationName("pokilocker")
30+
app.setOrganizationName("pokilocker")
31+
32+
# Segoe UI Variable — WinUI3 默认开源字体
33+
font = QFont("Segoe UI Variable", 10)
34+
font.setStyleStrategy(QFont.PreferAntialias)
35+
app.setFont(font)
36+
37+
# WinUI3 Fluent 主题
38+
setTheme(Theme.LIGHT)
39+
setThemeColor("#0078D4")
40+
41+
config = ConfigManager()
42+
config.load()
43+
44+
window = MainWindow(config)
45+
window.apply_on_startup()
46+
47+
if config.get("start_minimized", False):
48+
window.hide()
49+
if not config.get("stealth_mode", False):
50+
window.show_startup_notification()
51+
else:
52+
window.show()
53+
54+
sys.exit(app.exec_())
55+
56+
57+
if __name__ == "__main__":
58+
main()

pokilocker/autostart.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
Windows 开机自启动管理
3+
通过注册表 HKCU\Software\Microsoft\Windows\CurrentVersion\Run 实现
4+
"""
5+
import sys
6+
import os
7+
import winreg
8+
9+
REG_PATH = r"Software\Microsoft\Windows\CurrentVersion\Run"
10+
APP_NAME = "PokiLocker"
11+
12+
13+
def get_exe_path():
14+
"""获取当前运行的可执行文件或脚本路径"""
15+
if getattr(sys, 'frozen', False):
16+
return sys.executable
17+
return sys.executable
18+
19+
20+
def get_start_command():
21+
"""获取开机启动的完整命令行"""
22+
exe = get_exe_path()
23+
script = os.path.abspath(sys.argv[0]) if not getattr(sys, 'frozen', False) else ""
24+
if script and script.endswith(".py"):
25+
return f'"{exe}" "{script}"'
26+
return f'"{exe}"'
27+
28+
29+
def is_auto_start_enabled():
30+
"""检查是否已设置开机自启"""
31+
try:
32+
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, REG_PATH, 0, winreg.KEY_READ)
33+
try:
34+
value, _ = winreg.QueryValueEx(key, APP_NAME)
35+
return True
36+
except FileNotFoundError:
37+
return False
38+
finally:
39+
winreg.CloseKey(key)
40+
except Exception:
41+
return False
42+
43+
44+
def enable_auto_start():
45+
"""启用开机自启"""
46+
try:
47+
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, REG_PATH, 0, winreg.KEY_SET_VALUE)
48+
cmd = get_start_command()
49+
winreg.SetValueEx(key, APP_NAME, 0, winreg.REG_SZ, cmd)
50+
winreg.CloseKey(key)
51+
return True
52+
except Exception as e:
53+
return False
54+
55+
56+
def disable_auto_start():
57+
"""禁用开机自启"""
58+
try:
59+
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, REG_PATH, 0, winreg.KEY_SET_VALUE)
60+
try:
61+
winreg.DeleteValue(key, APP_NAME)
62+
except FileNotFoundError:
63+
pass
64+
winreg.CloseKey(key)
65+
return True
66+
except Exception as e:
67+
return False

0 commit comments

Comments
 (0)