papersearch 0.7.0 → 0.7.2

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.
Files changed (96) hide show
  1. package/dist/capabilities/download/batch/batch.d.ts.map +1 -1
  2. package/dist/capabilities/download/batch/batch.js +12 -1
  3. package/dist/capabilities/download/batch/batch.js.map +1 -1
  4. package/dist/capabilities/download/batch/batchSummary.d.ts.map +1 -1
  5. package/dist/capabilities/download/batch/batchSummary.js +16 -7
  6. package/dist/capabilities/download/batch/batchSummary.js.map +1 -1
  7. package/dist/capabilities/download/batch/journalKey.d.ts +12 -0
  8. package/dist/capabilities/download/batch/journalKey.d.ts.map +1 -0
  9. package/dist/capabilities/download/batch/journalKey.js +30 -0
  10. package/dist/capabilities/download/batch/journalKey.js.map +1 -0
  11. package/dist/capabilities/download/content/pdf/DownloadTier.d.ts +4 -0
  12. package/dist/capabilities/download/content/pdf/DownloadTier.d.ts.map +1 -1
  13. package/dist/capabilities/download/content/pdf/OpenAccessFallbackService.d.ts.map +1 -1
  14. package/dist/capabilities/download/content/pdf/OpenAccessFallbackService.js +2 -0
  15. package/dist/capabilities/download/content/pdf/OpenAccessFallbackService.js.map +1 -1
  16. package/dist/capabilities/download/content/pdf/school.js +2 -0
  17. package/dist/capabilities/download/content/pdf/school.js.map +1 -1
  18. package/dist/capabilities/download/types.d.ts +4 -0
  19. package/dist/capabilities/download/types.d.ts.map +1 -1
  20. package/dist/cli.js +32 -9
  21. package/dist/cli.js.map +1 -1
  22. package/dist/infrastructure/school/SchoolMcpClient.d.ts +4 -0
  23. package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -1
  24. package/dist/infrastructure/school/SchoolMcpClient.js +20 -1
  25. package/dist/infrastructure/school/SchoolMcpClient.js.map +1 -1
  26. package/dist/infrastructure/school/SchoolReadiness.d.ts +2 -0
  27. package/dist/infrastructure/school/SchoolReadiness.d.ts.map +1 -1
  28. package/dist/infrastructure/school/SchoolReadiness.js +3 -0
  29. package/dist/infrastructure/school/SchoolReadiness.js.map +1 -1
  30. package/dist/infrastructure/school/SchoolResultNormalizer.d.ts.map +1 -1
  31. package/dist/infrastructure/school/SchoolResultNormalizer.js +5 -0
  32. package/dist/infrastructure/school/SchoolResultNormalizer.js.map +1 -1
  33. package/dist/infrastructure/school/types.d.ts +12 -0
  34. package/dist/infrastructure/school/types.d.ts.map +1 -1
  35. package/dist/management/pro/activate.d.ts +36 -0
  36. package/dist/management/pro/activate.d.ts.map +1 -0
  37. package/dist/management/pro/activate.js +122 -0
  38. package/dist/management/pro/activate.js.map +1 -0
  39. package/dist/management/pro/install.d.ts +15 -0
  40. package/dist/management/pro/install.d.ts.map +1 -1
  41. package/dist/management/pro/install.js +39 -12
  42. package/dist/management/pro/install.js.map +1 -1
  43. package/dist/management/reports/index.d.ts +6 -0
  44. package/dist/management/reports/index.d.ts.map +1 -1
  45. package/dist/management/reports/index.js +6 -0
  46. package/dist/management/reports/index.js.map +1 -1
  47. package/dist/management/school/autoUpdate.d.ts.map +1 -1
  48. package/dist/management/school/autoUpdate.js +1 -0
  49. package/dist/management/school/autoUpdate.js.map +1 -1
  50. package/dist/management/school/cliProgress.d.ts.map +1 -1
  51. package/dist/management/school/cliProgress.js +1 -0
  52. package/dist/management/school/cliProgress.js.map +1 -1
  53. package/dist/management/school/settingsWindow.d.ts +1 -0
  54. package/dist/management/school/settingsWindow.d.ts.map +1 -1
  55. package/dist/management/school/settingsWindow.js +2 -0
  56. package/dist/management/school/settingsWindow.js.map +1 -1
  57. package/dist/management/updates/selfUpdate.d.ts +86 -0
  58. package/dist/management/updates/selfUpdate.d.ts.map +1 -0
  59. package/dist/management/updates/selfUpdate.js +194 -0
  60. package/dist/management/updates/selfUpdate.js.map +1 -0
  61. package/package.json +1 -1
  62. package/school/paper_search_school/adapters/annual_reviews/__init__.py +1 -0
  63. package/school/paper_search_school/adapters/ieee/__init__.py +1 -0
  64. package/school/paper_search_school/assets/capsule.html +1152 -206
  65. package/school/paper_search_school/assets/capsule_en.json +467 -19
  66. package/school/paper_search_school/assets/capsule_fr.json +1331 -0
  67. package/school/paper_search_school/assets/capsule_ja.json +1331 -0
  68. package/school/paper_search_school/assets/capsule_ko.json +1331 -0
  69. package/school/paper_search_school/assets/capsule_zh-Hant.json +2462 -0
  70. package/school/paper_search_school/browser/backend.py +15 -5
  71. package/school/paper_search_school/cli.py +15 -1
  72. package/school/paper_search_school/cold_start.py +70 -8
  73. package/school/paper_search_school/config.py +2 -0
  74. package/school/paper_search_school/download_diagnostics.py +4 -4
  75. package/school/paper_search_school/engine/batch_capture.py +37 -2
  76. package/school/paper_search_school/engine/batch_diagnostics.py +1 -1
  77. package/school/paper_search_school/engine/batch_institution.py +59 -0
  78. package/school/paper_search_school/engine/batch_login.py +117 -3
  79. package/school/paper_search_school/engine/batch_waits.py +42 -11
  80. package/school/paper_search_school/engine/bridge.py +11 -0
  81. package/school/paper_search_school/i18n.py +46 -22
  82. package/school/paper_search_school/orchestrator.py +60 -8
  83. package/school/paper_search_school/pro_status.py +54 -63
  84. package/school/paper_search_school/progress_capsule.py +349 -39
  85. package/school/paper_search_school/progress_reporter.py +51 -5
  86. package/school/paper_search_school/progress_view.py +3 -2
  87. package/school/paper_search_school/school_login.py +39 -2
  88. package/school/paper_search_school/school_switch.py +102 -0
  89. package/school/paper_search_school/school_test.py +335 -0
  90. package/school/paper_search_school/server.py +16 -0
  91. package/school/paper_search_school/updates.py +222 -0
  92. package/school/paper_search_school/user_settings.py +8 -3
  93. package/skills/paper-search/SKILL.md +1 -1
  94. package/skills/paper-search/references/browser-download.md +2 -2
  95. package/skills/paper-search/references/cli-contract.md +1 -1
  96. package/skills/paper-search/references/school-setup.md +1 -1
