dsh-app-controls 0.5.2 → 0.6.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.
- package/README.md +28 -18
- package/assets/dsh-tray.png +0 -0
- package/lib/client.js +332 -8
- package/lib/index.js +246 -11
- package/lib/settings.js +21 -0
- package/lib/update.js +640 -0
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +3 -2
- package/tray/dsh-tray.py +371 -34
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-app-controls",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "DeepSeek Harness Web GUI controls,
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "DeepSeek Harness Web GUI controls, single-instance DeepSeek-style KDE tray icon, same-window navigation, safe update deferral with task warnings, remembered window size, and cache cleanup.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"cordis.patch.yml",
|
|
17
17
|
"locale",
|
|
18
18
|
"icon.svg",
|
|
19
|
+
"assets",
|
|
19
20
|
"tray/dsh-tray.py"
|
|
20
21
|
],
|
|
21
22
|
"icon": "./icon.svg",
|
package/tray/dsh-tray.py
CHANGED
|
@@ -41,6 +41,10 @@ URL = os.environ.get("DSH_WEB_URL", "http://127.0.0.1:3080/")
|
|
|
41
41
|
AUTOSTART = HOME / ".config/autostart/dsh-tray.desktop"
|
|
42
42
|
LOCK_FILE = STATE_DIR / "tray.lock"
|
|
43
43
|
ICON_SVG = PLUGIN_DIR / "icon.svg"
|
|
44
|
+
SETTINGS_FILE = STATE_DIR / "settings.json"
|
|
45
|
+
WHALE_ASSET = PLUGIN_DIR / "assets" / "dsh-tray.png"
|
|
46
|
+
TRAY_ICON_STYLES = ("deepseek", "classic", "custom")
|
|
47
|
+
DEFAULT_TRAY_ICON_STYLE = "deepseek"
|
|
44
48
|
|
|
45
49
|
STATUS_INTERVAL_MS = 2000
|
|
46
50
|
UPDATE_INTERVAL_MS = 30 * 60 * 1000
|
|
@@ -71,6 +75,99 @@ def log(message: str) -> None:
|
|
|
71
75
|
pass
|
|
72
76
|
|
|
73
77
|
|
|
78
|
+
def read_tray_icon_settings(path: Path | None = None) -> tuple[str, Path]:
|
|
79
|
+
"""Read the tray icon choice from the shared settings file.
|
|
80
|
+
|
|
81
|
+
The settings file is owned by the host plugin, so this reader is
|
|
82
|
+
deliberately forgiving: a missing file, invalid JSON or an unknown style
|
|
83
|
+
all fall back to the DeepSeek whale. ``custom`` with a missing or
|
|
84
|
+
unreadable image also falls back to the whale, matching the Web UI.
|
|
85
|
+
"""
|
|
86
|
+
style = DEFAULT_TRAY_ICON_STYLE
|
|
87
|
+
custom = ""
|
|
88
|
+
try:
|
|
89
|
+
data = json.loads((path or SETTINGS_FILE).read_text(encoding="utf-8"))
|
|
90
|
+
except Exception:
|
|
91
|
+
return style, Path()
|
|
92
|
+
if isinstance(data, dict):
|
|
93
|
+
value = data.get("trayIcon")
|
|
94
|
+
if isinstance(value, dict):
|
|
95
|
+
candidate = value.get("style")
|
|
96
|
+
if candidate in TRAY_ICON_STYLES:
|
|
97
|
+
style = candidate
|
|
98
|
+
raw_custom = value.get("customPath")
|
|
99
|
+
if isinstance(raw_custom, str):
|
|
100
|
+
custom = raw_custom.strip()
|
|
101
|
+
if style != "custom" or not custom:
|
|
102
|
+
return (DEFAULT_TRAY_ICON_STYLE if style == "custom" else style), Path()
|
|
103
|
+
resolved = Path(os.path.expandvars(os.path.expanduser(custom)))
|
|
104
|
+
if not resolved.is_absolute():
|
|
105
|
+
resolved = HOME / resolved
|
|
106
|
+
try:
|
|
107
|
+
if not resolved.is_file() or not os.access(resolved, os.R_OK):
|
|
108
|
+
return DEFAULT_TRAY_ICON_STYLE, Path()
|
|
109
|
+
except OSError:
|
|
110
|
+
return DEFAULT_TRAY_ICON_STYLE, Path()
|
|
111
|
+
return "custom", resolved
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def read_update_defer_minutes(path: Path | None = None) -> int:
|
|
115
|
+
"""Read the shared default defer duration from settings.json."""
|
|
116
|
+
try:
|
|
117
|
+
data = json.loads((path or SETTINGS_FILE).read_text(encoding="utf-8"))
|
|
118
|
+
except Exception:
|
|
119
|
+
return 60
|
|
120
|
+
value = data.get("update") if isinstance(data, dict) else None
|
|
121
|
+
minutes = value.get("deferMinutes") if isinstance(value, dict) else None
|
|
122
|
+
try:
|
|
123
|
+
number = int(minutes)
|
|
124
|
+
except (TypeError, ValueError):
|
|
125
|
+
return 60
|
|
126
|
+
return number if 5 <= number <= 7 * 24 * 60 else 60
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def find_other_tray_processes() -> list[int]:
|
|
130
|
+
"""Return PIDs of other ``dsh-tray.py`` processes for this user.
|
|
131
|
+
|
|
132
|
+
``main()`` uses this before taking the lock so a second tray (for example
|
|
133
|
+
after an update, a manual start or a login race) exits immediately instead
|
|
134
|
+
of showing duplicate icons. Only the real script invocation counts:
|
|
135
|
+
one-shot ``python -m py_compile``/``-c`` commands and ``--check`` runs are
|
|
136
|
+
ignored, and the calling process is never reported. The scan lives here,
|
|
137
|
+
not in ``Tray.__init__``, so offscreen tests can instantiate ``Tray``.
|
|
138
|
+
"""
|
|
139
|
+
own_pid = os.getpid()
|
|
140
|
+
found: list[int] = []
|
|
141
|
+
try:
|
|
142
|
+
entries = os.listdir("/proc")
|
|
143
|
+
except OSError:
|
|
144
|
+
return found
|
|
145
|
+
for entry in entries:
|
|
146
|
+
if not entry.isdigit():
|
|
147
|
+
continue
|
|
148
|
+
pid = int(entry)
|
|
149
|
+
if pid == own_pid:
|
|
150
|
+
continue
|
|
151
|
+
try:
|
|
152
|
+
if os.stat(f"/proc/{pid}").st_uid != os.getuid():
|
|
153
|
+
continue
|
|
154
|
+
raw = Path(f"/proc/{pid}/cmdline").read_bytes()
|
|
155
|
+
except OSError:
|
|
156
|
+
continue
|
|
157
|
+
args = [part.decode("utf-8", "replace") for part in raw.split(b"\0") if part]
|
|
158
|
+
if not args:
|
|
159
|
+
continue
|
|
160
|
+
executable = Path(args[0]).name.lower()
|
|
161
|
+
if "python" not in executable:
|
|
162
|
+
continue
|
|
163
|
+
if "-m" in args or "-c" in args or "--check" in args:
|
|
164
|
+
continue
|
|
165
|
+
if any(Path(arg).name == "dsh-tray.py" for arg in args[1:]):
|
|
166
|
+
if pid not in found:
|
|
167
|
+
found.append(pid)
|
|
168
|
+
return found
|
|
169
|
+
|
|
170
|
+
|
|
74
171
|
def dsh_theme_preference() -> str:
|
|
75
172
|
"""Read the DSH Web profile's theme preference without requiring PyYAML."""
|
|
76
173
|
try:
|
|
@@ -201,6 +298,8 @@ class Tray(QSystemTrayIcon):
|
|
|
201
298
|
self.suppress_stop_notice = False
|
|
202
299
|
self.last_job_finished = None
|
|
203
300
|
self.last_notified_update = None
|
|
301
|
+
self.update_defer_until = 0.0
|
|
302
|
+
self.defer_notice_scheduled = False
|
|
204
303
|
self.requests = set()
|
|
205
304
|
self._request_id = 0
|
|
206
305
|
self.state = "stopped"
|
|
@@ -209,6 +308,11 @@ class Tray(QSystemTrayIcon):
|
|
|
209
308
|
self._theme_pref = None
|
|
210
309
|
self.check_result = None
|
|
211
310
|
self.check_result_deadline = 0.0
|
|
311
|
+
self.icon_style = DEFAULT_TRAY_ICON_STYLE
|
|
312
|
+
self.custom_icon_path = Path()
|
|
313
|
+
self._whale_source = None
|
|
314
|
+
self._icon_settings_key = None
|
|
315
|
+
self._custom_icon_fallback_logged = False
|
|
212
316
|
|
|
213
317
|
self.dark = self._resolve_dark()
|
|
214
318
|
self.menu = QMenu()
|
|
@@ -308,12 +412,15 @@ class Tray(QSystemTrayIcon):
|
|
|
308
412
|
dark = True if preference == "dark" else False if preference == "light" else base.lightness() < 128
|
|
309
413
|
key = (preference, dark, base.name())
|
|
310
414
|
if not force and key == self._theme_key:
|
|
415
|
+
self._sync_icon_settings()
|
|
311
416
|
return
|
|
312
417
|
self._theme_pref = preference
|
|
313
418
|
self.dark = dark
|
|
314
419
|
self._theme_key = key
|
|
420
|
+
self._sync_icon_settings()
|
|
315
421
|
self.menu.setStyleSheet(self._menu_style())
|
|
316
422
|
self._apply_action_icons()
|
|
423
|
+
self.setIcon(self._make_icon(self.state))
|
|
317
424
|
self._refresh_menu()
|
|
318
425
|
log(f"tray theme: {preference} ({'dark' if dark else 'light'})")
|
|
319
426
|
except Exception as error:
|
|
@@ -322,6 +429,25 @@ class Tray(QSystemTrayIcon):
|
|
|
322
429
|
def _sync_theme(self) -> None:
|
|
323
430
|
self._apply_theme()
|
|
324
431
|
|
|
432
|
+
def _sync_icon_settings(self) -> None:
|
|
433
|
+
"""Pick up trayIcon changes written by the Web settings panel."""
|
|
434
|
+
try:
|
|
435
|
+
stat = SETTINGS_FILE.stat()
|
|
436
|
+
key = (stat.st_mtime_ns, stat.st_size)
|
|
437
|
+
except OSError:
|
|
438
|
+
key = None
|
|
439
|
+
if key == self._icon_settings_key:
|
|
440
|
+
return
|
|
441
|
+
self._icon_settings_key = key
|
|
442
|
+
style, custom = read_tray_icon_settings()
|
|
443
|
+
if style == self.icon_style and custom == self.custom_icon_path:
|
|
444
|
+
return
|
|
445
|
+
self.icon_style = style
|
|
446
|
+
self.custom_icon_path = custom
|
|
447
|
+
self._custom_icon_fallback_logged = False
|
|
448
|
+
self.setIcon(self._make_icon(self.state))
|
|
449
|
+
log(f"tray icon style: {style}" + (f" ({custom})" if style == "custom" else ""))
|
|
450
|
+
|
|
325
451
|
def _menu_icon(self, kind: str, color: str | None = None) -> QIcon:
|
|
326
452
|
c = QColor(color or self._colors()["text"])
|
|
327
453
|
size = 18
|
|
@@ -484,14 +610,9 @@ class Tray(QSystemTrayIcon):
|
|
|
484
610
|
self.checking = False
|
|
485
611
|
if response.get("ok") and response.get("update"):
|
|
486
612
|
self.update = response["update"]
|
|
613
|
+
self._note_update_defer(self.update)
|
|
487
614
|
if self.update.get("updateAvailable"):
|
|
488
|
-
|
|
489
|
-
if candidate != self.last_notified_update:
|
|
490
|
-
self.last_notified_update = candidate
|
|
491
|
-
self._notify(
|
|
492
|
-
"有可用更新",
|
|
493
|
-
f"DeepSeek Harness {candidate}(当前 {self.update.get('current')})",
|
|
494
|
-
)
|
|
615
|
+
self._maybe_notify_update()
|
|
495
616
|
elif mode == "manual":
|
|
496
617
|
self._set_check_result("已是最新版本")
|
|
497
618
|
elif mode == "manual":
|
|
@@ -513,6 +634,86 @@ class Tray(QSystemTrayIcon):
|
|
|
513
634
|
self.check_result = None
|
|
514
635
|
self._refresh_menu()
|
|
515
636
|
|
|
637
|
+
def _note_update_defer(self, value) -> None:
|
|
638
|
+
if not isinstance(value, dict):
|
|
639
|
+
return
|
|
640
|
+
until = value.get("updateDeferUntil")
|
|
641
|
+
if isinstance(until, (int, float)) and until > 0:
|
|
642
|
+
self.update_defer_until = max(self.update_defer_until, float(until))
|
|
643
|
+
# A deferral set elsewhere (for example the Web dialog) should
|
|
644
|
+
# allow a fresh notification when it expires.
|
|
645
|
+
self.last_notified_update = None
|
|
646
|
+
|
|
647
|
+
def _update_deferred(self) -> bool:
|
|
648
|
+
return self.update_defer_until > time.time()
|
|
649
|
+
|
|
650
|
+
def _defer_time_text(self) -> str:
|
|
651
|
+
if not self._update_deferred():
|
|
652
|
+
return ""
|
|
653
|
+
return time.strftime("%H:%M", time.localtime(self.update_defer_until))
|
|
654
|
+
|
|
655
|
+
def _maybe_notify_update(self) -> None:
|
|
656
|
+
if not isinstance(self.update, dict) or not self.update.get("updateAvailable"):
|
|
657
|
+
return
|
|
658
|
+
# The startup check can finish before KDE has attached the tray icon;
|
|
659
|
+
# wait for the icon to be visible so the notification is not lost.
|
|
660
|
+
if not self.isVisible():
|
|
661
|
+
QTimer.singleShot(2000, self._maybe_notify_update)
|
|
662
|
+
return
|
|
663
|
+
if self._update_deferred():
|
|
664
|
+
remain = max(1.0, self.update_defer_until - time.time())
|
|
665
|
+
if not self.defer_notice_scheduled:
|
|
666
|
+
self.defer_notice_scheduled = True
|
|
667
|
+
QTimer.singleShot(int(remain * 1000) + 500, self._on_defer_expired)
|
|
668
|
+
return
|
|
669
|
+
candidate = self.update.get("candidate")
|
|
670
|
+
if candidate == self.last_notified_update:
|
|
671
|
+
return
|
|
672
|
+
self.last_notified_update = candidate
|
|
673
|
+
self._notify(
|
|
674
|
+
"有可用更新",
|
|
675
|
+
f"DeepSeek Harness {candidate}(当前 {self.update.get('current')})\n"
|
|
676
|
+
"右键托盘图标可立即更新,或先推迟更新。",
|
|
677
|
+
)
|
|
678
|
+
|
|
679
|
+
def _on_defer_expired(self) -> None:
|
|
680
|
+
self.defer_notice_scheduled = False
|
|
681
|
+
self.update_defer_until = 0.0
|
|
682
|
+
self._maybe_notify_update()
|
|
683
|
+
self._refresh_menu()
|
|
684
|
+
|
|
685
|
+
def _defer_update(self, minutes: int = 60) -> None:
|
|
686
|
+
def done(response: dict) -> None:
|
|
687
|
+
if not response.get("ok"):
|
|
688
|
+
self._notify("无法推迟更新", response.get("message") or response.get("error") or "未知错误")
|
|
689
|
+
return
|
|
690
|
+
until = response.get("updateDeferUntil")
|
|
691
|
+
if isinstance(until, (int, float)) and until > 0:
|
|
692
|
+
self.update_defer_until = float(until)
|
|
693
|
+
self.defer_notice_scheduled = False
|
|
694
|
+
self.last_notified_update = None
|
|
695
|
+
self._notify("已推迟更新", f"将在 {minutes} 分钟后再提醒你。")
|
|
696
|
+
self._refresh_menu()
|
|
697
|
+
|
|
698
|
+
self._request({"command": "defer-update", "minutes": minutes}, done, timeout_ms=CHECK_TIMEOUT_MS)
|
|
699
|
+
|
|
700
|
+
def _activity_text(self) -> str:
|
|
701
|
+
update = self.update if isinstance(self.update, dict) else {}
|
|
702
|
+
activity = update.get("activity")
|
|
703
|
+
if not isinstance(activity, dict) or activity.get("available") is False:
|
|
704
|
+
return "暂时无法确认是否有任务在运行,更新前请留意。"
|
|
705
|
+
if not activity.get("active"):
|
|
706
|
+
return "当前没有检测到正在运行的任务。"
|
|
707
|
+
parts = []
|
|
708
|
+
if isinstance(activity.get("turns"), int) and activity["turns"] > 0:
|
|
709
|
+
parts.append(f"{activity['turns']} 个进行中的对话")
|
|
710
|
+
if isinstance(activity.get("jobs"), int) and activity["jobs"] > 0:
|
|
711
|
+
parts.append(f"{activity['jobs']} 个后台任务")
|
|
712
|
+
count = activity.get("count")
|
|
713
|
+
if not isinstance(count, int) or count <= 0:
|
|
714
|
+
count = len(activity.get("items") or [])
|
|
715
|
+
return f"检测到 {count} 个正在运行的任务({'、'.join(parts)})。更新会重启本地服务,这些任务会被中断。"
|
|
716
|
+
|
|
516
717
|
# ── status handling ─────────────────────────────────────────────────────
|
|
517
718
|
def _on_status(self, response: dict) -> None:
|
|
518
719
|
self.polling = False
|
|
@@ -526,6 +727,10 @@ class Tray(QSystemTrayIcon):
|
|
|
526
727
|
self.job = response.get("job") if isinstance(response.get("job"), dict) else None
|
|
527
728
|
if isinstance(response.get("update"), dict):
|
|
528
729
|
self.update = response["update"]
|
|
730
|
+
self._note_update_defer(self.update)
|
|
731
|
+
self.update_defer_until = float(response.get("updateDeferUntil") or 0)
|
|
732
|
+
if self.update_defer_until > time.time():
|
|
733
|
+
self.last_notified_update = None
|
|
529
734
|
if not had_status:
|
|
530
735
|
log("connected to DeepSeek Harness control socket")
|
|
531
736
|
|
|
@@ -545,16 +750,7 @@ class Tray(QSystemTrayIcon):
|
|
|
545
750
|
self.suppress_stop_notice = True
|
|
546
751
|
self.tray_update = False
|
|
547
752
|
|
|
548
|
-
|
|
549
|
-
isinstance(self.update, dict)
|
|
550
|
-
and self.update.get("updateAvailable")
|
|
551
|
-
and self.update.get("candidate") != self.last_notified_update
|
|
552
|
-
):
|
|
553
|
-
self.last_notified_update = self.update.get("candidate")
|
|
554
|
-
self._notify(
|
|
555
|
-
"有可用更新",
|
|
556
|
-
f"DeepSeek Harness {self.update.get('candidate')}(当前 {self.update.get('current')})",
|
|
557
|
-
)
|
|
753
|
+
self._maybe_notify_update()
|
|
558
754
|
self._refresh_menu()
|
|
559
755
|
|
|
560
756
|
def _handle_unreachable(self) -> None:
|
|
@@ -584,16 +780,33 @@ class Tray(QSystemTrayIcon):
|
|
|
584
780
|
self.launch()
|
|
585
781
|
|
|
586
782
|
def open_plugins(self) -> None:
|
|
587
|
-
|
|
588
|
-
self._notify("服务未运行", "请先点击托盘图标启动 DeepSeek Harness。")
|
|
589
|
-
return
|
|
590
|
-
self._run_launcher("dsh-app-controls/plugins")
|
|
783
|
+
self._open_view("plugins")
|
|
591
784
|
|
|
592
785
|
def open_settings(self) -> None:
|
|
786
|
+
self._open_view("settings")
|
|
787
|
+
|
|
788
|
+
def _open_view(self, view: str) -> None:
|
|
789
|
+
"""Switch the existing Web window to ``view`` instead of opening one.
|
|
790
|
+
|
|
791
|
+
The host owns the browser window, so while the service is running the
|
|
792
|
+
tray asks it to change views over the control socket and only then
|
|
793
|
+
focuses the app through the launcher. The launcher is called without
|
|
794
|
+
a hash so an existing Chrome app window is reused. If the service is
|
|
795
|
+
stopped, or the host predates the ``open-view`` command, fall back to
|
|
796
|
+
the launcher hash so the page still opens.
|
|
797
|
+
"""
|
|
593
798
|
if self.status is None:
|
|
594
|
-
self.
|
|
799
|
+
self._run_launcher(f"dsh-app-controls/{view}")
|
|
595
800
|
return
|
|
596
|
-
|
|
801
|
+
|
|
802
|
+
def done(response: dict) -> None:
|
|
803
|
+
if response.get("ok"):
|
|
804
|
+
self._run_launcher()
|
|
805
|
+
return
|
|
806
|
+
log(f"open-view {view} failed: {response.get('error') or response.get('message')}")
|
|
807
|
+
self._run_launcher(f"dsh-app-controls/{view}")
|
|
808
|
+
|
|
809
|
+
self._request({"command": "open-view", "view": view}, done, timeout_ms=1500)
|
|
597
810
|
|
|
598
811
|
def launch(self) -> None:
|
|
599
812
|
if self.starting:
|
|
@@ -729,14 +942,32 @@ class Tray(QSystemTrayIcon):
|
|
|
729
942
|
return
|
|
730
943
|
if isinstance(self.update, dict) and self.update.get("updateAvailable"):
|
|
731
944
|
candidate = self.update.get("candidate")
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
945
|
+
activity = self.update.get("activity") if isinstance(self.update.get("activity"), dict) else {}
|
|
946
|
+
active = bool(activity.get("active"))
|
|
947
|
+
minutes = read_update_defer_minutes()
|
|
948
|
+
defer_label = "1 小时" if minutes == 60 else f"{minutes} 分钟"
|
|
949
|
+
box = QMessageBox()
|
|
950
|
+
box.setWindowTitle("更新 DeepSeek Harness")
|
|
951
|
+
box.setIcon(QMessageBox.Warning if active else QMessageBox.Information)
|
|
952
|
+
box.setText(f"发现新版本 {candidate}(当前 {self.update.get('current')})。")
|
|
953
|
+
box.setInformativeText(
|
|
954
|
+
f"{self._activity_text()}\n\n"
|
|
955
|
+
"更新会下载新版本并重启本地服务,正在进行的对话或后台任务会被中断。\n"
|
|
956
|
+
f"你可以立即更新,或推迟 {defer_label} 后再处理。"
|
|
738
957
|
)
|
|
739
|
-
|
|
958
|
+
notes = self.update.get("releaseNotes")
|
|
959
|
+
if isinstance(notes, dict) and isinstance(notes.get("notes"), str) and notes["notes"].strip():
|
|
960
|
+
box.setDetailedText(notes["notes"].strip()[:4000])
|
|
961
|
+
update_button = box.addButton("立即更新", QMessageBox.AcceptRole)
|
|
962
|
+
defer_button = box.addButton(f"推迟 {defer_label}", QMessageBox.ActionRole)
|
|
963
|
+
box.addButton("取消", QMessageBox.RejectRole)
|
|
964
|
+
box.setDefaultButton(defer_button if active else update_button)
|
|
965
|
+
box.exec_()
|
|
966
|
+
clicked = box.clickedButton()
|
|
967
|
+
if clicked is defer_button:
|
|
968
|
+
self._defer_update(minutes)
|
|
969
|
+
return
|
|
970
|
+
if clicked is not update_button:
|
|
740
971
|
return
|
|
741
972
|
self.tray_update = True
|
|
742
973
|
self._request({"command": "update"}, self._on_update_start, timeout_ms=CHECK_TIMEOUT_MS)
|
|
@@ -826,6 +1057,96 @@ for (var pi = 0; pi < ps.length; pi++) {
|
|
|
826
1057
|
self._refresh_menu()
|
|
827
1058
|
|
|
828
1059
|
def _make_icon(self, state: str) -> QIcon:
|
|
1060
|
+
if self.icon_style == "custom":
|
|
1061
|
+
icon = self._make_custom_icon(state)
|
|
1062
|
+
if icon is not None:
|
|
1063
|
+
return icon
|
|
1064
|
+
if self.icon_style == "classic":
|
|
1065
|
+
return self._make_classic_icon(state)
|
|
1066
|
+
return self._make_deepseek_icon(state)
|
|
1067
|
+
|
|
1068
|
+
def _whale_pixmap(self) -> QPixmap | None:
|
|
1069
|
+
if self._whale_source is not None:
|
|
1070
|
+
return self._whale_source
|
|
1071
|
+
pixmap = QPixmap(str(WHALE_ASSET))
|
|
1072
|
+
if pixmap.isNull():
|
|
1073
|
+
log(f"DeepSeek tray asset is missing: {WHALE_ASSET}")
|
|
1074
|
+
return None
|
|
1075
|
+
self._whale_source = pixmap
|
|
1076
|
+
return pixmap
|
|
1077
|
+
|
|
1078
|
+
@staticmethod
|
|
1079
|
+
def _tint_pixmap(source: QPixmap, color: QColor) -> QPixmap:
|
|
1080
|
+
result = QPixmap(source.size())
|
|
1081
|
+
result.fill(Qt.transparent)
|
|
1082
|
+
painter = QPainter(result)
|
|
1083
|
+
painter.drawPixmap(0, 0, source)
|
|
1084
|
+
painter.setCompositionMode(QPainter.CompositionMode_SourceIn)
|
|
1085
|
+
painter.fillRect(result.rect(), color)
|
|
1086
|
+
painter.end()
|
|
1087
|
+
return result
|
|
1088
|
+
|
|
1089
|
+
def _draw_status_dot(self, pixmap: QPixmap, state: str) -> None:
|
|
1090
|
+
dot = QColor(_STATE_COLORS.get(state, _STATE_COLORS["running"]))
|
|
1091
|
+
ring = QColor(self._colors()["bg"])
|
|
1092
|
+
painter = QPainter(pixmap)
|
|
1093
|
+
painter.setRenderHint(QPainter.Antialiasing)
|
|
1094
|
+
painter.setPen(QPen(ring, 3))
|
|
1095
|
+
painter.setBrush(dot)
|
|
1096
|
+
painter.drawEllipse(QRectF(43, 43, 17, 17))
|
|
1097
|
+
painter.end()
|
|
1098
|
+
|
|
1099
|
+
def _make_deepseek_icon(self, state: str) -> QIcon:
|
|
1100
|
+
mask = self._whale_pixmap()
|
|
1101
|
+
if mask is None:
|
|
1102
|
+
return self._make_classic_icon(state)
|
|
1103
|
+
size = 64
|
|
1104
|
+
canvas = QPixmap(size, size)
|
|
1105
|
+
canvas.fill(Qt.transparent)
|
|
1106
|
+
painter = QPainter(canvas)
|
|
1107
|
+
painter.setRenderHint(QPainter.SmoothPixmapTransform)
|
|
1108
|
+
scaled = mask.scaled(58, 58, Qt.KeepAspectRatio, Qt.SmoothTransformation)
|
|
1109
|
+
painter.drawPixmap((size - scaled.width()) // 2, (size - scaled.height()) // 2, scaled)
|
|
1110
|
+
painter.end()
|
|
1111
|
+
# The bundled asset is a white alpha mask, tinted with the current
|
|
1112
|
+
# theme text colour so it stays visible on both light and dark panels.
|
|
1113
|
+
tinted = self._tint_pixmap(canvas, QColor(self._colors()["text"]))
|
|
1114
|
+
self._draw_status_dot(tinted, state)
|
|
1115
|
+
icon = QIcon()
|
|
1116
|
+
icon.addPixmap(tinted, QIcon.Normal)
|
|
1117
|
+
icon.addPixmap(tinted, QIcon.Active)
|
|
1118
|
+
icon.addPixmap(tinted, QIcon.Selected)
|
|
1119
|
+
return icon
|
|
1120
|
+
|
|
1121
|
+
def _make_custom_icon(self, state: str) -> QIcon | None:
|
|
1122
|
+
path = self.custom_icon_path
|
|
1123
|
+
try:
|
|
1124
|
+
if not path or not path.is_file():
|
|
1125
|
+
return None
|
|
1126
|
+
source = QPixmap(str(path))
|
|
1127
|
+
except Exception:
|
|
1128
|
+
source = QPixmap()
|
|
1129
|
+
if source.isNull():
|
|
1130
|
+
if not self._custom_icon_fallback_logged:
|
|
1131
|
+
self._custom_icon_fallback_logged = True
|
|
1132
|
+
log(f"custom tray icon is not readable: {path}; using DeepSeek icon")
|
|
1133
|
+
return None
|
|
1134
|
+
size = 64
|
|
1135
|
+
canvas = QPixmap(size, size)
|
|
1136
|
+
canvas.fill(Qt.transparent)
|
|
1137
|
+
painter = QPainter(canvas)
|
|
1138
|
+
painter.setRenderHint(QPainter.SmoothPixmapTransform)
|
|
1139
|
+
scaled = source.scaled(58, 58, Qt.KeepAspectRatio, Qt.SmoothTransformation)
|
|
1140
|
+
painter.drawPixmap((size - scaled.width()) // 2, (size - scaled.height()) // 2, scaled)
|
|
1141
|
+
painter.end()
|
|
1142
|
+
self._draw_status_dot(canvas, state)
|
|
1143
|
+
icon = QIcon()
|
|
1144
|
+
icon.addPixmap(canvas, QIcon.Normal)
|
|
1145
|
+
icon.addPixmap(canvas, QIcon.Active)
|
|
1146
|
+
icon.addPixmap(canvas, QIcon.Selected)
|
|
1147
|
+
return icon
|
|
1148
|
+
|
|
1149
|
+
def _make_classic_icon(self, state: str) -> QIcon:
|
|
829
1150
|
pixmap = QPixmap(64, 64)
|
|
830
1151
|
pixmap.fill(Qt.transparent)
|
|
831
1152
|
painter = QPainter(pixmap)
|
|
@@ -859,7 +1180,10 @@ for (var pi = 0; pi < ps.length; pi++) {
|
|
|
859
1180
|
if self.job and self.job.get("active"):
|
|
860
1181
|
lines.append(f"更新中 · {self.job.get('percent', 0)}%")
|
|
861
1182
|
elif isinstance(self.update, dict) and self.update.get("updateAvailable"):
|
|
862
|
-
|
|
1183
|
+
if self._update_deferred():
|
|
1184
|
+
lines.append(f"可更新到 {self.update.get('candidate')}(已推迟到 {self._defer_time_text()})")
|
|
1185
|
+
else:
|
|
1186
|
+
lines.append(f"可更新到 {self.update.get('candidate')}")
|
|
863
1187
|
lines.append("左键打开 · 右键菜单")
|
|
864
1188
|
return "\n".join(lines)
|
|
865
1189
|
|
|
@@ -895,7 +1219,10 @@ for (var pi = 0; pi < ps.length; pi++) {
|
|
|
895
1219
|
self.update_action.setText(f"正在更新 {self.job.get('percent', 0)}%")
|
|
896
1220
|
self.update_action.setEnabled(False)
|
|
897
1221
|
elif isinstance(self.update, dict) and self.update.get("updateAvailable"):
|
|
898
|
-
|
|
1222
|
+
if self._update_deferred():
|
|
1223
|
+
self.update_action.setText(f"更新到 {self.update.get('candidate')}({self._defer_time_text()} 再提醒)")
|
|
1224
|
+
else:
|
|
1225
|
+
self.update_action.setText(f"更新到 {self.update.get('candidate')}")
|
|
899
1226
|
self.update_action.setEnabled(True)
|
|
900
1227
|
elif self.check_result:
|
|
901
1228
|
self.update_action.setText(self.check_result)
|
|
@@ -906,8 +1233,9 @@ for (var pi = 0; pi < ps.length; pi++) {
|
|
|
906
1233
|
|
|
907
1234
|
self.status_action.setIcon(self._status_icon())
|
|
908
1235
|
self.restart_action.setText("重启服务" if running else "启动服务")
|
|
909
|
-
|
|
910
|
-
self.
|
|
1236
|
+
# Navigation stays available while stopped: it launches/focuses the app.
|
|
1237
|
+
self.plugins_action.setEnabled(True)
|
|
1238
|
+
self.settings_action.setEnabled(True)
|
|
911
1239
|
self.stop_action.setEnabled(running)
|
|
912
1240
|
self.copy_action.setEnabled(running)
|
|
913
1241
|
self.logs_action.setEnabled(True)
|
|
@@ -932,6 +1260,15 @@ def run_check() -> int:
|
|
|
932
1260
|
def main() -> int:
|
|
933
1261
|
if "--check" in sys.argv:
|
|
934
1262
|
return run_check()
|
|
1263
|
+
# A fresh tray is only needed when this user has no other tray helper.
|
|
1264
|
+
# Checking before the lock/pid means a duplicate exits without touching
|
|
1265
|
+
# tray.pid, so the host never sees a stale or foreign pid.
|
|
1266
|
+
others = find_other_tray_processes()
|
|
1267
|
+
if others:
|
|
1268
|
+
message = "dsh-tray is already running (pid {})".format(", ".join(str(pid) for pid in sorted(others)))
|
|
1269
|
+
log(message)
|
|
1270
|
+
print(message, file=sys.stderr)
|
|
1271
|
+
return 0
|
|
935
1272
|
STATE_DIR.mkdir(parents=True, exist_ok=True, mode=0o700)
|
|
936
1273
|
lock = open(LOCK_FILE, "w", encoding="utf-8")
|
|
937
1274
|
try:
|