@fefeding/aicmd 1.0.5 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,23 +1,25 @@
1
1
  /**
2
- * @file Electron 自动更新模块
3
- * @description 使用 electron-updater 检测、下载和安装应用更新
2
+ * @file 版本更新检查模块
3
+ * @description 通过 GitHub Releases API 检查是否有新版本,仅 toast 提示,不自动下载
4
4
  *
5
- * 更新流程:
6
- * 1. 应用启动时自动检查更新
7
- * 2. 发现新版本 → 通知渲染进程显示提示
8
- * 3. 后台下载更新(利用 blockmap 增量下载)
9
- * 4. 下载完成 → 通知渲染进程显示"重启安装"按钮
10
- * 5. 用户确认后重启并安装
5
+ * 更新策略:
6
+ * 1. 应用启动时自动检查 GitHub 最新 release 版本
7
+ * 2. 发现新版本 → 通知渲染进程显示 toast 提示
8
+ * 3. 用户点击 toast 跳转到下载页自行下载安装
9
+ * 4. 不自动下载、不自动安装;所有错误静默忽略
11
10
  */
12
11
 
13
- const { autoUpdater } = require('electron-updater');
14
- const { BrowserWindow, ipcMain, app } = require('electron');
12
+ const { BrowserWindow, ipcMain, app, net } = require('electron');
13
+
14
+ // GitHub Releases API
15
+ const GITHUB_API = 'https://api.github.com/repos/fefeding/ai-cmd/releases/latest';
16
+ const DOWNLOAD_URL = 'https://github.com/fefeding/ai-cmd/releases/latest';
17
+
18
+ // 当前版本
19
+ const currentVersion = app.getVersion();
15
20
 
16
21
  // 更新状态
17
22
  let updateAvailable = null;
18
- let updateDownloaded = false;
19
- let downloadProgress = null;
20
- let lastProgressBroadcast = 0; // 进度广播节流
21
23
 
22
24
  /**
23
25
  * 向所有窗口广播更新事件
@@ -31,116 +33,69 @@ function broadcastUpdate(event, data) {
31
33
  }
32
34
 
33
35
  /**
34
- * 初始化自动更新
35
- * @param {object} options - 配置选项
36
- * @param {boolean} options.isDev - 是否开发模式
36
+ * 通过 GitHub API 检查最新版本
37
37
  */