@@ -38,9 +38,16 @@ ASSETS = Path(__file__).with_name("assets")
38
38
  PAGE = ASSETS / "capsule.html"
39
39
 
40
40
 
41
+ #: Where each language's table goes in the page.
42
+ _TABLE_MARKS = {"en": "CAPSULE_EN", "zh-Hant": "CAPSULE_ZH_HANT", "ja": "CAPSULE_JA", "ko": "CAPSULE_KO", "fr": "CAPSULE_FR"}
43
+
44
+
41
45
  def page_html() -> str:
42
- """The page with its English table in it (the window loads it as one string)."""
43
- return PAGE.read_text(encoding="utf-8").replace("/*CAPSULE_EN*/null", i18n.TABLE.read_text(encoding="utf-8"))
46
+ """The page with its tables in it, one per language (the window loads it as one string)."""
47
+ page = PAGE.read_text(encoding="utf-8")
48
+ for code, mark in _TABLE_MARKS.items():
49
+ page = page.replace(f"/*{mark}*/null", i18n.TABLES[code].read_text(encoding="utf-8"))
50
+ return page
44
51
  # PaperSearch's icon (assets/icon.svg) for the Dock.
45
52
  ICON = ASSETS / "icon-512.png"
46
53
  # The first, collapsed frame; the page then reports the size it needs.
@@ -144,6 +151,10 @@ class Notifier:
144
151
  threading.Thread(target=self._send, args=("PaperSearch", message, state), daemon=True).start()
145
152
 
146
153
 
154
+ #: How many schools 添加学校 lists at most (a country's name finds all of its).
155
+ FOUND_SHOWN = 50
156
+
157
+
147
158
  class Api:
148
159
  """What the page calls (``window.pywebview.api``). Every method returns
149
160
  plain values and never raises into the page."""
@@ -420,7 +431,7 @@ class Api:
420
431
  def set_language(self, lang: str) -> dict[str, Any]:
421
432
  """The language switch saves at once and the page follows it."""
422
433
  if lang not in i18n.LANGUAGES:
423
- return {"ok": False, "error": "语言只能是中文或英文"}
434
+ return {"ok": False, "error": "不支持这种语言"}
424
435
  try:
425
436
  user_settings.set_language(lang)
426
437
  except (OSError, ValueError) as exc:
@@ -580,28 +591,73 @@ class Api:
580
591
 
581
592
  # --- PaperSearch Pro: the Markdown page -------------------------------
582
593
  def school_login_state(self) -> dict[str, Any]:
583
- """The sign-in page (PaperSearch Pro, school_login.py): the current school, its saved
584
- account (masked; never the password) and whether Pro fills it in."""
594
+ """The sign-in page (PaperSearch Pro, school_login.py): the schools saved, each with its account
595
+ (masked; never the password) and whether Pro fills it in, the default one first (user,
596
+ 2026-11-20: several schools here, one of them the default for downloads, switched here); the
597
+ default one's fields at the top level too, for the home page's line."""
585
598
  if not pro_features():
586
599
  return {"ok": False, "error": "这个版本没有自动登录"}
