Skip to content

Commit 1065a00

Browse files
authored
Merge pull request #12 from QiaoKes/develop
[add] 支持更新检查
2 parents d1310d9 + 8216307 commit 1065a00

8 files changed

Lines changed: 910 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
## 更新记录
2525

26+
* 2025.8.24 - v1.7.0 支持自动检查更新,登录界面支持配置github代理
2627
* 2025.8.24 - v1.6.4 mpv配置管理抽为单独仓库,支持Anime4K着色器预设方案
2728
* 2025.8.23 - v1.6.3 优化mpv启动参数,固定启动时的初始窗口大小
2829
* 2025.8.22 - v1.6.2 修改部分快捷键为potplayer常用键位,mpv播放器改为无边框

docs/download-proxy.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# 下载代理功能说明
2+
3+
## 功能概述
4+
为更新检查的文件下载添加了可配置的代理功能,采用小巧美观的UI设计,用于解决GitHub下载速度慢的问题。
5+
6+
## 功能特点
7+
- ✅ 仅用于文件下载,不影响API请求
8+
- ✅ 美观的齿轮按钮设计,位于右上角
9+
- ✅ 弹出式设置面板,简洁易用
10+
- ✅ 支持启用/禁用代理切换开关
11+
- ✅ 代理URL可配置,支持多种代理服务
12+
- ✅ 默认开启代理,开箱即用
13+
- ✅ 配置持久化保存
14+
- ✅ 点击外部自动关闭面板
15+
16+
## 使用方法
17+
18+
### 1. 打开代理设置
19+
1. 点击登录页面右上角的齿轮图标⚙️
20+
2. 弹出代理设置面板
21+
22+
### 2. 配置代理
23+
1. **启用开关**:控制是否使用代理(默认开启)
24+
2. **代理地址**:输入代理URL(默认:`https://ghfast.top`
25+
3. 点击"保存"按钮确认设置
26+
27+
### 3. 支持的代理服务
28+
- **ghfast.top** - `https://ghfast.top` (推荐,默认)
29+
- **gh.api.99988866.xyz** - `https://gh.api.99988866.xyz`
30+
- **github.moeyy.xyz** - `https://github.moeyy.xyz`
31+
- **hub.fastgit.xyz** - `https://hub.fastgit.xyz`
32+
- 或其他GitHub代理服务
33+
34+
## UI设计特点
35+
36+
### 齿轮按钮
37+
- 位置:登录页面右上角
38+
- 样式:半透明圆形按钮,毛玻璃效果
39+
- 交互:悬停时旋转90度,优雅动画
40+
41+
### 设置面板
42+
- 位置:齿轮按钮下方
43+
- 样式:现代化卡片设计,毛玻璃背景
44+
- 动画:淡入淡出 + 滑动效果
45+
- 功能:点击外部自动关闭
46+
47+
### 开关控件
48+
- 类型:iOS风格滑动开关
49+
- 状态:蓝色激活,灰色禁用
50+
- 默认:开启状态
51+
52+
## 配置存储
53+
54+
### 数据结构
55+
```json
56+
{
57+
"downloadProxyEnabled": true,
58+
"downloadProxy": "https://ghfast.top",
59+
"account": "...",
60+
"domain": "...",
61+
...
62+
}
63+
```
64+
65+
### 默认值
66+
- `downloadProxyEnabled`: `true` (默认开启)
67+
- `downloadProxy`: `"https://ghfast.top"`
68+
69+
## 技术实现
70+
71+
### 前端界面
72+
- **CSS**:现代化设计,毛玻璃效果,平滑动画
73+
- **JavaScript**:面板切换,事件处理,IPC通信
74+
- **交互**:点击外部关闭,键盘友好
75+
76+
### 后端逻辑
77+
- **配置管理**:支持enabled和proxyUrl两个字段
78+
- **代理应用**:只在enabled=true时应用代理
79+
- **错误处理**:配置失败时自动回退
80+
81+
### API接口
82+
```javascript
83+
// 获取配置
84+
getDownloadProxyConfig() // 返回 {enabled, proxyUrl}
85+
86+
// 设置配置
87+
setDownloadProxyConfig({enabled, proxyUrl})
88+
89+
// IPC事件
90+
'get-download-proxy' -> 'download-proxy-info'
91+
'set-download-proxy' -> 'download-proxy-set'
92+
```
93+
94+
## 代理工作原理
95+
96+
### 启用代理时
97+
```
98+
原始: https://github.com/owner/repo/releases/download/v1.0.0/app.exe
99+
代理: https://ghfast.top/https://github.com/owner/repo/releases/download/v1.0.0/app.exe
100+
```
101+
102+
### 禁用代理时
103+
```
104+
使用原始链接,不经过代理
105+
```
106+
107+
## 日志输出
108+
109+
### 启用代理
110+
```
111+
使用代理下载链接: https://ghfast.top/https://github.com/...
112+
```
113+
114+
### 禁用代理
115+
```
116+
使用原始下载链接: https://github.com/...
117+
```
118+
119+
### 配置变更
120+
```
121+
代理设置保存成功
122+
```
123+
124+
## 注意事项
125+
126+
1. **默认开启**:首次使用会自动启用代理
127+
2. **GitHub专用**:只对GitHub域名应用代理
128+
3. **网络要求**:需要代理服务正常工作
129+
4. **配置验证**:URL格式需要正确
130+
5. **向后兼容**:保持旧版本配置兼容性
131+
132+
## 故障排除
133+
134+
### 代理不生效
135+
1. 检查开关是否开启
136+
2. 验证代理URL格式
137+
3. 尝试其他代理服务
138+
4. 查看控制台日志
139+
140+
### 面板显示异常
141+
1. 刷新页面重试
142+
2. 检查浏览器兼容性
143+
3. 清除缓存重启应用
144+
145+
### 保存失败
146+
1. 检查配置文件权限
147+
2. 确认磁盘空间充足
148+
3. 查看错误日志详情

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fntv",
3-
"version": "1.6.4",
3+
"version": "1.7.0",
44
"description": "A fntv app built with Electron",
55
"main": "src/main/main.js",
66
"scripts": {
@@ -13,7 +13,8 @@
1313
"electron-builder": "^26.0.12"
1414
},
1515
"dependencies": {
16-
"axios": "^1.11.0"
16+
"axios": "^1.11.0",
17+
"semver": "^7.7.2"
1718
},
1819
"build": {
1920
"directories": {
@@ -26,7 +27,9 @@
2627
"target": [
2728
{
2829
"target": "nsis",
29-
"arch": ["x64"]
30+
"arch": [
31+
"x64"
32+
]
3033
}
3134
]
3235
},
@@ -50,4 +53,4 @@
5053
}
5154
]
5255
}
53-
}
56+
}