38
- function initAutoUpdater(options = {}) {
39
- // 开发模式下禁用自动更新
40
- if (options.isDev) {
41
- console.log('[Updater] Disabled in dev mode');
42
- return;
43
- }
44
-
45
- // 未打包时禁用(如通过 npm start 运行的 Web 模式)
46
- if (!app.isPackaged) {
47
- console.log('[Updater] Disabled: app is not packaged');
48
- return;
49
- }
50
-
51
- // 配置 autoUpdater
52
- autoUpdater.autoDownload = true;
53
- autoUpdater.autoInstallOnAppQuit = true;
54
-
55
- // 事件监听
56
- autoUpdater.on('checking-for-update', () => {
57
- console.log('[Updater] Checking for updates...');
58
- broadcastUpdate('checking', null);
59
- });
60
-
61
- autoUpdater.on('update-available', (info) => {
62
- console.log(`[Updater] Update available: v${info.version}`);
63
- updateAvailable = info;
64
- updateDownloaded = false;
65
- broadcastUpdate('available', {
66
- version: info.version,
67
- releaseDate: info.releaseDate,
68
- releaseNotes: info.releaseNotes,
38
+ async function checkForUpdates() {
39
+ try {
40
+ const response = await net.fetch(GITHUB_API, {
41
+ headers: {
42
+ 'Accept': 'application/vnd.github.v3+json',
43
+ 'User-Agent': 'AICmd-Updater',
44
+ },
69
45
  });
70
- });
71
-
72
- autoUpdater.on('update-not-available', (info) => {
73
- console.log(`[Updater] Already up to date: v${info.version}`);
74
- updateAvailable = null;
75
- updateDownloaded = false;
76
- broadcastUpdate('not-available', { version: info.version });
77
- });
78
46
 
79
- autoUpdater.on('download-progress', (progress) => {
80
- downloadProgress = {
81
- percent: Math.round(progress.percent),
82
- bytesPerSecond: progress.bytesPerSecond,
83
- transferred: progress.transferred,
84
- total: progress.total,
85
- };
86
- // 节流:至少间隔 1 秒广播一次
87
- const now = Date.now();
88
- if (now - lastProgressBroadcast >= 1000 || downloadProgress.percent >= 100) {
89
- lastProgressBroadcast = now;
90
- broadcastUpdate('progress', downloadProgress);
47
+ if (!response.ok) {
48
+ console.log(`[Updater] GitHub API returned ${response.status}`);
49
+ return;
91
50
  }
92
- });
93
51
 
94
- autoUpdater.on('update-downloaded', (info) => {
95
- console.log(`[Updater] Update downloaded: v${info.version}`);
96
- updateDownloaded = true;
97
- broadcastUpdate('downloaded', {
98
- version: info.version,
99
- releaseDate: info.releaseDate,
100
- releaseNotes: info.releaseNotes,
101
- });
102
- });
103
-
104
- autoUpdater.on('error', (error) => {
105
- console.error('[Updater] Error:', error.message);
106
- updateAvailable = null;
107
- updateDownloaded = false;
108
- downloadProgress = null;
109
- broadcastUpdate('error', { message: error.message });
110
- });
111
-
112
- // 注册 IPC 处理器
113
- setupUpdateIPC();
114
-
115
- // 延迟 3 秒后检查更新(避免启动时太卡)
116
- setTimeout(() => {
117
- checkForUpdates();
118
- }, 3000);
52
+ const release = await response.json();
53
+ const latestVersion = release.tag_name?.replace(/^v/, '') || '';
119
54
 
120
- // 每小时检查一次更新
121
- setInterval(() => {
122
- checkForUpdates();
123
- }, 60 * 60 * 1000);
124
- }
55
+ if (!latestVersion) {
56
+ console.log('[Updater] Could not parse latest version');
57
+ return;
58
+ }
125
59
 
126
- /**
127
- * 检查更新
128
- */
129
- async function checkForUpdates() {
130
- try {
131
- await autoUpdater.checkForUpdates();
60
+ console.log(`[Updater] Current: v${currentVersion}, Latest: v${latestVersion}`);
61
+
62
+ if (compareVersions(latestVersion, currentVersion) > 0) {
63
+ console.log(`[Updater] New version available: v${latestVersion}`);
64
+ updateAvailable = {
65
+ version: latestVersion,
66
+ releaseDate: release.published_at,
67
+ releaseNotes: release.body,
68
+ downloadUrl: release.html_url || DOWNLOAD_URL,
69
+ };
70
+ broadcastUpdate('available', {
71
+ version: latestVersion,
72
+ downloadUrl: release.html_url || DOWNLOAD_URL,
73
+ });
74
+ } else {
75
+ console.log('[Updater] Already up to date');
76
+ updateAvailable = null;
77
+ }
132
78
  } catch (err) {
133
- console.error('[Updater] Check failed:', err.message);
79
+ console.log('[Updater] Check failed (ignored):', err?.message || err);
134
80
  }
135
81
  }
136
82
 
137
83
  /**
138
- * 安装更新并重启
84
+ * 简单的语义化版本比较
85
+ * @returns {number} 正数表示 v1 > v2,负数表示 v1 < v2,0 表示相等
139
86
  */
140
- function quitAndInstall() {
141
- if (updateDownloaded) {
142
- autoUpdater.quitAndInstall();
87
+ function compareVersions(v1, v2) {
88
+ const parts1 = v1.split('.').map(Number);
89
+ const parts2 = v2.split('.').map(Number);
90
+ const len = Math.max(parts1.length, parts2.length);
91
+
92
+ for (let i = 0; i < len; i++) {
93
+ const a = parts1[i] || 0;
94
+ const b = parts2[i] || 0;
95
+ if (a > b) return 1;
96
+ if (a < b) return -1;
143
97
  }
98
+ return 0;
144
99
  }
145
100
 
146
101
  /**
@@ -159,23 +114,48 @@ function setupUpdateIPC() {
159
114
  updateAvailable: updateAvailable
160
115
  ? {
161
116
  version: updateAvailable.version,
162
- releaseDate: updateAvailable.releaseDate,
117
+ downloadUrl: updateAvailable.downloadUrl,
163
118
  }
164
119
  : null,
165
- updateDownloaded,
166
- downloadProgress,
167
120
  };
168
121
  });
122
+ }
169
123
 
170
- // 渲染进程请求安装更新
171
- ipcMain.handle('update:install', () => {
172
- quitAndInstall();
173
- return { installing: true };
174
- });
124
+ /**
125
+ * 初始化更新检查
126
+ * @param {object} options - 配置选项
127
+ * @param {boolean} options.isDev - 是否开发模式
128
+ */
129
+ function initAutoUpdater(options = {}) {
130
+ // 开发模式下禁用
131
+ if (options.isDev) {
132
+ console.log('[Updater] Disabled in dev mode');
133
+ return;
134
+ }
135
+
136
+ // 未打包时禁用
137
+ if (!app.isPackaged) {
138
+ console.log('[Updater] Disabled: app is not packaged');
139
+ return;
140
+ }
141
+
142
+ console.log(`[Updater] Initialized, current version: v${currentVersion}`);
143
+
144
+ // 注册 IPC 处理器
145
+ setupUpdateIPC();
146
+
147
+ // 延迟 5 秒后检查更新(避免启动时太卡)
148
+ setTimeout(() => {
149
+ checkForUpdates();
150
+ }, 5000);
151
+
152
+ // 每 4 小时检查一次更新
153
+ setInterval(() => {
154
+ checkForUpdates();
155
+ }, 4 * 60 * 60 * 1000);
175
156
  }
176
157
 
177
158
  module.exports = {
178
159
  initAutoUpdater,
179
160
  checkForUpdates,
180
- quitAndInstall,
181
161
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fefeding/aicmd",
3
- "version": "1.0.5",
3
+ "version": "1.0.9",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "description": "AI-powered web SSH terminal with autonomous agent, skills, and file transfer",
@@ -42,7 +42,6 @@
42
42
  "axios": "^1.16.1",
43
43
  "dayjs": "^1.11.21",
44
44
  "dotenv": "^17.4.2",
45
- "electron-updater": "^6.8.3",
46
45
  "express": "^5.2.1",
47
46
  "node-pty": "1.2.0-beta.13",
48
47
  "ssh2": "^1.17.0",
@@ -81,7 +80,6 @@
81
80
  "bootstrap-icons": "^1.13.1",
82
81
  "electron": "^35.5.1",
83
82
  "electron-builder": "^26.0.12",
84
- "electron-updater": "^6.8.3",
85
83
  "jimp": "^1.6.1",
86
84
  "js-cookie": "^3.0.7",
87
85
  "jsdom": "^26.1.0",