# WallShift
**Repository Path**: seventeenY/wall-shift
## Basic Information
- **Project Name**: WallShift
- **Description**: 一款 Windows 桌面壁纸切换器,壁纸来自 Chrome 新标签页官方壁纸库
- **Primary Language**: Python
- **License**: Apache-2.0
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2026-07-15
- **Last Updated**: 2026-07-16
## Categories & Tags
**Categories**: Uncategorized
**Tags**: Python, PyQt6, PyQt-Fluent-Widgets, Chromium
## README
# WallShift
一款 Windows 桌面壁纸切换器,壁纸来自 Chrome 新标签页官方壁纸库

## 特性
- 🖼️ **官方壁纸库** — 内置 Chrome 新标签页「自定义 Chrome」的 15 个壁纸合集、500+ 张 4K 壁纸,
支持在线刷新获取最新合集
- 🔍 **浏览与搜索** — 按合集浏览、按标题/作者搜索,悬停即可设为壁纸、预览大图或下载
- 🔄 **自动切换** — 每次启动 / 每小时 / 每 6 小时 / 每天 / 自定义分钟数;
切换范围可跟随当前合集或固定某个合集;托盘一键暂停/继续
- ⬇️ **下载管理** — 按所选画质(4K / 1080p / 自适应屏幕)保存原图,
点击缩略图调用系统查看器打开
- 🎨 **Fluent 界面** — 基于 [PyQt-Fluent-Widgets](https://github.com/zhiyiYo/PyQt-Fluent-Widgets)
的 Windows 11 风格界面,白天/黑夜双主题
- 📌 **系统托盘** — 关闭窗口最小化到托盘,自动切换持续运行;
左键托盘弹出快捷面板(当前壁纸预览 + 上一张/暂停/下一张),右键完整菜单
- 🚀 **开机自启** — 一键写入注册表,登录后静默启动到托盘
- 🌐 **代理支持** — 为无法直连 Google 的网络环境提供 HTTP 代理配置
## 快速开始
要求 **Windows 10/11** 与 **Python 3.10+**。
```powershell
git clone https://github.com/wu566448/WallShift.git
cd WallShift/WallShift
pip install -r requirements.txt
python main.py
```
命令行参数:
| 参数 | 说明 |
|---|---|
| `--minimized` | 静默启动到系统托盘(开机自启使用) |
> **网络提示**:壁纸图片托管在 `googleusercontent.com`。若所在网络无法直连 Google,
> 请在 设置 → 网络代理 中填写代理地址(如 `http://127.0.0.1:7890`),缩略图与原图下载均走此代理。
## 壁纸数据从哪来?
Chrome 新标签页的背景图来自 Google Backdrop API(protobuf over HTTP)。
本项目手工编解码 protobuf 消息(不依赖 protobuf 库):
- 合集列表:`POST https://clients3.google.com/cast/chromecast/home/wallpaper/collections?rt=b`
- 合集壁纸:`POST https://clients3.google.com/cast/chromecast/home/wallpaper/collection-images?rt=b`
图片直链支持 `=w{宽}-h{高}` 尺寸参数,应用按场景分级取图(缩略图 640px / 预览 1600px / 原图最高 4K)。
仓库内置一份抓取好的壁纸数据 `WallShift/data/chrome_ntp_wallpapers.json`,可随时在应用右上角在线刷新。
### script/ — 独立抓取脚本
应用之外,`script/` 目录提供一个零 GUI 依赖的命令行抓取工具,
也是应用内「在线刷新」功能(`WallShift/app/data.py`)的原型:
| 文件 | 说明 |
|---|---|
| `chrome_ntp_wallpapers.py` | 抓取脚本:请求 Backdrop API,手工编解码 protobuf,导出全部合集的壁纸直链 |
| `chrome_ntp_wallpapers.json` | 脚本的抓取结果示例,应用内置的 `WallShift/data/` 数据即来源于此 |
用法(仅依赖 `httpx`):
```powershell
python script/chrome_ntp_wallpapers.py # 抓取全部合集 -> chrome_ntp_wallpapers.json
python script/chrome_ntp_wallpapers.py --list # 只列出合集名
python script/chrome_ntp_wallpapers.py --collection 风光 # 只抓名称含关键字的合集
python script/chrome_ntp_wallpapers.py --proxy http://127.0.0.1:7890 # 走代理(国内需要)
python script/chrome_ntp_wallpapers.py --size w1920-h1080 # 自定义图片尺寸参数
```
## Nuitka 打包
```powershell
pip install nuitka
cd WallShift
python -m nuitka --onefile --standalone --enable-plugin=pyqt6 --windows-console-mode=disable --windows-icon-from-ico=assets/app.ico --include-data-dir=assets=assets --include-data-dir=data=data --include-package-data=qfluentwidgets --output-filename=WallShift.exe --output-dir=build --remove-output --jobs=8 --show-progress main.py
```
- `--windows-icon-from-ico` 使用 `assets/app.ico`(16~256px 共 7 个尺寸)作为 exe 图标,
运行时窗口与托盘图标亦从该文件加载
- `--include-data-dir` 随程序分发图标资源与壁纸库 JSON,代码内按 `__file__` 相对定位,打包后无需改动
- `--include-package-data=qfluentwidgets` 必需,用于携带 Fluent 组件的样式与图标资源
## 项目结构
```
.
├── README.md / LICENSE
├── script/ 独立抓取脚本(见上文)
│ ├── chrome_ntp_wallpapers.py
│ └── chrome_ntp_wallpapers.json
└── WallShift/ 桌面应用
├── main.py 入口
├── requirements.txt
├── app/
│ ├── config.py 配置持久化 (%APPDATA%/WallShift/config.json)
│ ├── data.py 数据模型 / 本地 JSON 加载 / Backdrop API 在线刷新
│ ├── netimg.py 异步图片加载(磁盘缓存)+ 原图下载(进度回调)
│ ├── winwall.py Windows 设壁纸 / 开机自启注册表 / DWM 原生圆角
│ ├── icons.py Lucide 图标 SVG 内嵌渲染(托盘图标、卡片悬停按钮)
│ ├── theme.py 主题辅助(qfluentwidgets 主题切换 + 自绘控件调色板)
│ ├── mainwindow.py 主窗口 (FluentWindow) / 托盘 / 自动切换调度 / 下载流程
│ └── ui/
│ ├── library.py 壁纸库页(合集列表 + 当前壁纸面板 + 卡片网格)
│ ├── cards.py 壁纸卡片(悬停操作 / 下载进度 / 角标)+ 自适应网格
│ ├── downloads.py 下载管理页
│ ├── settings.py 设置页 (SettingCard)
│ ├── detail.py 壁纸详情弹窗(屏幕居中、可拖动)
│ └── tray.py 托盘快捷面板
├── assets/ 应用图标 (app.ico / app.png / icons/)
├── data/ 壁纸库数据 JSON
└── docs/ 截图等文档资源
```
### 运行时目录
| 路径 | 内容 |
|---|---|
| `%APPDATA%\WallShift\config.json` | 用户配置(主题、切换频率、下载记录等) |
| `%LOCALAPPDATA%\WallShift\cache\img` | 缩略图磁盘缓存 |
| `%LOCALAPPDATA%\WallShift\cache\full` | 设壁纸用的原图缓存(二次切换免下载) |
| `~\Pictures\WallShift` | 默认下载目录(可在设置中修改) |
## 版权说明
- 壁纸图片版权归 **Google 及各原创艺术家**所有,应用内展示作品名与作者署名。
本项目仅提供浏览与设置壁纸的工具,请勿将壁纸用于商业用途
- 本项目与 Google 无任何关联,Backdrop API 接口行为可能随时变更
## 致谢
- [PyQt6](https://www.riverbankcomputing.com/software/pyqt/) — GUI 框架
- [PyQt-Fluent-Widgets](https://github.com/zhiyiYo/PyQt-Fluent-Widgets) — Fluent Design 组件库
- [Lucide](https://lucide.dev/) — 图标集(经 [Iconify](https://iconify.design/) 收录)
- [httpx](https://www.python-httpx.org/) — HTTP 客户端
- Chromium `ntp_background_service` 源码 — Backdrop API 协议参考
## License
[Apache-2.0](LICENSE)