easyai 1.0.8 → 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.
- checksums.yaml +4 -4
- data/lib/easyai/base/update_notifier.rb +18 -17
- data/lib/easyai/base/version_checker.rb +25 -44
- data/lib/easyai/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e62a795c1d9f823731c5efa0fdd2ccccece744164374c222cf42039eeab1d394
|
4
|
+
data.tar.gz: 8a937a49e3b619094a9af1beae643b9ede84f82e0f5cd38777e74e9f369711ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32ac98c88d9cf7ae7045a461d49d40f187c050f6d83c484c7a00c605b38ae94527f95ffc82229f70afd50e9ca3a8f6c79c6359eabad5173dbf0c2134d7e1a5c9
|
7
|
+
data.tar.gz: 2d0e460bdd981bd8b411557657b25ea7c2a62fb5f270be3af0fb20922245a4e063dff7afd8099bca1e9cf3ce6fbc440b1775081ac94b836254c52736b269ca06
|
@@ -5,7 +5,7 @@ require 'colored2'
|
|
5
5
|
module EasyAI
|
6
6
|
module Base
|
7
7
|
class UpdateNotifier
|
8
|
-
|
8
|
+
VERSION_INFO_FILE = File.expand_path('~/.easyai/version_info.yml')
|
9
9
|
|
10
10
|
class << self
|
11
11
|
# 智能决定是否显示更新通知
|
@@ -14,7 +14,7 @@ module EasyAI
|
|
14
14
|
return unless should_show_notification?
|
15
15
|
|
16
16
|
notification = load_notification
|
17
|
-
return unless notification && notification['
|
17
|
+
return unless notification && notification['new_version_available']
|
18
18
|
|
19
19
|
# 使用简洁的单行提醒
|
20
20
|
show_brief_notification(notification)
|
@@ -26,7 +26,7 @@ module EasyAI
|
|
26
26
|
return if ENV['EASYAI_NO_UPDATE_CHECK']
|
27
27
|
|
28
28
|
notification = load_notification
|
29
|
-
return unless notification && notification['
|
29
|
+
return unless notification && notification['new_version_available']
|
30
30
|
return if notification['shown_today']
|
31
31
|
|
32
32
|
# 退出时显示稍微详细的信息
|
@@ -41,7 +41,7 @@ module EasyAI
|
|
41
41
|
return false unless notification
|
42
42
|
|
43
43
|
# 只要当前版本低于最新版本就提醒
|
44
|
-
current =
|
44
|
+
current = EasyAI::VERSION # 始终使用实际运行的版本
|
45
45
|
latest = notification['latest_version']
|
46
46
|
|
47
47
|
# 使用版本比较逻辑
|
@@ -71,26 +71,26 @@ module EasyAI
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def major_update?(notification)
|
74
|
-
return false unless notification['latest_version']
|
74
|
+
return false unless notification['latest_version']
|
75
75
|
|
76
76
|
latest_major = notification['latest_version'].split('.')[0].to_i
|
77
|
-
current_major =
|
77
|
+
current_major = EasyAI::VERSION.split('.')[0].to_i
|
78
78
|
|
79
79
|
latest_major > current_major
|
80
80
|
end
|
81
81
|
|
82
82
|
def minor_update?(notification)
|
83
|
-
return false unless notification['latest_version']
|
83
|
+
return false unless notification['latest_version']
|
84
84
|
|
85
85
|
latest_parts = notification['latest_version'].split('.').map(&:to_i)
|
86
|
-
current_parts =
|
86
|
+
current_parts = EasyAI::VERSION.split('.').map(&:to_i)
|
87
87
|
|
88
88
|
latest_parts[0] == current_parts[0] && latest_parts[1] > current_parts[1]
|
89
89
|
end
|
90
90
|
|
91
91
|
def show_brief_notification(notification)
|
92
92
|
latest = notification['latest_version']
|
93
|
-
current =
|
93
|
+
current = EasyAI::VERSION
|
94
94
|
|
95
95
|
# 醒目的框形提醒
|
96
96
|
if major_update?(notification)
|
@@ -113,7 +113,7 @@ module EasyAI
|
|
113
113
|
|
114
114
|
def show_exit_notification(notification)
|
115
115
|
latest = notification['latest_version']
|
116
|
-
current =
|
116
|
+
current = EasyAI::VERSION
|
117
117
|
|
118
118
|
puts "\n" + "─" * 50
|
119
119
|
puts "📦 EasyAI 更新提醒".yellow
|
@@ -125,14 +125,15 @@ module EasyAI
|
|
125
125
|
end
|
126
126
|
|
127
127
|
def load_notification
|
128
|
-
return nil unless File.exist?(
|
129
|
-
YAML.load_file(
|
128
|
+
return nil unless File.exist?(VERSION_INFO_FILE)
|
129
|
+
YAML.load_file(VERSION_INFO_FILE) rescue nil
|
130
130
|
end
|
131
131
|
|
132
132
|
def update_shown_time
|
133
|
-
|
134
|
-
|
135
|
-
|
133
|
+
# 读取完整的版本信息,只更新显示时间
|
134
|
+
data = load_notification || {}
|
135
|
+
data['last_shown_at'] = Time.now.to_s
|
136
|
+
save_notification(data)
|
136
137
|
end
|
137
138
|
|
138
139
|
def mark_as_shown_today
|
@@ -142,8 +143,8 @@ module EasyAI
|
|
142
143
|
end
|
143
144
|
|
144
145
|
def save_notification(data)
|
145
|
-
FileUtils.mkdir_p(File.dirname(
|
146
|
-
File.write(
|
146
|
+
FileUtils.mkdir_p(File.dirname(VERSION_INFO_FILE))
|
147
|
+
File.write(VERSION_INFO_FILE, data.to_yaml)
|
147
148
|
rescue
|
148
149
|
nil
|
149
150
|
end
|
@@ -9,7 +9,7 @@ module EasyAI
|
|
9
9
|
module Base
|
10
10
|
class VersionChecker
|
11
11
|
RUBYGEMS_API = 'https://rubygems.org/api/v1/gems/easyai.json'
|
12
|
-
|
12
|
+
VERSION_INFO_FILE = File.expand_path('~/.easyai/version_info.yml')
|
13
13
|
CHECK_INTERVAL = 5 * 60 * 60 # 5小时检查一次
|
14
14
|
|
15
15
|
class << self
|
@@ -58,10 +58,10 @@ module EasyAI
|
|
58
58
|
return false if ENV['EASYAI_SKIP_FORCE_UPDATE'] # 紧急跳过选项
|
59
59
|
|
60
60
|
# 检查缓存
|
61
|
-
if File.exist?(
|
62
|
-
cache = YAML.load_file(
|
61
|
+
if File.exist?(VERSION_INFO_FILE)
|
62
|
+
cache = YAML.load_file(VERSION_INFO_FILE) rescue {}
|
63
63
|
latest = cache['latest_version']
|
64
|
-
current =
|
64
|
+
current = EasyAI::VERSION # 直接使用实际版本
|
65
65
|
|
66
66
|
return needs_major_or_minor_update?(latest, current)
|
67
67
|
end
|
@@ -77,7 +77,7 @@ module EasyAI
|
|
77
77
|
|
78
78
|
# 如果缓存中已有需要强制更新的信息,直接使用
|
79
79
|
if require_force_update?
|
80
|
-
cache = YAML.load_file(
|
80
|
+
cache = YAML.load_file(VERSION_INFO_FILE) rescue {}
|
81
81
|
show_force_update_message(cache['latest_version'], EasyAI::VERSION)
|
82
82
|
exit(1)
|
83
83
|
end
|
@@ -96,8 +96,8 @@ module EasyAI
|
|
96
96
|
else
|
97
97
|
puts " 💾 使用缓存(未过期)".cyan if ENV['EASYAI_DEBUG']
|
98
98
|
# 从缓存中获取版本信息
|
99
|
-
if File.exist?(
|
100
|
-
cache = YAML.load_file(
|
99
|
+
if File.exist?(VERSION_INFO_FILE)
|
100
|
+
cache = YAML.load_file(VERSION_INFO_FILE) rescue {}
|
101
101
|
return cache['latest_version']
|
102
102
|
end
|
103
103
|
end
|
@@ -124,9 +124,9 @@ module EasyAI
|
|
124
124
|
|
125
125
|
# 显示缓存的更新提醒(如果有)
|
126
126
|
def show_cached_reminder
|
127
|
-
return unless File.exist?(
|
127
|
+
return unless File.exist?(VERSION_INFO_FILE)
|
128
128
|
|
129
|
-
cache = YAML.load_file(
|
129
|
+
cache = YAML.load_file(VERSION_INFO_FILE) rescue {}
|
130
130
|
return unless cache['new_version_available']
|
131
131
|
return if cache['reminder_shown_at'] &&
|
132
132
|
Time.now - Time.parse(cache['reminder_shown_at']) < 3600 # 1小时内不重复提醒
|
@@ -149,8 +149,8 @@ module EasyAI
|
|
149
149
|
return false if ENV['EASYAI_NO_UPDATE_CHECK'] # 允许用户禁用
|
150
150
|
|
151
151
|
# 检查缓存文件
|
152
|
-
if File.exist?(
|
153
|
-
cache = YAML.load_file(
|
152
|
+
if File.exist?(VERSION_INFO_FILE)
|
153
|
+
cache = YAML.load_file(VERSION_INFO_FILE) rescue {}
|
154
154
|
last_check = cache['last_check_at']
|
155
155
|
if last_check
|
156
156
|
time_since_check = Time.now - Time.parse(last_check)
|
@@ -175,48 +175,30 @@ module EasyAI
|
|
175
175
|
def check_and_cache_with_version(latest)
|
176
176
|
return unless latest
|
177
177
|
|
178
|
+
# 不记录 current_version,运行时直接使用 EasyAI::VERSION 比较
|
178
179
|
current = EasyAI::VERSION
|
179
180
|
is_new = newer_version?(latest, current)
|
180
181
|
|
182
|
+
# 读取现有文件以保留提醒显示时间
|
183
|
+
existing_data = {}
|
184
|
+
if File.exist?(VERSION_INFO_FILE)
|
185
|
+
existing_data = YAML.load_file(VERSION_INFO_FILE) rescue {}
|
186
|
+
end
|
187
|
+
|
181
188
|
cache = {
|
182
189
|
'last_check_at' => Time.now.to_s,
|
183
190
|
'latest_version' => latest,
|
184
|
-
'
|
185
|
-
'
|
191
|
+
'new_version_available' => is_new,
|
192
|
+
'last_shown_at' => existing_data['last_shown_at'], # 保留上次显示时间
|
193
|
+
'shown_today' => existing_data['shown_today'] # 保留今日显示标记
|
186
194
|
}
|
187
195
|
|
188
196
|
save_cache(cache)
|
189
|
-
|
190
|
-
# 同时更新通知文件
|
191
|
-
if is_new
|
192
|
-
update_notification(latest, current)
|
193
|
-
end
|
194
197
|
rescue => e
|
195
198
|
# 静默失败,不影响主程序
|
196
199
|
nil
|
197
200
|
end
|
198
201
|
|
199
|
-
def update_notification(latest, current)
|
200
|
-
notification_file = File.expand_path('~/.easyai/update_notification.yml')
|
201
|
-
notification = {
|
202
|
-
'available' => true,
|
203
|
-
'latest_version' => latest,
|
204
|
-
'current_version' => current,
|
205
|
-
'checked_at' => Time.now.to_s
|
206
|
-
}
|
207
|
-
|
208
|
-
# 保留上次显示时间
|
209
|
-
if File.exist?(notification_file)
|
210
|
-
old_data = YAML.load_file(notification_file) rescue {}
|
211
|
-
notification['last_shown_at'] = old_data['last_shown_at']
|
212
|
-
notification['shown_today'] = old_data['shown_today']
|
213
|
-
end
|
214
|
-
|
215
|
-
FileUtils.mkdir_p(File.dirname(notification_file))
|
216
|
-
File.write(notification_file, notification.to_yaml)
|
217
|
-
rescue
|
218
|
-
nil
|
219
|
-
end
|
220
202
|
|
221
203
|
def fetch_latest_version
|
222
204
|
uri = URI(RUBYGEMS_API)
|
@@ -283,9 +265,9 @@ module EasyAI
|
|
283
265
|
|
284
266
|
# 是否应该立即检查
|
285
267
|
def should_check_immediately?
|
286
|
-
return true unless File.exist?(
|
268
|
+
return true unless File.exist?(VERSION_INFO_FILE)
|
287
269
|
|
288
|
-
cache = YAML.load_file(
|
270
|
+
cache = YAML.load_file(VERSION_INFO_FILE) rescue {}
|
289
271
|
last_check = cache['last_check_at']
|
290
272
|
|
291
273
|
# 如果没有检查记录或缓存超过指定时间间隔,立即检查
|
@@ -300,7 +282,6 @@ module EasyAI
|
|
300
282
|
cache = {
|
301
283
|
'last_check_at' => Time.now.to_s,
|
302
284
|
'latest_version' => latest,
|
303
|
-
'current_version' => current,
|
304
285
|
'new_version_available' => true,
|
305
286
|
'force_update_required' => true
|
306
287
|
}
|
@@ -308,8 +289,8 @@ module EasyAI
|
|
308
289
|
end
|
309
290
|
|
310
291
|
def save_cache(data)
|
311
|
-
FileUtils.mkdir_p(File.dirname(
|
312
|
-
File.write(
|
292
|
+
FileUtils.mkdir_p(File.dirname(VERSION_INFO_FILE))
|
293
|
+
File.write(VERSION_INFO_FILE, data.to_yaml)
|
313
294
|
rescue => e
|
314
295
|
# 静默失败
|
315
296
|
nil
|
data/lib/easyai/version.rb
CHANGED