587
600
  try:
588
601
  from . import school_login
589
602
  from .config import load_config
603
+ from .schools import saved as saved_schools
590
604
 
591
605
  config = load_config()
592
- entity_id = str(config.get("idp_entity_id") or "").strip()
593
- account = school_login.saved(config, entity_id) or {}
594
- return {"ok": True, "school": str(config.get("school_name") or config.get("school_name_en") or ""),
595
- "entity": bool(entity_id), "saved": bool(account),
596
- "username": school_login.masked(account.get("username", "")) if account else "",
597
- "enabled": bool(account.get("enabled")), "off": str(account.get("off") or ""),
598
- "pro": school_login.module() is not None, "status": school_login.school_status(entity_id)}
606
+ saved_schools.remember(config)
607
+ pro = school_login.module()
608
+ listed = []
609
+ for entry in saved_schools.saved(config):
610
+ entity_id = str(entry.get("idp_entity_id") or "").strip()
611
+ account = school_login.saved(config, entity_id) or {}
612
+ listed.append({"key": entity_id, "name": str(entry.get("school_name") or ""),
613
+ "name_en": str(entry.get("school_name_en") or ""),
614
+ "current": saved_schools.is_current(config, entry), "entity": bool(entity_id),
615
+ "saved": bool(account), "username": school_login.masked(account.get("username", "")) if account else "",
616
+ "enabled": bool(account.get("enabled")), "off": str(account.get("off") or ""),
617
+ "status": school_login.school_status(entity_id, pro) if pro is not None else ""})
618
+ listed.sort(key=lambda school: not school["current"])
619
+ current = next((school for school in listed if school["current"]), {})
620
+ from . import school_switch
621
+
622
+ return {"ok": True, "pro": pro is not None, "schools": listed, "switch": school_switch.enabled(config),
623
+ "counts": school_login.school_counts(pro) if pro is not None else {},
624
+ "school": current.get("name", ""), "entity": bool(current.get("entity")), "saved": bool(current.get("saved")),
625
+ "username": current.get("username", ""), "enabled": bool(current.get("enabled")),
626
+ "off": current.get("off", ""), "status": current.get("status", "")}
599
627
  except Exception as exc:
600
628
  return {"ok": False, "error": f"读取失败:{type(exc).__name__}"}
601
629
 
602
- def school_login_saved(self) -> dict[str, str]:
603
- """The current school's saved account and password, for the sign-in page's fields: the
604
- password there, hidden until its eye shows it (user, 2026-11-19: they may see it)."""
630
+ def school_support_list(self) -> dict[str, Any]:
631
+ """The sign-in page's 支持哪些学校 (user, 2026-11-20): the schools Pro knows, by name and province,
632
+ each with what it does for them; an older Pro has no list."""
633
+ if not pro_features():
634
+ return {"ok": False, "error": "这个版本没有自动登录"}
635
+ try:
636
+ from . import school_login
637
+
638
+ pro = school_login.module()
639
+ if pro is None:
640
+ return {"ok": False, "error": "需要 PaperSearch Pro"}
641
+ schools = school_login.school_list(pro)
642
+ except Exception as exc:
643
+ return {"ok": False, "error": f"读取失败:{type(exc).__name__}"}
644
+ return {"ok": True, "schools": schools} if schools else {"ok": False, "error": "需要更新 PaperSearch Pro"}
645
+
646
+ @staticmethod
647
+ def _login_school(config: dict[str, Any], key: str) -> str:
648
+ """The entityID of the saved school ``key`` names; the default school's when it is empty; "" when none."""
649
+ from .schools import saved as saved_schools
650
+
651
+ key = str(key or "").strip()
652
+ if not key:
653
+ return str(config.get("idp_entity_id") or "").strip()
654
+ saved_schools.remember(config)
655
+ known = {str(entry.get("idp_entity_id") or "").strip() for entry in saved_schools.saved(config)}
656
+ return key if key in known else ""
657
+
658
+ def school_login_saved(self, key: str = "") -> dict[str, str]:
659
+ """A saved school's account and password, for the sign-in page's fields: the password there,
660
+ hidden until its eye shows it (user, 2026-11-19: they may see it). The default school's by default."""
605
661
  if not pro_features():
606
662
  return {}
607
663
  try:
@@ -609,20 +665,22 @@ class Api:
609
665
  from .config import load_config
610
666
 
611
667
  config = load_config()
612
- account = school_login.saved(config, str(config.get("idp_entity_id") or "").strip()) or {}
668
+ account = school_login.saved(config, self._login_school(config, key)) or {}
613
669
  except Exception:
614
670
  return {}
615
671
  return {"username": str(account.get("username") or ""), "password": str(account.get("password") or "")}
616
672
 
617
- def save_school_login(self, username: str = "", password: str = "", enabled: bool = True) -> dict[str, Any]:
618
- """Keep the current school's account; empty fields keep what was saved (the switch)."""
673
+ def save_school_login(self, username: str = "", password: str = "", enabled: bool = True, key: str = "") -> dict[str, Any]:
674
+ """Keep a saved school's account (the default school's by default); empty fields keep what was saved (the switch)."""
619
675
  if not pro_features():
620
676
  return {"ok": False, "error": "这个版本没有自动登录"}
621
677
  try:
622
678
  from . import school_login
623
679
  from .config import load_config
624
680
 
625
- entity_id = str(load_config().get("idp_entity_id") or "").strip()
681
+ entity_id = self._login_school(load_config(), key)
682
+ if key and not entity_id:
683
+ return {"ok": False, "error": "这所学校还没有添加"}
626
684
  school_login.save(entity_id, str(username or ""), str(password or ""), enabled=bool(enabled))
627
685
  except ValueError as exc:
628
686
  return {"ok": False, "error": str(exc)}
@@ -630,18 +688,222 @@ class Api:
630
688
  return {"ok": False, "error": f"保存失败:{type(exc).__name__}"}
631
689
  return self.school_login_state()
632
690
 
633
- def clear_school_login(self) -> dict[str, Any]:
691
+ # 测试登录 (user, 2026-11-21; school_test.py): a saved school's account tried on an article, as a download goes.
692
+ def school_test_article(self, key: str = "") -> dict[str, Any]:
693
+ """The article this school's test opens: {ok, doi} ("" while the user has set none)."""
694
+ if not pro_features():
695
+ return {"ok": False, "error": "这个版本没有自动登录"}
696
+ from .config import load_config
697
+ from .school_test import article
698
+
699
+ entity_id = self._login_school(load_config(), key)
700
+ return {"ok": True, **article(entity_id)} if entity_id else {"ok": False, "error": "这所学校还没有添加"}
701
+
702
+ def set_school_test_article(self, key: str = "", text: str = "") -> dict[str, Any]:
703
+ """The article set by its DOI or its page's address (user, 2026-11-21: set by them, none for them)."""
634
704
  if not pro_features():
635
705
  return {"ok": False, "error": "这个版本没有自动登录"}
706
+ try:
707
+ from .config import load_config
708
+ from .school_test import set_article
709
+
710
+ entity_id = self._login_school(load_config(), key)
711
+ return set_article(entity_id, str(text or "")) if entity_id else {"ok": False, "error": "这所学校还没有添加"}
712
+ except Exception as exc:
713
+ return {"ok": False, "error": f"保存失败:{type(exc).__name__}"}
714
+
715
+ def start_school_test(self, key: str = "", doi: str = "") -> dict[str, Any]:
716
+ """Starts the test of a saved school whose account is saved, on ``doi``; or says why not."""
717
+ if not pro_features():
718
+ return {"state": "idle", "error": "这个版本没有自动登录"}
636
719
  try:
637
720
  from . import school_login
638
721
  from .config import load_config
639
722
 
640
- school_login.clear(str(load_config().get("idp_entity_id") or "").strip())
723
+ config = load_config()
724
+ entity_id = self._login_school(config, key)
725
+ if not entity_id:
726
+ return {"state": "idle", "error": "这所学校还没有添加"}
727
+ if not school_login.saved(config, entity_id):
728
+ return {"state": "idle", "error": "先保存账号和密码,再测试"}
729
+ doi = str(doi or "").strip()
730
+ if not doi:
731
+ return {"state": "idle", "error": "先填测试文章"}
732
+ return self._school_test().start(entity_id, doi)
733
+ except Exception as exc:
734
+ return {"state": "idle", "error": f"测试没有开始:{type(exc).__name__}"}
735
+
736
+ def school_test_state(self) -> dict[str, Any]:
737
+ return self._school_test().state()
738
+
739
+ def stop_school_test(self) -> dict[str, Any]:
740
+ return self._school_test().stop()
741
+
742
+ def forget_school_test(self) -> dict[str, Any]:
743
+ self._school_test().forget()
744
+ return self._school_test().state()
745
+
746
+ def _school_test(self):
747
+ from .school_test import SchoolTest
748
+
749
+ test = getattr(self, "_test", None)
750
+ if test is None:
751
+ test = self._test = SchoolTest()
752
+ return test
753
+
754
+ def set_school_switch(self, on: bool = True) -> dict[str, Any]:
755
+ """没权限时换下一所学校 on or off (school_switch.py); the page's state after it."""
756
+ if not pro_features():
757
+ return {"ok": False, "error": "这个版本没有自动登录"}
758
+ try:
759
+ from .config import update_config
760
+ from .school_switch import SETTING
761
+
762
+ update_config(SETTING, "true" if on else "false")
763
+ except Exception as exc:
764
+ return {"ok": False, "error": f"保存失败:{type(exc).__name__}"}
765
+ return self.school_login_state()
766
+
767
+ def clear_school_login(self, key: str = "") -> dict[str, Any]:
768
+ if not pro_features():
769
+ return {"ok": False, "error": "这个版本没有自动登录"}
770
+ try:
771
+ from . import school_login
772
+ from .config import load_config
773
+
774
+ school_login.clear(self._login_school(load_config(), key))
641
775
  except Exception as exc:
642
776
  return {"ok": False, "error": f"清除失败:{type(exc).__name__}"}
643
777
  return self.school_login_state()
644
778
 
779
+ def find_school(self, query: str = "") -> dict[str, Any]:
780
+ """The sign-in page's 添加学校: the school named, in any language, by its domain or entityID, from
781
+ the federations' own lists (schools/lookup.py, as setup finds one); each with whether Pro fills its
782
+ sign-in in and whether it is saved already (user, 2026-11-20: only a school found there is kept)."""
783
+ if not pro_features():
784
+ return {"ok": False, "error": "这个版本没有自动登录"}
785
+ query = str(query or "").strip()
786
+ if not query:
787
+ return {"ok": False, "error": "请输入学校名称"}
788
+ try:
789
+ from . import school_login
790
+ from .config import DATA_DIR, load_config
791
+ from .schools import lookup
792
+ from .schools import saved as saved_schools
793
+
794
+ config = load_config()
795
+ found = lookup.find(query, config, DATA_DIR)
796
+ schools = ([found.school] if found.school is not None else []) + [s for s in found.candidates if s != found.school]
797
+ # Kept for 添加: the school found, not looked up again (user, 2026-11-20: the page seemed stuck).
798
+ self._found_schools = {school.entity_id: school for school in schools if school.entity_id}
799
+ saved_schools.remember(config)
800
+ saved = {str(entry.get("idp_entity_id") or "").strip() for entry in saved_schools.saved(config)}
801
+ pro = school_login.module()
802
+ # 支持哪些学校's own search too (user, 2026-11-21: 台湾 found nothing here, Taiwan's schools there): Pro's
803
+ # list by any of its names (Wikidata's Chinese one among them), its country, province or state, in
804
+ # Chinese or English; each school's names in other languages for the page to show.
805
+ listed = [school for school in school_login.school_list(pro) if school["key"]] if pro is not None else []
806
+ known = {school["key"]: school for school in listed}
807
+ wanted = query.lower()
808
+
809
+ def said(school: dict[str, Any]) -> str:
810
+ places = [school["province"], school["area"], school["country"]]
811
+ return " ".join([school["name"], school["name_en"], *school["names"].values(), *places,
812
+ *(i18n.translate(place, "en") for place in places if place)]).lower()
813
+
814
+ results = [{"key": school.entity_id, "name": school.name, "name_en": school.name_en,
815
+ "names": known.get(school.entity_id, {}).get("names", {}),
816
+ "federation": school.summary()["federation"], "added": school.entity_id in saved,
817
+ "status": school_login.school_status(school.entity_id, pro) if pro is not None else ""}
818
+ for school in schools if school.entity_id]
819
+ taken = {result["key"] for result in results}
820
+ results += [{"key": school["key"], "name": school["name"], "name_en": school["name_en"], "names": school["names"],
821
+ "federation": school["country"], "added": school["key"] in saved, "status": school["status"]}
822
+ for school in listed if school["key"] not in taken and wanted in said(school)]
823
+ except Exception as exc:
824
+ return {"ok": False, "error": f"查找失败:{type(exc).__name__}"}
825
+ left = max(0, len(results) - FOUND_SHOWN)
826
+ note = (f"还有 {left} 所没列出,输入更完整的名称可以缩小范围" if left
827
+ else "" if results else "这所学校所在的学术联盟还不支持" if found.unsupported
828
+ else "学校名单暂时读不到,请稍后再试" if found.unavailable
829
+ else "没有找到这所学校:换成学校的正式中文名、英文名或网址试试")
830
+ return {"ok": True, "results": results[:FOUND_SHOWN], "note": note}
831
+
832
+ def add_school(self, key: str = "") -> dict[str, Any]:
833
+ """A school found by 添加学校 kept in the saved list, the default one unchanged (none yet: it)."""
834
+ if not pro_features():
835
+ return {"ok": False, "error": "这个版本没有自动登录"}
836
+ try:
837
+ from .config import DATA_DIR, load_config, save_config
838
+ from .schools import lookup
839
+ from .schools import saved as saved_schools
840
+
841
+ key = str(key or "").strip()
842
+ config = load_config()
843
+ known = getattr(self, "_found_schools", {}).get(key) # the school 添加学校 found
844
+ if known is None:
845
+ found = lookup.find(key, config, DATA_DIR) if key else None
846
+ if found is None or found.school is None or found.school.entity_id != key:
847
+ return {"ok": False, "error": "这所学校没有找到,请重新查找"}
848
+ known = found.school
849
+ school: dict[str, Any] = {}
850
+ lookup.save(school, known)
851
+ if saved_schools.current(config) is None:
852
+ saved_schools.apply(config, school)
853
+ saved_schools.remember(config)
854
+ listed = saved_schools.saved(config)
855
+ if not any(saved_schools._same(entry, school) for entry in listed):
856
+ listed.append({name: school.get(name) for name in saved_schools.SCHOOL_FIELDS})
857
+ config[saved_schools.SAVED_KEY] = listed[:saved_schools.MAX_SAVED]
858
+ save_config(config)
859
+ except Exception as exc:
860
+ return {"ok": False, "error": f"添加失败:{type(exc).__name__}"}
861
+ return self.school_login_state()
862
+
863
+ def set_default_school(self, key: str = "") -> dict[str, Any]:
864
+ """A saved school as the default one for downloads (the current school; `paper-search-school use`)."""
865
+ if not pro_features():
866
+ return {"ok": False, "error": "这个版本没有自动登录"}
867
+ try:
868
+ from .config import load_config, save_config
869
+ from .schools import saved as saved_schools
870
+
871
+ config = load_config()
872
+ saved_schools.remember(config)
873
+ entry = next((entry for entry in saved_schools.saved(config)
874
+ if str(entry.get("idp_entity_id") or "").strip() == str(key or "").strip()), None)
875
+ if entry is None:
876
+ return {"ok": False, "error": "这所学校还没有添加"}
877
+ saved_schools.apply(config, entry)
878
+ saved_schools.remember(config)
879
+ save_config(config)
880
+ except Exception as exc:
881
+ return {"ok": False, "error": f"切换失败:{type(exc).__name__}"}
882
+ return self.school_login_state()
883
+
884
+ def forget_school(self, key: str = "") -> dict[str, Any]:
885
+ """A saved school out of the list, its account with it; the default one stays."""
886
+ if not pro_features():
887
+ return {"ok": False, "error": "这个版本没有自动登录"}
888
+ try:
889
+ from . import school_login
890
+ from .config import load_config, save_config
891
+ from .schools import saved as saved_schools
892
+
893
+ config = load_config()
894
+ saved_schools.remember(config)
895
+ entry = next((entry for entry in saved_schools.saved(config)
896
+ if str(entry.get("idp_entity_id") or "").strip() == str(key or "").strip()), None)
897
+ if entry is None:
898
+ return {"ok": False, "error": "这所学校还没有添加"}
899
+ if not saved_schools.forget(config, entry):
900
+ return {"ok": False, "error": "默认学校不能移除:先把别的学校设为默认"}
901
+ save_config(config)
902
+ school_login.clear(str(key).strip())
903
+ except Exception as exc:
904
+ return {"ok": False, "error": f"移除失败:{type(exc).__name__}"}
905
+ return self.school_login_state()
906
+
645
907
  def pro_status(self) -> dict[str, Any]:
646
908
  from . import pro_status
647
909
 
@@ -650,28 +912,13 @@ class Api:
650
912
  except Exception as exc:
651
913
  return {"ok": False, "error": f"读取失败:{type(exc).__name__}"}
652
914
 
653
- def install_pro(self) -> dict[str, Any]:
654
- """The Markdown page's 安装: starts it, or says how it goes (pro_install_state)."""
655
- return self._pro_installer().start()
915
+ def install_pro(self, code: str | None = None) -> dict[str, Any]:
916
+ """Pro's 安装, or 激活并安装 with the code typed: starts it, or says how it goes (pro_install_state)."""
917
+ return self._pro_installer().start(None if code is None else str(code))
656
918
 
657
919
  def pro_install_state(self) -> dict[str, Any]:
658
920
  return self._pro_installer().state()
659
921
 
660
- def check_pro(self) -> dict[str, Any]:
661
- """The Markdown page's 检查更新: starts it, or says how it goes (pro_check_state)."""
662
- return self._pro_checker().start()
663
-
664
- def pro_check_state(self) -> dict[str, Any]:
665
- return self._pro_checker().state()
666
-
667
- def _pro_checker(self):
668
- from .pro_status import ProCheck
669
-
670
- checker = getattr(self, "_pro_check", None)
671
- if checker is None:
672
- checker = self._pro_check = ProCheck()
673
- return checker
674
-
675
922
  def _pro_installer(self):
676
923
  from .pro_status import ProInstall
677
924
 
@@ -680,6 +927,69 @@ class Api:
680
927
  installer = self._pro_install = ProInstall()
681
928
  return installer
682
929
 