src/main/eventHandlers.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const MpvPlayer = require('../modules/mpv/mpv');
55
const fn = require('../modules/fn_api/api');
66
const { restoreCookies } = require('../modules/fn_config/cookie');
77
const fnConfig = require('../modules/fn_config/config');
8+
const UpdateChecker = require('../modules/updater/updateChecker');
89

910
async function refreshWindow() {
1011
const focusedWindow = BrowserWindow.getFocusedWindow()
@@ -301,15 +302,71 @@ function handleLogin() {
301302
});
302303
}
303304

305+
// 创建更新检查器实例
306+
const updateChecker = new UpdateChecker();
307+
308+
// 处理手动检查更新
309+
function handleCheckUpdate() {
310+
ipcMain.on('check-update', async (event) => {
311+
console.log('收到手动检查更新请求');
312+
await updateChecker.manualCheckForUpdates();
313+
});
314+
}
315+
316+
// 处理自动检查更新
317+
function handleAutoCheckUpdate() {
318+
ipcMain.on('auto-check-update', async (event) => {
319+
console.log('收到自动检查更新请求');
320+
await updateChecker.autoCheckForUpdates();
321+
});
322+
}
323+
324+
// 获取当前版本信息
325+
function handleGetVersion() {
326+
ipcMain.on('get-version', (event) => {
327+
event.reply('version-info', {
328+
version: app.getVersion(),
329+
name: app.getName()
330+
});
331+
});
332+
}
333+
334+
// 处理下载代理设置
335+
function handleDownloadProxy() {
336+
// 获取当前代理设置
337+
ipcMain.on('get-download-proxy', (event) => {
338+
const proxyConfig = fnConfig.getDownloadProxyConfig();
339+
event.reply('download-proxy-info', proxyConfig);
340+
});
341+
342+
// 设置代理配置
343+
ipcMain.on('set-download-proxy', (event, { enabled, proxyUrl }) => {
344+
try {
345+
fnConfig.setDownloadProxyConfig({
346+
enabled: enabled !== false,
347+
proxyUrl: proxyUrl || 'https://ghfast.top'
348+
});
349+
event.reply('download-proxy-set', { success: true });
350+
} catch (error) {
351+
event.reply('download-proxy-set', { success: false, error: error.message });
352+
}
353+
});
354+
}
355+
304356
// 注册所有IPC处理器的聚合函数
305357
function registerIpcHandlers() {
306358
handleLogin();
307359
handleMinimize();
308360
handleMaximize();
309361
handleClose();
310362
handlePlayMovie();
363+
handleCheckUpdate();
364+
handleAutoCheckUpdate();
365+
handleGetVersion();
366+
handleDownloadProxy();
311367
}
312368

