Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(windows): announce the Start-Menu entry so app search can find it

Haraldd37b04f79b97
diff --git a/jarvis/ui/icon_utils.py b/jarvis/ui/icon_utils.py
index a9bdc479a2..cf7567b59e 100644
--- a/jarvis/ui/icon_utils.py
+++ b/jarvis/ui/icon_utils.py
@@ -690,6 +690,7 @@ def ensure_start_menu_shortcut(
)
rw_store.SetValue(pscon.PKEY_AppUserModel_ID, propsys.PROPVARIANTType(aumid))
rw_store.Commit()
+ _notify_shell_of_shortcut(lnk)
logger.debug("Start-Menu shortcut ensured: {}", lnk)
return True
except Exception as exc: # noqa: BLE001
@@ -697,6 +698,39 @@ def ensure_start_menu_shortcut(
return False
+def _notify_shell_of_shortcut(lnk: Path) -> None:
+ """Tell the shell the Start-Menu entry changed, so app search can pick it up.
+
+ Writing the .lnk is only half the job. Windows answers Start-menu searches
+ from its own app index (``shell:AppsFolder``), not by reading the folder, and
+ that index is refreshed from shell change notifications. We finish the file
+ with an ``IPropertyStore`` commit *after* ``Save()`` — a plain write the
+ shell is never told about — so nothing announces the final version.
+
+ ``SHChangeNotify`` is the documented announcement: the item itself, then its
+ directory. Best-effort by design; it only ever makes the entry appear
+ SOONER. A machine whose app index has stopped accepting new entries
+ altogether is a shell-side fault this cannot repair (verified 2026-08-16:
+ on such a machine a plain ``notepad.exe`` shortcut is refused just the same)
+ — there the fix is restarting Explorer or signing back in.
+ """
+ if sys.platform != "win32":
+ return
+ try:
+ import ctypes
+
+ SHCNE_CREATE, SHCNE_UPDATEDIR, SHCNF_PATHW = 0x0002, 0x1000, 0x0005
+ shell32 = ctypes.windll.shell32
+ shell32.SHChangeNotify(
+ SHCNE_CREATE, SHCNF_PATHW, ctypes.c_wchar_p(str(lnk)), None
+ )
+ shell32.SHChangeNotify(
+ SHCNE_UPDATEDIR, SHCNF_PATHW, ctypes.c_wchar_p(str(lnk.parent)), None
+ )
+ except Exception as exc: # noqa: BLE001 — a nicety, never load-bearing
+ logger.debug("shell change notification skipped: {}", exc)
+
+
def ensure_windows_app_identity(
app_id: str = APP_USER_MODEL_ID, *, write_shortcut: bool = True
) -> bool:
diff --git a/tests/unit/ui/test_start_menu_shortcut_target.py b/tests/unit/ui/test_start_menu_shortcut_target.py
index c0dc9017d7..e35be61891 100644
--- a/tests/unit/ui/test_start_menu_shortcut_target.py
+++ b/tests/unit/ui/test_start_menu_shortcut_target.py
@@ -128,6 +128,61 @@ class TestShortcutWriterRefusesADeadTarget:
assert sc.Arguments.strip() == f"-m {icon_utils._LAUNCHER_MODULE}"
+class TestShellIsToldAboutTheEntry:
+ """Writing the file is half the job — the app index needs the notification.
+
+ Windows answers Start-menu searches from `shell:AppsFolder`, refreshed from
+ shell change notifications. The .lnk is finished by an IPropertyStore commit
+ *after* Save(), which announces nothing, so without this the entry can sit
+ on disk unindexed.
+ """
+
+ def test_writer_announces_the_entry(self) -> None:
+ import inspect
+
+ src = inspect.getsource(icon_utils.ensure_start_menu_shortcut)
+ assert "_notify_shell_of_shortcut(lnk)" in src
+ # …after the property-store commit, which is the last write to the file.
+ assert src.index("rw_store.Commit()") < src.index("_notify_shell_of_shortcut")
+
+ def test_is_a_noop_off_windows(self, monkeypatch: pytest.MonkeyPatch) -> None:
+ monkeypatch.setattr(icon_utils.sys, "platform", "linux")
+ icon_utils._notify_shell_of_shortcut(Path("/tmp/whatever.lnk"))
+
+ @windows_only
+ def test_notifies_the_item_and_its_directory(
+ self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ import ctypes
+
+ lnk = tmp_path / "Programs" / "Personal Jarvis.lnk"
+ calls: list[tuple[int, object]] = []
+ monkeypatch.setattr(
+ ctypes.windll.shell32,
+ "SHChangeNotify",
+ lambda event, flags, a, b: calls.append((event, a.value)),
+ raising=False,
+ )
+ icon_utils._notify_shell_of_shortcut(lnk)
+ events = [c[0] for c in calls]
+ assert events == [0x0002, 0x1000], "announce the item, then its folder"
+ assert calls[0][1] == str(lnk)
+ assert calls[1][1] == str(lnk.parent)
+
+ @windows_only
+ def test_never_raises(self, monkeypatch: pytest.MonkeyPatch) -> None:
+ """A failed notification must never take the shortcut write down."""
+ import ctypes
+
+ def _explode(*a: object) -> None:
+ raise OSError("shell is unavailable")
+
+ monkeypatch.setattr(
+ ctypes.windll.shell32, "SHChangeNotify", _explode, raising=False
+ )
+ icon_utils._notify_shell_of_shortcut(Path("C:/nope/x.lnk"))
+
+
@windows_only
class TestIdentityCallCanSkipTheShortcut:
def test_write_shortcut_false_writes_nothing(