930
+ # One version and one update (user, 2026-11-21; updates.py): the about page, the home page's foot, the card's dot.
931
+ def versions(self) -> dict[str, Any]:
932
+ """The version this window runs and the one installed now (an update elsewhere: they differ)."""
933
+ from . import updates
934
+
935
+ return {"running": updates.RUNNING, "installed": updates.installed_version()}
936
+
937
+ def check_versions(self, again: bool = False) -> dict[str, Any]:
938
+ return self._version_check().start(bool(again))
939
+
940
+ def versions_state(self) -> dict[str, Any]:
941
+ return self._version_check().state()
942
+
943
+ def update_all(self) -> dict[str, Any]:
944
+ """更新: what the last check found behind (PaperSearch, then its extension and Skills; Pro)."""
945
+ checked = self._version_check().state()
946
+ if checked.get("state") != "done":
947
+ return {"state": "idle", "error": "先检查更新"}
948
+ return self._updater().start(bool(checked.get("update")), bool(checked.get("pro_update")),
949
+ str(checked.get("latest") if checked.get("update") else ""))
950
+
951
+ def update_state(self) -> dict[str, Any]:
952
+ return self._updater().state()
953
+
954
+ def reopen_window(self, page: str = "about") -> dict[str, Any]:
955
+ """The settings opened again with the PaperSearch installed now, once this window has closed."""
956
+ from . import updates
957
+
958
+ page = page if page in ("home", "about") else "about"
959
+ if not updates.reopen(page):
960
+ return {"ok": False, "message": "找不到 paper-search 命令,请关掉窗口后重新打开设置"}
961
+ threading.Timer(0.3, self.request_close).start()
962
+ return {"ok": True}
963
+
964
+ def open_release_notes(self) -> dict[str, Any]:
965
+ """这次更新了什么: the release notes where the check found the new version."""
966
+ import webbrowser
967
+
968
+ url = str(self._version_check().state().get("notes") or "")
969
+ if not url.startswith("https://"):
970
+ return {"ok": False, "message": "没有更新说明"}
971
+ try:
972
+ opened = webbrowser.open(url)
973
+ except Exception as exc:
974
+ return {"ok": False, "message": f"打开失败:{type(exc).__name__}"}
975
+ return {"ok": True} if opened else {"ok": False, "message": "打开失败:没有找到默认浏览器"}
976
+
977
+ def _version_check(self):
978
+ from .updates import VersionCheck
979
+
980
+ check = getattr(self, "_versions", None)
981
+ if check is None:
982
+ check = self._versions = VersionCheck()
983
+ return check
984
+
985
+ def _updater(self):
986
+ from .updates import UpdateAll
987
+
988
+ updater = getattr(self, "_update_all", None)
989
+ if updater is None:
990
+ updater = self._update_all = UpdateAll()
991
+ return updater
992
+
683
993
  def open_issue(self) -> dict[str, Any]:
684
994
  """GitHub's new-issue page for the Markdown, its title begun."""
685
995
  import webbrowser
@@ -40,7 +40,9 @@ _STAGE_LISTENER: ContextVar[tuple[str, Callable[[str], None]] | None] = ContextV
40
40
 
41
41
  STAGES = frozenset({
42
42
  "starting", "opening_article", "waiting_login", "waiting_verification",
43
- "checking_access", "fetching_pdf", "pdf_captured",
43
+ # switching_school (没权限时换下一所学校): no step of its own, the card's line says "没权限,换××" (a school's name can
44
+ # be long: the step bar's label would squeeze the bars; the line ends in … and says it all on hover).
45
+ "checking_access", "fetching_pdf", "pdf_captured", "switching_school",
44
46
  "saved_pending_verification", "access_ready", "supplements_checked", "route_failed", "failed", "cancelled", "interrupted", "unknown",
45
47
  })
46
48
  _IDENTITY_FIELDS = frozenset({"schema_version", "run_id", "revision", "owner_pid"})
@@ -270,6 +272,10 @@ def _batch_state(batch_id: str) -> dict[str, Any] | None:
270
272
  return None
271
273
 
272
274
 
275
+ #: What the card says of the paper it shows, which another paper does not keep (_adopt_batch).
276
+ PAPER_FIELDS = ("title", "journal", "publisher", "notice")
277
+
278
+
273
279
  def _adopt_batch(batch_id: str, total: int, counts: tuple[int | None, int | None, int | None],
274
280
  *, beside_download: bool = False, **fields: Any) -> bool | None:
