poi-plugin-kancolle-chs 1.3.0 → 1.4.1

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.
package/index.es CHANGED
@@ -3,6 +3,7 @@ import { configManager } from './src/config'
3
3
  import { dataLoader } from './src/loaders/data-loader'
4
4
  import { mainPatcher } from './src/core/main-patcher'
5
5
  import { resourceManager } from './src/core/resource-manager'
6
+ import { startupChecker } from './src/core/startup-checker'
6
7
 
7
8
  // 导出插件在 POI 中展示的界面组件
8
9
  export const reactClass = MainPanel
@@ -31,12 +32,8 @@ export const pluginDidLoad = async () => {
31
32
  await mainPatcher.buildAndDeploy()
32
33
  }
33
34
 
34
- // 4. 若开启了启动自动检查更新,后台静默检查
35
- if (configManager.get('autoCheckUpdate', true)) {
36
- import('./src/core/git-manager').then(({ gitManager }) => {
37
- gitManager.checkForUpdates().catch(() => {})
38
- }).catch(() => {})
39
- }
35
+ // 4. 后台静默自检:即便用户未打开插件面板,也自动检查更新并在有更新时置顶弹窗提醒
36
+ startupChecker.scheduleStartupCheck(2000)
40
37
 
41
38
  console.log('[砍口垒汉化计划PLUS] 插件加载完毕,原生汉化模式已生效!')
42
39
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poi-plugin-kancolle-chs",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "砍口垒汉化计划PLUS POI 原生独立插件:提供全界面文本替换、正则动态替换、KCSAPI 响应合流、中文字体与贴图魔改、自定义字体适配与官方资源更新",
5
5
  "main": "index.es",
6
6
  "files": [
@@ -9,6 +9,11 @@
9
9
  "assets/",
10
10
  "generated/"
11
11
  ],
