Skip to content

Commit

Permalink
Initial commit: WeChat Auto Lock tool
Browse files Browse the repository at this point in the history
  • Loading branch information
flyhunterl committed Jan 21, 2025
0 parents commit 4a56721
Show file tree
Hide file tree
Showing 7 changed files with 434 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# IDE
.idea/
.vscode/
*.swp
*.swo

# Windows
Thumbs.db
ehthumbs.db
Desktop.ini
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# WeChat Auto Lock

一个自动锁定微信的小工具,当系统空闲指定时间后自动锁定微信窗口。

## 功能特点

- 系统托盘运行,不占用任务栏
- 可自定义空闲时间(1-10分钟)
- 支持手动立即锁定
- 自动检测系统空闲状态
- 支持开机自启动

## 使用方法

### 方法一:直接运行(推荐)

1. 下载 `WeChat Auto Lock.exe`
2. 双击运行,允许管理员权限

### 方法二:从源码运行

1. 确保已安装 Python 3.6 或更高版本
2. 安装依赖:
```bash
pip install -r requirements.txt
```
3. 运行程序:
```bash
python system_inactivity_lock.py
```

## 命令行参数

- `-t, --time`: 空闲锁定时间(秒),默认120秒
- `-i, --interval`: 检查间隔时间(秒),默认10秒

## 系统要求

- Windows 7/8/10/11
- Python 3.6+
- 微信 PC 版本

## 依赖项

- pywin32
- pystray
- Pillow

## 注意事项

- 程序需要管理员权限运行
- 请确保微信已经登录
- 程序会自动以管理员权限重启

## License

MIT License
57 changes: 57 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import os
import sys
import base64

# 将图标转换为 Python 代码中的 base64 字符串
def icon_to_base64():
with open('icon.png', 'rb') as f:
return base64.b64encode(f.read()).decode('utf-8')

# 修改主程序,添加内置图标
def modify_main_script():
icon_base64 = icon_to_base64()

with open('system_inactivity_lock.py', 'r', encoding='utf-8') as f:
content = f.read()

# 在导入语句后添加图标数据
icon_code = f'''
# 内置图标数据
ICON_BASE64 = "{icon_base64}"
def get_icon_image():
"""获取内置图标"""
import base64
from io import BytesIO
from PIL import Image
icon_data = base64.b64decode(ICON_BASE64)
return Image.open(BytesIO(icon_data))
'''

# 替换图标加载代码
content = content.replace(
'icon_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), \'icon.png\')\n image = Image.open(icon_path)',
'image = get_icon_image()'
)

with open('system_inactivity_lock_temp.py', 'w', encoding='utf-8') as f:
f.write(content)
f.write(icon_code)

def build():
# 修改主程序
modify_main_script()

# PyInstaller 打包命令
os.system('pyinstaller --noconfirm --onefile --windowed '
'--uac-admin ' # 请求管理员权限
'--name "WeChat Auto Lock" ' # 输出文件名
'--icon icon.png ' # 程序图标
'system_inactivity_lock_temp.py') # 临时主程序文件

# 清理临时文件
if os.path.exists('system_inactivity_lock_temp.py'):
os.remove('system_inactivity_lock_temp.py')

if __name__ == '__main__':
build()
18 changes: 18 additions & 0 deletions create_icon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from PIL import Image, ImageDraw

def create_icon():
# 创建一个32x32的图像,背景透明
img = Image.new('RGBA', (32, 32), (0, 0, 0, 0))
draw = ImageDraw.Draw(img)

# 绘制一个简单的锁形状
# 外框
draw.rectangle([8, 12, 24, 28], outline=(0, 0, 0, 255), width=2)
# 锁环
draw.arc([11, 4, 21, 14], 0, 180, fill=(0, 0, 0, 255), width=2)

# 保存图标
img.save('icon.png')

if __name__ == '__main__':
create_icon()
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pywin32>=228
pystray>=0.19.4
Pillow>=9.0.0
Loading

0 comments on commit 4a56721

Please sign in to comment.