275
281
  """Continue this batch's report in the current process, or start it (True).
@@ -307,6 +313,10 @@ def _adopt_batch(batch_id: str, total: int, counts: tuple[int | None, int | None
307
313
  and isinstance(owner, int) and owner != os.getpid() and _pid_alive(owner)):
308
314
  return None
309
315
  _STARTED_MONO = time.monotonic()
316
+ if previous is not None and fields.get("current") and str(fields["current"]).lower() != str(previous.get("current") or "").lower():
317
+ # Another paper: the last one's title, journal, publisher and notice go with it (user, 2026-11-21: the card kept
318
+ # one paper's title, and its publisher in place of 开放下载, while the open-access lane went through others).
319
+ previous = {key: value for key, value in previous.items() if key not in PAPER_FIELDS}
310
320
  if previous is None:
311
321
  previous = {
312
322
  # A lone download comes as a batch of one (its finished card gets the reason).
@@ -422,7 +432,10 @@ def _short_line(value: Any, limit: int = 80) -> str:
422
432
 
423
433
  FAILURE_CLASSES = ("no_access", "user_side", "school_side", "publisher_or_network", "article_or_site", "unsupported", "unexplained")
424
434
  _RESULT_CONTENTS = ("main", "supplements", "both", "markdown")
425
- _MAX_RESULT_FAILURES = 1000 # the caller's batch limit
435
+ # A bound against malformed input only: a batch has no limit since 7a38a068 (user, 2026-11-17). Left at its old 1000,
436
+ # a batch's papers after the 1000th were left out of the lists (user, 2026-11-21: 失败 1 on the card, the list empty,
437
+ # the failed paper the 1211th of 1551; 成功 and 剩余 stopped at 1000 too).
438
+ _MAX_BATCH_PAPERS = 100_000
426
439
  _MAX_RESULT_TEXT = 300
427
440
 
428
441
 
@@ -479,7 +492,7 @@ def _batch_results(raw: Any) -> dict[str, Any] | None:
479
492
  }
480
493
  for key in ("failures", "supplement_failures", "markdown_failures"):
481
494
  listed = raw.get(key)
482
- for item in (listed if isinstance(listed, list) else [])[:_MAX_RESULT_FAILURES]:
495
+ for item in (listed if isinstance(listed, list) else [])[:_MAX_BATCH_PAPERS]:
483
496
  if not isinstance(item, dict) or not text(item.get("reason")):
484
497
  continue
485
498
  summary[key].append({
@@ -517,7 +530,7 @@ def _paper(raw: Any) -> dict[str, Any] | None:
517
530
  if not isinstance(raw, dict) or raw.get("state") not in PAPER_STATES:
518
531
  return None
519
532
  index = raw.get("index")
520
- if not isinstance(index, int) or isinstance(index, bool) or not 1 <= index <= _MAX_RESULT_FAILURES:
533
+ if not isinstance(index, int) or isinstance(index, bool) or not 1 <= index <= _MAX_BATCH_PAPERS:
521
534
  return None
522
535
  paper = {"index": index, "state": raw["state"],
523
536
  **{field: _display_text(raw.get(field)) for field in ("doi", "title", "journal")}}
@@ -590,7 +603,7 @@ def sync_papers(batch_id: str, folder: str, papers: Any) -> bool:
590
603
  if isinstance(folder, str) and 0 < len(folder) <= 4096 and os.path.isabs(folder):
591
604
  listed["folder"] = folder
592
605
  known = listed["papers"]
593
- for raw in papers[:_MAX_RESULT_FAILURES]:
606
+ for raw in papers[:_MAX_BATCH_PAPERS]:
594
607
  paper = _paper(raw)
595
608
  if paper is None:
596
609
  continue
@@ -667,6 +680,7 @@ def tracked_download(current: str, output_dir: Any = None, batch: BatchContext |
667
680
  markdown=bool(markdown), page_reading=False)
668
681
  if output_dir:
669
682
  set_output_dir(output_dir)
683
+ name_journal(current)
670
684
  outcome: dict[str, Any] = {}
671
685
  try:
672
686
  yield outcome
@@ -717,6 +731,38 @@ def _finish_download(outcome: dict[str, Any], current: str, batch: BatchContext
717
731
  finish()
718
732
 
719
733
 
734
+ def name_journal(current: str, look_up: Callable[[str], dict[str, Any]] | None = None) -> threading.Thread | None:
735
+ """The paper's journal on the card, where PaperSearch gave none (a list of DOIs; user, 2026-11-21: the card said
736
+ Elsevier, the publisher, for a paper of Metabolism): looked up beside the download (Crossref, kept by
737
+ entitlements.journal_identity), said once known, while the card is still on that paper."""
738
+ if look_up is None and os.environ.get("SCHOOL_PROGRESS_BAR") == "0":
739
+ return None # no card to say it on (and no lookups from the tests)
740
+ with _LOCK:
741
+ if not _STATE or _STATE.get("journal") or str(_STATE.get("current") or "") != current or not current:
742
+ return None
743
+
744
+ def look() -> None:
745
+ try:
746
+ if look_up is None:
747
+ from .entitlements import journal_identity
748
+
749
+ name = str(journal_identity(current).get("journal") or "").strip()
750
+ else:
751
+ name = str(look_up(current).get("journal") or "").strip()
752
+ except Exception:
753
+ return # the card keeps the publisher
754
+ if not name:
755
+ return
756
+ with _LOCK:
757
+ if _STATE and str(_STATE.get("current") or "") == current and not _STATE.get("journal"):
758
+ _STATE["journal"] = name
759
+ _write_state()
760
+
761
+ thread = threading.Thread(target=look, name="journal-name", daemon=True)
762
+ thread.start()
763
+ return thread
764
+
765
+
720
766
  def _write_state() -> None:
721
767
  """Called under _LOCK; revisions count successful atomic replacements only."""
722
768
  payload = {
@@ -311,8 +311,9 @@ def paper_lists(listed: Any, state: dict[str, Any] | None) -> dict[str, Any]:
311
311
  if paper.get("detail"):
312
312
  details[paper["detail"]] = details.get(paper["detail"], 0) + 1
313
313
  label = way + ("(" + "、".join(f"{name} {n}" for name, n in details.items()) + ")" if details else "")
314
- saved.append(group(label, [row(p, p.get("journal"), (p.get("detail") or "开放获取") if way == OPEN_DOWNLOAD else "")
315
- for p in items]))
314
+ # 机构下载's detail: the saved school it went through, when not the default one (没权限时换下一所学校).
315
+ saved.append(group(label, [row(p, p.get("journal"), (p.get("detail") or "开放获取") if way == OPEN_DOWNLOAD
316
+ else str(p.get("detail") or "")) for p in items]))
316
317
 
317
318
  # A batch of the Markdown alone fails a paper for its Markdown: a site not yet supported's
318
319
  # note stands in for the journal, as on the finished card (user, 2026-11-16).