easyai 1.0.8 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3eaaa20803649142336c80f3c56d85e3047588f02cc81266d666147122c43200
4
- data.tar.gz: fd5ae3775b3baef860d237ea61d59ec14bd4e292cdb2abe477b8dd624ee7533c
3
+ metadata.gz: '04579f0d2347a0226227a5d1385fa7e80bfc6e5e0fbad684c45541a768352665'
4
+ data.tar.gz: df9f71c2a71f06cf3499b2920f4737cd97ebec66e7b2aab22a459f224836b80a
5
5
  SHA512:
6
- metadata.gz: 7bd32be0384e8e411b7d0984b3a754fba62cc586ab967a7556058d958fbe47492c3445b7e985f7e2cfb4333b1fe001b31db33750c1ffa51cff04612d1368ccff
7
- data.tar.gz: 1a92f0937530b9cadf52699a884bc2dbd21b11e940b215ca7858f48ab0235eb4c640b3cf3925d57a28683ceed38d6da81e5dfdb347226fff639c9e47fc195fbe
6
+ metadata.gz: 7fb5b852906e9a6fbf3d4ff07fbb27e30eba6d3c5fdc917b40965405473163feb72c44115e07353fd50e374f8ac0e2f6cecca0fc1978bf54da5246bd48c39678
7
+ data.tar.gz: 3fec979042cf13ff735d66afbeac7180c873e9088c26c2e2c1eeb3ba6da48b570f264ff2441f7acfc1142fb21634c42caa1260088ca37ce697141d2d45d9156b
@@ -5,7 +5,7 @@ require 'colored2'
5
5
  module EasyAI
6
6
  module Base
7
7
  class UpdateNotifier
8
- NOTIFICATION_FILE = File.expand_path('~/.easyai/update_notification.yml')
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['available']
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['available']
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 = notification['current_version'] || EasyAI::VERSION
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'] && notification['current_version']
74
+ return false unless notification['latest_version']
75
75
 
76
76
  latest_major = notification['latest_version'].split('.')[0].to_i
77
- current_major = notification['current_version'].split('.')[0].to_i
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'] && notification['current_version']
83
+ return false unless notification['latest_version']
84
84
 
85
85
  latest_parts = notification['latest_version'].split('.').map(&:to_i)
86
- current_parts = notification['current_version'].split('.').map(&:to_i)
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 = notification['current_version']
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 = notification['current_version']
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?(NOTIFICATION_FILE)
129
- YAML.load_file(NOTIFICATION_FILE) rescue nil
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
- notification = load_notification || {}
134
- notification['last_shown_at'] = Time.now.to_s
135
- save_notification(notification)
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(NOTIFICATION_FILE))
146
- File.write(NOTIFICATION_FILE, data.to_yaml)
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
- CACHE_FILE = File.expand_path('~/.easyai/version_cache.yml')
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?(CACHE_FILE)
62
- cache = YAML.load_file(CACHE_FILE) rescue {}
61
+ if File.exist?(VERSION_INFO_FILE)
62
+ cache = YAML.load_file(VERSION_INFO_FILE) rescue {}
63
63
  latest = cache['latest_version']
64
- current = cache['current_version'] || EasyAI::VERSION
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(CACHE_FILE) rescue {}
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?(CACHE_FILE)
100
- cache = YAML.load_file(CACHE_FILE) rescue {}
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?(CACHE_FILE)
127
+ return unless File.exist?(VERSION_INFO_FILE)
128
128
 
129
- cache = YAML.load_file(CACHE_FILE) rescue {}
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?(CACHE_FILE)
153
- cache = YAML.load_file(CACHE_FILE) rescue {}
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
- 'current_version' => current,
185
- 'new_version_available' => is_new
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?(CACHE_FILE)
268
+ return true unless File.exist?(VERSION_INFO_FILE)
287
269
 
288
- cache = YAML.load_file(CACHE_FILE) rescue {}
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(CACHE_FILE))
312
- File.write(CACHE_FILE, data.to_yaml)
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
@@ -1,3 +1,3 @@
1
1
  module EasyAI
2
- VERSION = '1.0.8'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easyai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wade