12
+ "scripts": {
13
+ "pub": "node scripts/publish-to-npm.js",
14
+ "publish-plugin": "node scripts/publish-to-npm.js",
15
+ "pub:dry": "node scripts/publish-to-npm.js --dry-run"
16
+ },
12
17
  "author": {
13
18
  "name": "泉浅漪",
14
19
  "link": "https://github.com/asaico",
package/src/config.es CHANGED
@@ -93,6 +93,10 @@ class ConfigManager {
93
93
 
94
94
  if (saved && typeof saved === 'object') {
95
95
  this.config = { ...DEFAULT_CONFIG, ...saved }
96
+ // 自动保障:只要自动检查更新为开启状态,汉化资源自检与弹窗提醒同步开启
97
+ if (this.config.autoCheckUpdate !== false) {
98
+ this.config.autoCheckResourceUpdate = true
99
+ }
96
100
  } else {
97
101
  // 若首次启动且无配置,尝试全平台推荐路径初始化
98
102
  for (const candidate of RECOMMENDED_SOURCE_PATHS) {
package/src/constants.es CHANGED
@@ -15,7 +15,7 @@ export const OFFICIAL_REPO_GIT = 'https://github.com/asaico/Kancolle_to_CHS.git'
15
15
  export const OFFICIAL_REPO_RELEASES = 'https://github.com/asaico/Kancolle_to_CHS/releases'
16
16
 
17
17
  // 插件版本与 npm 元信息
18
- let pkgVersion = '1.3.0'
18
+ let pkgVersion = '1.4.1'
19
19
  try {
20
20
  const pkg = require('../package.json')
21
21
  if (pkg && pkg.version) pkgVersion = pkg.version
@@ -70,6 +70,7 @@ export const DEFAULT_CONFIG = {
70
70
  enableApiMapInfo: true, // 出击海区与作战行动说明 (start2.api_mst_mapinfo.json)
71
71
  enableApiPictureBook: true, // 舰船与装备图鉴介绍 (picture_book.ship / slotitem)
72
72
  enableApiFlavor: true, // 海域进点气象与深海台词 (battle.api_flavor_info.json)
73
+ enableApiItem: true, // 消耗道具与商城道具汉化 (useitem / payitem.json)
73
74
 
74
75
  // --- 3. 静态魔改资产细分开关 ---
75
76
  enableFontHack: true, // 默认中文字体替换(思源黑体)
@@ -82,8 +83,9 @@ export const DEFAULT_CONFIG = {
82
83
  customFontPath: '', // 本地字体文件绝对路径 (.woff2 / .ttf / .otf)
83
84
 
84
85
  // --- 5. 官方资源与更新管理 ---
85
- autoCheckUpdate: true, // 插件启动时是否在后台自动检查更新
86
- downloadMirror: 'direct', // 资源下载加速镜像,默认 'direct' (GitHub 官方直连)
86
+ autoCheckUpdate: true, // 插件启动时是否在后台自动检查更新
87
+ autoCheckResourceUpdate: true, // 启动 POI 时自动检查本地汉化资源更新并在面板提示
88
+ downloadMirror: 'direct', // 资源下载加速镜像,默认 'direct' (GitHub 官方直连)
87
89
 
88
90
  // --- 6. 游戏运行帧率上限调节 ---
89
91
  fpsLimit: 60, // 游戏帧率上限 (默认 60,可选 60, 120, 165, 240)
@@ -11,6 +11,7 @@ export function generateApiPatcherScript(apiData, options = {}) {
11
11
  enableApiMapInfo = true,
12
12
  enableApiPictureBook = true,
13
13
  enableApiFlavor = true,
14
+ enableApiItem = true,
14
15
  } = options
15
16
 
16
17
  // 若所有 API 模块均未启用,则不注入 XHR 拦截代码
@@ -21,7 +22,8 @@ export function generateApiPatcherScript(apiData, options = {}) {
21
22
  enableApiFurniture ||
22
23
  enableApiMapInfo ||
23
24
  enableApiPictureBook ||
24
- enableApiFlavor
25
+ enableApiFlavor ||
26
+ enableApiItem
25
27
 
26
28
  if (!anyApiEnabled) {
27
29
  return ''
@@ -33,6 +35,10 @@ export function generateApiPatcherScript(apiData, options = {}) {
33
35
  furniture = {},
34
36
  mapinfo = {},
35
37
  slotitem = {},
38
+ slotitemEquiptype = {},
39
+ stype = {},
40
+ useitem = {},
41
+ payitem = {},
36
42
  pictureBookShip = {},
37
43
  pictureBookSlot = {},
38
44
  questlist = {},
@@ -45,6 +51,10 @@ export function generateApiPatcherScript(apiData, options = {}) {
45
51
  const activeFurniture = enableApiFurniture ? furniture : {}
46
52
  const activeMapInfo = enableApiMapInfo ? mapinfo : {}
47
53
  const activeSlot = enableApiShip ? slotitem : {}
54
+ const activeEquiptype = enableApiShip ? slotitemEquiptype : {}
55
+ const activeStype = enableApiShip ? stype : {}
56
+ const activeUseitem = enableApiItem ? useitem : {}
57
+ const activePayitem = enableApiItem ? payitem : {}
48
58
  const activePBShip = enableApiPictureBook ? pictureBookShip : {}
49
59
  const activePBSlot = enableApiPictureBook ? pictureBookSlot : {}
50
60
  const activeQuest = enableApiQuest ? questlist : {}
@@ -61,6 +71,7 @@ export function generateApiPatcherScript(apiData, options = {}) {
61
71
  enableApiMapInfo: ${enableApiMapInfo ? 'true' : 'false'},
62
72
  enableApiPictureBook: ${enableApiPictureBook ? 'true' : 'false'},
63
73
  enableApiFlavor: ${enableApiFlavor ? 'true' : 'false'},
74
+ enableApiItem: ${enableApiItem ? 'true' : 'false'},
64
75
  }, window.__kanchs_api_options || {});
65
76
 
66
77
  window.__kanchs_api_data = Object.assign({
@@ -69,6 +80,10 @@ export function generateApiPatcherScript(apiData, options = {}) {
69
80
  furniture: ${JSON.stringify(activeFurniture)},
70
81
  mapinfo: ${JSON.stringify(activeMapInfo)},
71
82
  slotitem: ${JSON.stringify(activeSlot)},
83
+ slotitemEquiptype: ${JSON.stringify(activeEquiptype)},
84
+ stype: ${JSON.stringify(activeStype)},
85
+ useitem: ${JSON.stringify(activeUseitem)},
86
+ payitem: ${JSON.stringify(activePayitem)},
72
87
  pictureBookShip: ${JSON.stringify(activePBShip)},
73
88
  pictureBookSlot: ${JSON.stringify(activePBSlot)},
74
89
  questlist: ${JSON.stringify(activeQuest)},
@@ -198,6 +213,105 @@ export function generateApiPatcherScript(apiData, options = {}) {
198
213
  }
199
214
  }
200
215
 
216
+ // 6. 装备类型分类母表 (start2.api_mst_slotitem_equiptype.json)
217
+ if (getOpt('enableApiShip') && Array.isArray(data.api_mst_slotitem_equiptype)) {
218
+ const EQUIPTYPE_DATA = getData('slotitemEquiptype');
219
+ for (let i = 0; i < data.api_mst_slotitem_equiptype.length; i++) {
220
+ const eq = data.api_mst_slotitem_equiptype[i];
221
+ if (!eq || eq.api_id === undefined) continue;
222
+ const patch = EQUIPTYPE_DATA[eq.api_id] || EQUIPTYPE_DATA[String(eq.api_id)];
223
+ if (patch && patch.api_name) {
224
+ const origName = eq.api_name;
225
+ eq.api_name = patch.api_name;
226
+ if (typeof window !== 'undefined' && window.__kanchs_dynamic_dict && origName) {
227
+ window.__kanchs_dynamic_dict[origName] = patch.api_name;
228
+ }
229
+ modified = true;
230
+ }
231
+ }
232
+ }
233
+
234
+ // 7. 基础舰种母表 (start2.api_mst_stype.json)
235
+ if (getOpt('enableApiShip') && Array.isArray(data.api_mst_stype)) {
236
+ const STYPE_DATA = getData('stype');
237
+ for (let i = 0; i < data.api_mst_stype.length; i++) {
238
+ const st = data.api_mst_stype[i];
239
+ if (!st || st.api_id === undefined) continue;
240
+ const patch = STYPE_DATA[st.api_id] || STYPE_DATA[String(st.api_id)];
241
+ if (patch && patch.api_name) {
242
+ const origName = st.api_name;
243
+ st.api_name = patch.api_name;
244
+ if (typeof window !== 'undefined' && window.__kanchs_dynamic_dict && origName) {
245
+ window.__kanchs_dynamic_dict[origName] = patch.api_name;
246
+ }
247
+ modified = true;
248
+ }
249
+ }
250
+ }
251
+
252
+ // 8. 消耗道具母表 (start2.api_mst_useitem.json)
253
+ if (getOpt('enableApiItem') && Array.isArray(data.api_mst_useitem)) {
254
+ const USEITEM_DATA = getData('useitem');
255
+ for (let i = 0; i < data.api_mst_useitem.length; i++) {
256
+ const u = data.api_mst_useitem[i];
257
+ if (!u || u.api_id === undefined) continue;
258
+ const patch = USEITEM_DATA[u.api_id] || USEITEM_DATA[String(u.api_id)];
259
+ if (patch) {
260
+ if (patch.api_name) {
261
+ const origName = u.api_name;
262
+ u.api_name = patch.api_name;
263
+ if (typeof window !== 'undefined' && window.__kanchs_dynamic_dict && origName) {
264
+ window.__kanchs_dynamic_dict[origName] = patch.api_name;
265
+ }
266
+ }
267
+ if (patch.api_description) {
268
+ u.api_description = patch.api_description;
269
+ if (Array.isArray(patch.api_description)) {
270
+ for (let dIdx = 0; dIdx < patch.api_description.length; dIdx++) {
271
+ const line = patch.api_description[dIdx];
272
+ if (typeof line === 'string' && line.trim()) {
273
+ registerBrVariants(line, line);
274
+ }
275
+ }
276
+ } else if (typeof patch.api_description === 'string') {
277
+ registerBrVariants(patch.api_description, patch.api_description);
278
+ }
279
+ }
280
+ modified = true;
281
+ }
282
+ }
283
+ }
284
+
285
+ // 9. 商城与点券道具母表 (start2.api_mst_payitem.json)
286
+ if (getOpt('enableApiItem') && Array.isArray(data.api_mst_payitem)) {
287
+ const PAYITEM_DATA = getData('payitem');
288
+ for (let i = 0; i < data.api_mst_payitem.length; i++) {
289
+ const p = data.api_mst_payitem[i];
290
+ if (!p || p.api_id === undefined) continue;
291
+ const patch = PAYITEM_DATA[p.api_id] || PAYITEM_DATA[String(p.api_id)];
292
+ if (patch) {
293
+ if (patch.api_name) {
294
+ const origName = p.api_name;
295
+ p.api_name = patch.api_name;
296
+ if (typeof window !== 'undefined' && window.__kanchs_dynamic_dict && origName) {
297
+ window.__kanchs_dynamic_dict[origName] = patch.api_name;
298
+ }
299
+ }
300
+ if (patch.api_description) {
301
+ const origDesc = p.api_description;
302
+ p.api_description = patch.api_description;
303
+ registerBrVariants(origDesc, patch.api_description);
304
+ }
305
+ if (patch.api_shop_description) {
306
+ const origShop = p.api_shop_description;
307
+ p.api_shop_description = patch.api_shop_description;
308
+ registerBrVariants(origShop, patch.api_shop_description);
309
+ }
310
+ modified = true;
311
+ }
312
+ }
313
+ }
314
+
201
315
  return modified;
202
316
  }
203
317
 
@@ -298,19 +412,102 @@ export function generateApiPatcherScript(apiData, options = {}) {
298
412
  }
299
413
 
300
414
  function patchFlavor(data) {
301
- if (!getOpt('enableApiFlavor') || !data || !Array.isArray(data.api_flavor_info)) return false;
415
+ if (!getOpt('enableApiFlavor') || !data || typeof data !== 'object') return false;
302
416
  let modified = false;
303
417
  const FLAVOR_DATA = getData('flavorInfo');
418
+ const SHIP_DATA = getData('ship');
419
+ const dynamicDict = window.__kanchs_dynamic_dict || {};
420
+
421
+ // 1. 处理战斗台词与深海入场 (api_flavor_info 数组或单个对象)
422
+ if (data.api_flavor_info) {
423
+ const list = Array.isArray(data.api_flavor_info) ? data.api_flavor_info : [data.api_flavor_info];
424
+ for (let i = 0; i < list.length; i++) {
425
+ const f = list[i];
426
+ if (!f || typeof f !== 'object') continue;
427
+
428
+ // 尝试通过 api_voice_id 或 api_boss_ship_id 匹配汉化补丁
429
+ let patch = null;
430
+ if (f.api_voice_id !== undefined && f.api_voice_id !== null) {
431
+ patch = FLAVOR_DATA[f.api_voice_id] || FLAVOR_DATA[String(f.api_voice_id)];
432
+ }
433
+ if (!patch && f.api_boss_ship_id !== undefined && f.api_boss_ship_id !== null) {
434
+ patch = FLAVOR_DATA['ship_' + f.api_boss_ship_id] || FLAVOR_DATA[f.api_boss_ship_id];
435
+ }
304
436
 
305
- for (let i = 0; i < data.api_flavor_info.length; i++) {
306
- const f = data.api_flavor_info[i];
307
- if (!f || f.api_voice_id === undefined) continue;
308
- const patch = FLAVOR_DATA[f.api_voice_id];
309
- if (patch) {
310
- if (patch.api_message) f.api_message = patch.api_message;
311
- if (patch.api_class_name) f.api_class_name = patch.api_class_name;
312
- if (patch.api_ship_name) f.api_ship_name = patch.api_ship_name;
313
- modified = true;
437
+ const origMsg = f.api_message || '';
438
+ const origShip = f.api_ship_name || '';
439
+ const origClass = f.api_class_name || '';
440
+
441
+ if (patch) {
442
+ if (patch.api_message) {
443
+ f.api_message = patch.api_message;
444
+ registerBrVariants(origMsg, patch.api_message);
445
+ modified = true;
446
+ }
447
+ if (patch.api_class_name) {
448
+ f.api_class_name = patch.api_class_name;
449
+ if (origClass) dynamicDict[origClass] = patch.api_class_name;
450
+ modified = true;
451
+ }
452
+ if (patch.api_ship_name) {
453
+ f.api_ship_name = patch.api_ship_name;
454
+ if (origShip) dynamicDict[origShip] = patch.api_ship_name;
455
+ modified = true;
456
+ }
457
+ }
458
+
459
+ // 兜底 1: 若未由 patch 提供 ship_name 或 class_name,尝试通过舰船表与动态字典补全汉化
460
+ if (f.api_boss_ship_id && SHIP_DATA && SHIP_DATA[f.api_boss_ship_id] && SHIP_DATA[f.api_boss_ship_id].api_name) {
461
+ if (!patch || !patch.api_ship_name) {
462
+ f.api_ship_name = SHIP_DATA[f.api_boss_ship_id].api_name;
463
+ if (origShip) dynamicDict[origShip] = f.api_ship_name;
464
+ modified = true;
465
+ }
466
+ } else if (f.api_ship_name && dynamicDict[f.api_ship_name]) {
467
+ f.api_ship_name = dynamicDict[f.api_ship_name];
468
+ modified = true;
469
+ }
470
+
471
+ if (f.api_class_name && dynamicDict[f.api_class_name]) {
472
+ f.api_class_name = dynamicDict[f.api_class_name];
473
+ modified = true;
474
+ }
475
+
476
+ // 兜底 2: 若 api_message 未被 voice_id 补丁命中,尝试字典直接替换
477
+ if ((!patch || !patch.api_message) && f.api_message) {
478
+ if (dynamicDict[f.api_message]) {
479
+ f.api_message = dynamicDict[f.api_message];
480
+ registerBrVariants(origMsg, f.api_message);
481
+ modified = true;
482
+ } else {
483
+ const clean = f.api_message.replace(/<br\\s*\\/?>/gi, '');
484
+ if (dynamicDict[clean]) {
485
+ f.api_message = dynamicDict[clean];
486
+ registerBrVariants(origMsg, f.api_message);
487
+ modified = true;
488
+ }
489
+ }
490
+ }
491
+ }
492
+ }
493
+
494
+ // 2. 处理海图进点气象/剧情提示 (api_cell_flavor 对象)
495
+ if (data.api_cell_flavor && typeof data.api_cell_flavor === 'object') {
496
+ const cf = data.api_cell_flavor;
497
+ if (cf.api_message) {
498
+ const orig = cf.api_message;
499
+ if (dynamicDict[orig]) {
500
+ cf.api_message = dynamicDict[orig];
501
+ registerBrVariants(orig, cf.api_message);
502
+ modified = true;
503
+ } else {
504
+ const clean = orig.replace(/<br\\s*\\/?>/gi, '');
505
+ if (dynamicDict[clean]) {
506
+ cf.api_message = dynamicDict[clean];
507
+ registerBrVariants(orig, cf.api_message);
508
+ modified = true;
509
+ }
510
+ }
314
511
  }
315
512
  }
316
513
 
@@ -327,7 +524,12 @@ export function generateApiPatcherScript(apiData, options = {}) {
327
524
  return url.indexOf('/api_start2/getData') !== -1 ||
328
525
  url.indexOf('/api_get_member/picture_book') !== -1 ||
329
526
  url.indexOf('/api_get_member/questlist') !== -1 ||
330
- url.indexOf('/api_req_map/') !== -1;
527
+ url.indexOf('/api_req_map/') !== -1 ||
528
+ url.indexOf('/api_req_sortie/') !== -1 ||
529
+ url.indexOf('/api_req_combined_battle/') !== -1 ||
530
+ url.indexOf('/api_req_battle_midnight/') !== -1 ||
531
+ url.indexOf('/api_req_practice/') !== -1 ||
532
+ url.indexOf('battle') !== -1;
331
533
  }
332
534
 
333
535
  function handleIntercept(target) {
@@ -363,8 +565,19 @@ export function generateApiPatcherScript(apiData, options = {}) {
363
565
  modified = patchPictureBook(json.api_data, target._kanchs_body);
364
566
  } else if (url.includes('/api_get_member/questlist')) {
365
567
  modified = patchQuestlist(json.api_data);
366
- } else if (url.includes('/api_req_map/')) {
367
- modified = patchFlavor(json.api_data);
568
+ }
569
+
570
+ // 战斗、夜战、联合舰队或海图进点:检查并合流深海台词 (api_flavor_info) 与海况剧情 (api_cell_flavor)
571
+ if (
572
+ url.includes('/api_req_sortie/') ||
573
+ url.includes('/api_req_combined_battle/') ||
574
+ url.includes('/api_req_battle_midnight/') ||
575
+ url.includes('/api_req_practice/') ||
576
+ url.includes('/api_req_map/') ||
577
+ (json.api_data && (json.api_data.api_flavor_info || json.api_data.api_cell_flavor))
578
+ ) {
579
+ const flavorModified = patchFlavor(json.api_data);
580
+ modified = modified || flavorModified;
368
581
  }
369
582
 
370
583
  if (modified) {
@@ -255,6 +255,7 @@ class MainPatcher {
255
255
  enableApiMapInfo: configManager.get('enableApiMapInfo', true),
256
256
  enableApiPictureBook: configManager.get('enableApiPictureBook', true),
257
257
  enableApiFlavor: configManager.get('enableApiFlavor', true),
258
+ enableApiItem: configManager.get('enableApiItem', true),
258
259
  }
259
260
  const apiScript = generateApiPatcherScript(dataLoader.apiData, apiOptions)
260
261
  if (apiScript) {
@@ -9,6 +9,7 @@ import { configManager } from '../config'
9
9
  import { dataLoader } from '../loaders/data-loader'
10
10
  import { resourceManager } from './resource-manager'
11
11
  import { mainPatcher } from './main-patcher'
12
+ import { PLUGIN_VERSION } from '../constants'
12
13
 
13
14
  const execAsync = util.promisify(exec)
14
15
 
@@ -264,7 +265,7 @@ class ResourceUpdater {
264
265
  currentUrl,
265
266
  {
266
267
  headers: {
267
- 'User-Agent': 'poi-plugin-kancolle-chs/1.3.0',
268
+ 'User-Agent': `poi-plugin-kancolle-chs/${PLUGIN_VERSION}`,
268
269
  Accept: '*/*',
269
270
  },
270
271
  },
@@ -606,7 +607,7 @@ class ResourceUpdater {
606
607
  treeUrl,
607
608
  {
608
609
  headers: {
609
- 'User-Agent': 'poi-plugin-kancolle-chs/1.3.0',
610
+ 'User-Agent': `poi-plugin-kancolle-chs/${PLUGIN_VERSION}`,
610
611
  Accept: 'application/vnd.github.v3+json',
611
612
  },
612
613
  timeout: 15000,
@@ -0,0 +1,136 @@
1
+ import { configManager } from '../config'
2
+ import { resourceUpdater } from './resource-updater'
3
+ import { checkPluginUpdate } from './plugin-updater'
4
+ import { PLUGIN_VERSION } from '../constants'
5
+
6
+ /**
7
+ * POI 启动自检管理器 (单例)
8
+ * 在后台静默检查插件本体版本 (npm) 与本地汉化资源增量 (GitHub)。
9
+ * 检查结果同步派发给插件面板 (MainPanel),由插件内原生的暗黑风格 Blueprint Alert 统一弹窗展示,
10
+ * 彻底移除侵入式的 Windows 原生白色系统对话框。
11
+ */
12
+ class StartupChecker {
13
+ constructor() {
14
+ this.hasChecked = false
15
+ this.isChecking = false
16
+ this.lastResult = null
17
+ this.listeners = new Set()
18
+ }
19
+
20
+ subscribe(listener) {
21
+ this.listeners.add(listener)
22
+ return () => this.listeners.delete(listener)
23
+ }
24
+
25
+ notify() {
26
+ for (const fn of this.listeners) {
27
+ try {
28
+ fn(this.lastResult)
29
+ } catch (_) {}
30
+ }
31
+ }
32
+
33
+ /**
34
+ * 启动时异步后台静默检查 (延迟 2 秒执行,避开 POI 启动窗口与网络初始化高峰)
35
+ */
36
+ scheduleStartupCheck(delayMs = 2000) {
37
+ if (this.hasChecked) return
38
+ setTimeout(() => {
39
+ this.checkOnStartup().catch((e) => {
40
+ console.warn('[KanCHS] 启动后台自检异常:', e)
41
+ })
42
+ }, delayMs)
43
+ }
44
+
45
+ /**
46
+ * 执行启动自检逻辑
47
+ */
48
+ async checkOnStartup() {
49
+ if (this.hasChecked || this.isChecking) return
50
+ this.isChecking = true
51
+ this.hasChecked = true
52
+
53
+ // 检查配置开关
54
+ const autoCheck = configManager.get('autoCheckUpdate', true) !== false &&
55
+ configManager.get('autoCheckResourceUpdate', true) !== false
56
+
57
+ if (!autoCheck) {
58
+ console.log('[KanCHS] 启动自检已在配置中关闭,跳过检查。')
59
+ this.isChecking = false
60
+ return
61
+ }
62
+
63
+ const sourceDir = configManager.resolveSourcePath()
64
+ const mirrorId = configManager.get('downloadMirror', 'ghproxy')
65
+
66
+ console.log('[KanCHS] 正在后台静默检查插件与汉化资源远端更新...')
67
+
68
+ try {
69
+ // 并发检查插件本体版本 (npm) 与本地汉化资源增量 (GitHub)
70
+ const [pluginRes, resourceRes] = await Promise.all([
71
+ checkPluginUpdate(PLUGIN_VERSION).catch((err) => {
72
+ console.warn('[KanCHS] 检查插件本体更新异常:', err.message)
73
+ return { hasUpdate: false, latestVersion: PLUGIN_VERSION }
74
+ }),
75
+ sourceDir
76
+ ? resourceUpdater.checkIncrementalUpdates({ sourceDir, mirrorId }).catch((err) => {
77
+ console.warn('[KanCHS] 检查汉化资源增量异常:', err.message)
78
+ return null
79
+ })
80
+ : null,
81
+ ])
82
+
83
+ const hasPlugin = Boolean(pluginRes && pluginRes.hasUpdate)
84
+ const hasResource = Boolean(
85
+ resourceRes &&
86
+ resourceRes.hasUpdate &&
87
+ Array.isArray(resourceRes.changedFiles) &&
88
+ resourceRes.changedFiles.length > 0
89
+ )
90
+
91
+ this.lastResult = {
92
+ pluginRes: pluginRes || { hasUpdate: false, latestVersion: PLUGIN_VERSION },
93
+ resourceRes,
94
+ hasPlugin,
95
+ hasResource,
96
+ }
97
+
98
+ this.notify()
99
+
100
+ if (hasPlugin || hasResource) {
101
+ console.log(`[KanCHS] 发现更新!插件更新: ${hasPlugin}, 资源变动: ${hasResource ? resourceRes.changedFiles.length + '项' : '无'}`)
102
+ this.notifyUpdateToast({
103
+ pluginRes: this.lastResult.pluginRes,
104
+ resourceRes,
105
+ hasPlugin,
106
+ hasResource,
107
+ })
108
+ } else {
109
+ console.log('[KanCHS] 启动自检完成:插件与汉化资源均为最新版本,保持完全静默。')
110
+ }
111
+ } catch (err) {
112
+ console.warn('[KanCHS] 启动检查失败:', err)
113
+ } finally {
114
+ this.isChecking = false
115
+ }
116
+ }
117
+
118
+ /**
119
+ * 发送 POI 系统 Toast 提示(非侵入式,完全不使用原生白色对话框)
120
+ */
121
+ notifyUpdateToast({ pluginRes, resourceRes, hasPlugin, hasResource }) {
122
+ try {
123
+ if (typeof window !== 'undefined' && typeof window.toast === 'function') {
124
+ if (hasResource && hasPlugin) {
125
+ window.toast(`[砍口垒汉化] 发现插件 v${pluginRes.latestVersion} 及 ${resourceRes.changedFiles.length} 项资源更新,已在面板就绪!`, { type: 'warning' })
126
+ } else if (hasResource) {
127
+ window.toast(`[砍口垒汉化] 发现 ${resourceRes.changedFiles.length} 项汉化资源可更新,已在面板就绪!`, { type: 'warning' })
128
+ } else if (hasPlugin) {
129
+ window.toast(`[砍口垒汉化] 发现插件新版本 v${pluginRes.latestVersion},已在面板就绪!`, { type: 'warning' })
130
+ }
131
+ }
132
+ } catch (_) {}
133
+ }
134
+ }
135
+
136
+ export const startupChecker = new StartupChecker()
@@ -28,6 +28,9 @@ export function generateTextPatcherScript(textDict = {}, regexRules = [], option
28
28
  const CUSTOM_FONT_NAME = ${JSON.stringify(customFontName || 'Microsoft YaHei')};
29
29
 
30
30
  const KCT_TLS = ${JSON.stringify(activeDict)};
31
+ try {
32
+ Object.assign(window.__kanchs_dynamic_dict, KCT_TLS);
33
+ } catch(_) {}
31
34
  const KCT_RAW_RULES = ${JSON.stringify(activeRegex)};
32
35
  const KCT_REPLACEMENTS = [];
33
36