313369
module.exports = {
314370
registerIpcHandlers,
371+
updateChecker,
315372
};

src/main/main.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { app, Tray, Menu, nativeImage, BrowserWindow } = require('electron');
22
const path = require('path');
3-
const { registerIpcHandlers } = require('./eventHandlers');
3+
const { registerIpcHandlers, updateChecker } = require('./eventHandlers');
44
const { createMainWindow, setupWindowShowEvents } = require('./windowManager');
55
const { setupFullScreenToggle } = require('./screenControl');
66

@@ -46,6 +46,13 @@ if (!gotTheLock) {
4646

4747
// 设置窗口显示事件
4848
setupWindowShowEvents(mainWindow);
49+
50+
// 延迟3秒后进行自动更新检查,避免影响应用启动速度
51+
setTimeout(() => {
52+
updateChecker.autoCheckForUpdates().catch(error => {
53+
console.error('启动时自动检查更新失败:', error);
54+
});
55+
}, 3000);
4956
});
5057
}
5158

@@ -72,6 +79,20 @@ function createTray() {
7279
}
7380
}
7481
},
82+
{
83+
type: 'separator'
84+
},
85+
{
86+
label: '检查更新',
87+
click: () => {
88+
updateChecker.manualCheckForUpdates().catch(error => {
89+
console.error('手动检查更新失败:', error);
90+
});
91+
}
92+
},
93+
{
94+
type: 'separator'
95+
},
7596
{
7697
label: '退出',
7798
click: () => {

src/modules/fn_config/config.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,42 @@ function deleteHistoryItem({ domain, account }) {
115115
return false;
116116
}
117117

118+
// 获取下载代理配置
119+
function getDownloadProxyConfig() {
120+
const config = readConfig() || {};
121+
return {
122+
enabled: config.downloadProxyEnabled !== false, // 默认开启
123+
proxyUrl: config.downloadProxy || 'https://ghfast.top'
124+
};
125+
}
126+
127+
// 设置下载代理配置
128+
function setDownloadProxyConfig({ enabled = true, proxyUrl = 'https://ghfast.top' }) {
129+
const config = readConfig() || {};
130+
config.downloadProxyEnabled = enabled;
131+
config.downloadProxy = proxyUrl;
132+
fs.writeFileSync(getConfigPath(), JSON.stringify(config, null, 2));
133+
}
134+
135+
// 向后兼容的函数
136+
function getDownloadProxyUrl() {
137+
return getDownloadProxyConfig().proxyUrl;
138+
}
139+
140+
function setDownloadProxyUrl(proxyUrl) {
141+
const current = getDownloadProxyConfig();
142+
setDownloadProxyConfig({ enabled: current.enabled, proxyUrl });
143+
}
144+
118145
module.exports = {
119146
saveConfig,
120147
readConfig,
121148
addHistory,
122149
getHistory,
123150
clearHistory,
124-
deleteHistoryItem
151+
deleteHistoryItem,
152+
getDownloadProxyUrl,
153+
setDownloadProxyUrl,
154+
getDownloadProxyConfig,
155+
setDownloadProxyConfig
125156
};

0 commit comments

Comments
 (0)