A new style desktop shell for Windows 11: menu bar, Dock, Finder, Spotlight, Control Center and Liquid Glass, in native C++.
Rust
Notifications: clicking a Thunderbird/Firefox notification opens the app
Eternity07062857526893b952
diff --git a/src/shell/notificacoes.cpp b/src/shell/notificacoes.cppindex ca1f980..7d8071d 100644--- a/src/shell/notificacoes.cpp+++ b/src/shell/notificacoes.cpp@@ -19,6 +19,9 @@#include <wincodec.h>#include <shcore.h>#include <shlobj.h>+#include <shobjidl.h>+#include <propkey.h>+#include <cwctype>#include <ctime>#include <DispatcherQueue.h>#include <winrt/Windows.Foundation.h>@@ -1297,14 +1300,97 @@ void Frame() {if (!busy && !slideBusy) { ui::FrameClock(g_wnd, WM_NC_FRAME, false); KillTimer(g_wnd, T_ANIM); g_running = false; }}+// apps de desktop que mandam notificação com um AUMID só para os avisos (Thunderbird/Firefox:+// "ThunderbirdToast-D78BF5DD33499EC2", registrado em HKCU\Software\Classes\AppUserModelId com um ativador COM). Esse+// AUMID não existe no shell:AppsFolder (lá o app é "D78BF5DD33499EC2", nome "Thunderbird"; o aviso diz "Mozilla+// Thunderbird"): abrir "shell:AppsFolder\<AUMID do aviso>" dava a janela de erro "O Windows não pode encontrar...".+// Aqui o aviso é ligado ao app de verdade da pasta Aplicativos: pelo fim do AUMID ou pelo nome. "" = nenhum.+static bool NoAppsFolder(const std::wstring& parsing) {+ IShellItem* si = nullptr;+ if (parsing.empty() || FAILED(SHCreateItemFromParsingName((L"shell:AppsFolder\\" + parsing).c_str(), nullptr, IID_PPV_ARGS(&si)))) return false;+ si->Release();+ return true;+}+static std::wstring NomeRegistrado(const std::wstring& aumid) { // DisplayName do AUMID (HKCU, senão HKLM)+ std::wstring k = L"Software\\Classes\\AppUserModelId\\" + aumid;+ for (HKEY raiz : { HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE }) {+ wchar_t b[512] = {}; DWORD cb = sizeof(b);+ if (RegGetValueW(raiz, k.c_str(), L"DisplayName", RRF_RT_REG_SZ, nullptr, b, &cb) == ERROR_SUCCESS && b[0]) return b;+ }+ return L"";+}+static std::wstring AppDoAviso(const Note& n) {+ if (NoAppsFolder(n.aumid)) return n.aumid;+ std::vector<std::wstring> nomes = { n.app, NomeRegistrado(n.aumid) };+ auto lower = [](std::wstring s) { for (auto& c : s) c = (wchar_t)towlower(c); return s; };+ std::wstring aumidL = lower(n.aumid);+ auto contemPalavra = [&](const std::wstring& todo, const std::wstring& parte) { // "mozilla thunderbird" ⊃ "thunderbird"+ if (parte.size() < 4) return false;+ for (size_t p = todo.find(parte); p != std::wstring::npos; p = todo.find(parte, p + 1)) {+ bool ini = p == 0 || !iswalnum(todo[p - 1]), fim = p + parte.size() == todo.size() || !iswalnum(todo[p + parte.size()]);+ if (ini && fim) return true;+ }+ return false;+ };+ std::wstring melhor; int nota = 0;+ IShellItem* pasta = nullptr; IEnumShellItems* en = nullptr;+ if (SUCCEEDED(SHCreateItemFromParsingName(L"shell:AppsFolder", nullptr, IID_PPV_ARGS(&pasta)))) {+ if (SUCCEEDED(pasta->BindToHandler(nullptr, BHID_EnumItems, IID_PPV_ARGS(&en)))) {+ IShellItem* it = nullptr;+ while (nota < 3 && en->Next(1, &it, nullptr) == S_OK) {+ PWSTR pp = nullptr, pn = nullptr;+ it->GetDisplayName(SIGDN_PARENTRELATIVEPARSING, &pp);+ it->GetDisplayName(SIGDN_NORMALDISPLAY, &pn);+ std::wstring parsing = pp ? pp : L"", nome = lower(pn ? pn : L"");+ CoTaskMemFree(pp); CoTaskMemFree(pn);+ it->Release();+ if (parsing.empty()) continue;+ std::wstring pl = lower(parsing);+ int v = 0;+ if (pl.size() >= 4 && aumidL.size() > pl.size() && aumidL.compare(aumidL.size() - pl.size(), pl.size(), pl) == 0 &&+ wcschr(L"-_.!", aumidL[aumidL.size() - pl.size() - 1]))+ v = 3; // "ThunderbirdToast-D78BF5DD33499EC2" termina com o AUMID do app+ for (auto& nm : nomes) {+ std::wstring l = lower(nm);+ if (l.empty()) continue;+ if (l == nome) v = std::max(v, 2);+ else if (contemPalavra(l, nome) || contemPalavra(nome, l)) v = std::max(v, 1);+ }+ if (v > nota) { nota = v; melhor = parsing; }+ }+ en->Release();+ }+ pasta->Release();+ }+ return melhor;+}+static std::wstring ExeDoItem(const std::wstring& parsing) { // o .exe por trás do item (minúsculas), "" se não souber+ IShellItem2* si = nullptr; std::wstring r;+ if (SUCCEEDED(SHCreateItemFromParsingName((L"shell:AppsFolder\\" + parsing).c_str(), nullptr, IID_PPV_ARGS(&si)))) {+ PWSTR p = nullptr;+ if (SUCCEEDED(si->GetString(PKEY_Link_TargetParsingPath, &p)) && p) { r = p; CoTaskMemFree(p); }+ si->Release();+ }+ for (auto& c : r) c = (wchar_t)towlower(c);+ return r;+}+void OpenApp(const Note& n) {if (n.aumid == L"WacOS.Atualizacao") { shell::OpenSettings(L"atualizacao"); return; } // atualizacao.cppfor (auto& a : apps::list)if (!a.wins.empty() && (!_wcsicmp(a.id.c_str(), (L"aumid:" + n.aumid).c_str()) || !_wcsicmp(a.name.c_str(), n.app.c_str()))) { apps::Activate(a); return; }for (auto& a : apps::list)if (!_wcsicmp(a.name.c_str(), n.app.c_str())) { apps::Launch(a); return; }- if (!apps::ActivatePackaged(L"shell:AppsFolder\\" + n.aumid))- shell::Abrir(L"open", (L"shell:AppsFolder\\" + n.aumid).c_str(), nullptr, nullptr, SW_SHOWNORMAL);+ std::wstring alvo = AppDoAviso(n);+ if (alvo.empty()) { Log(L"notificação: app de %ls (%ls) não achado na pasta Aplicativos; nada aberto", n.app.c_str(), n.aumid.c_str()); return; }+ if (alvo != n.aumid) {+ Log(L"notificação: %ls -> app %ls", n.aumid.c_str(), alvo.c_str());+ std::wstring exe = ExeDoItem(alvo);+ for (auto& a : apps::list) // o app já está aberto: traz as janelas+ if (!a.wins.empty() && (!_wcsicmp(a.id.c_str(), (L"aumid:" + alvo).c_str()) || (!exe.empty() && !_wcsicmp(a.exe.c_str(), exe.c_str())))) { apps::Activate(a); return; }+ }+ if (!apps::ActivatePackaged(L"shell:AppsFolder\\" + alvo))+ shell::Abrir(L"open", (L"shell:AppsFolder\\" + alvo).c_str(), nullptr, nullptr, SW_SHOWNORMAL);}void ClearGroup(int gi) {