andandandand commited on
Commit
1d0166a
·
verified ·
1 Parent(s): 9a04857

Force dock layout cache reset version and keep Sphere3D default panel

Browse files
Files changed (1) hide show
  1. demo.py +49 -14
demo.py CHANGED
@@ -5,6 +5,7 @@ from __future__ import annotations
5
 
6
  import json
7
  import os
 
8
  from pathlib import Path
9
  from typing import Any
10
 
@@ -35,15 +36,20 @@ ASSET_MANIFEST_PATH = Path(
35
 
36
 
37
  def _patch_hyperview_default_panel() -> None:
38
- """Patch HyperView 0.3.1 frontend so Sphere 3D opens as the active scatter panel.
39
 
40
- HyperView currently has no public API for this behavior. This runtime patch is
41
  intentionally narrow and idempotent, targeting the known bundled chunk for v0.3.1.
42
  """
43
  default_panel = os.environ.get("HYPERVIEW_DEFAULT_PANEL", "spherical3d").strip().lower()
44
- if default_panel not in {"spherical3d", "sphere3d"}:
 
45
  print(f"Skipping frontend default-panel patch (HYPERVIEW_DEFAULT_PANEL={default_panel!r}).")
46
- return
 
 
 
 
47
 
48
  chunk_path = (
49
  Path(hv.__file__).resolve().parent
@@ -67,22 +73,51 @@ def _patch_hyperview_default_panel() -> None:
67
  print(f"Default-panel patch skipped: failed reading chunk ({exc})")
68
  return
69
 
70
- if marker_after in payload:
71
- print("HyperView frontend already patched for Sphere 3D default panel.")
72
- return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
- if marker_before not in payload:
75
- print("Default-panel patch skipped: expected marker not found in HyperView chunk.")
76
  return
77
 
78
- patched = payload.replace(marker_before, marker_after, 1)
79
  try:
80
  chunk_path.write_text(patched, encoding="utf-8")
81
  except OSError as exc:
82
- print(f"Default-panel patch skipped: failed writing chunk ({exc})")
83
- return
84
-
85
- print("Patched HyperView frontend: Sphere 3D will open as default scatter panel.")
86
 
87
 
88
  def _resolve_bind_host() -> tuple[str, str | None]:
 
5
 
6
  import json
7
  import os
8
+ import re
9
  from pathlib import Path
10
  from typing import Any
11
 
 
36
 
37
 
38
  def _patch_hyperview_default_panel() -> None:
39
+ """Patch HyperView 0.3.1 frontend for default panel and dock cache-key migration.
40
 
41
+ HyperView currently has no public API for these behaviors. This runtime patch is
42
  intentionally narrow and idempotent, targeting the known bundled chunk for v0.3.1.
43
  """
44
  default_panel = os.environ.get("HYPERVIEW_DEFAULT_PANEL", "spherical3d").strip().lower()
45
+ apply_default_panel_patch = default_panel in {"spherical3d", "sphere3d"}
46
+ if not apply_default_panel_patch:
47
  print(f"Skipping frontend default-panel patch (HYPERVIEW_DEFAULT_PANEL={default_panel!r}).")
48
+
49
+ cache_version = os.environ.get("HYPERVIEW_LAYOUT_CACHE_VERSION", "v6").strip() or "v6"
50
+ target_layout_key = f"hyperview:dockview-layout:{cache_version}"
51
+ legacy_layout_key = "hyperview:dockview-layout:v5"
52
+ layout_key_pattern = r"hyperview:dockview-layout:v\d+"
53
 
54
  chunk_path = (
55
  Path(hv.__file__).resolve().parent
 
73
  print(f"Default-panel patch skipped: failed reading chunk ({exc})")
74
  return
75
 
76
+ patched = payload
77
+ changed = False
78
+
79
+ if apply_default_panel_patch:
80
+ if marker_after in patched:
81
+ print("HyperView frontend already patched for Sphere 3D default panel.")
82
+ elif marker_before in patched:
83
+ patched = patched.replace(marker_before, marker_after, 1)
84
+ changed = True
85
+ print("Patched HyperView frontend: Sphere 3D will open as default scatter panel.")
86
+ else:
87
+ print("Default-panel patch skipped: expected marker not found in HyperView chunk.")
88
+
89
+ if target_layout_key in patched:
90
+ print(f"HyperView frontend already uses dock cache key '{target_layout_key}'.")
91
+ elif legacy_layout_key in patched:
92
+ patched = patched.replace(legacy_layout_key, target_layout_key, 1)
93
+ changed = True
94
+ print(f"Patched HyperView frontend: dock cache key {legacy_layout_key} -> {target_layout_key}.")
95
+ else:
96
+ discovered = re.search(layout_key_pattern, patched)
97
+ if discovered:
98
+ source_key = discovered.group(0)
99
+ if source_key == target_layout_key:
100
+ print(f"HyperView frontend already uses dock cache key '{target_layout_key}'.")
101
+ else:
102
+ print(
103
+ f"Dock cache patch notice: expected legacy key '{legacy_layout_key}' not found; "
104
+ f"migrating detected key '{source_key}' -> '{target_layout_key}'."
105
+ )
106
+ patched = patched.replace(source_key, target_layout_key, 1)
107
+ changed = True
108
+ else:
109
+ print(
110
+ "Dock cache patch warning: expected layout cache key marker "
111
+ f"'{legacy_layout_key}' not found in HyperView chunk."
112
+ )
113
 
114
+ if not changed:
 
115
  return
116
 
 
117
  try:
118
  chunk_path.write_text(patched, encoding="utf-8")
119
  except OSError as exc:
120
+ print(f"Frontend patch skipped: failed writing chunk ({exc})")
 
 
 
121
 
122
 
123
  def _resolve_bind_host() -> tuple[str, str | None]: