| 1359 | } |
| 1360 | |
| 1361 | void TaskbarAttributeWorker::ResetState(bool manual) |
| 1362 | { |
| 1363 | if (!m_ResettingState) |
| 1364 | { |
| 1365 | MessagePrint(spdlog::level::debug, L"Resetting worker state"); |
| 1366 | |
| 1367 | m_ResettingState = true; |
| 1368 | m_ResetStateReentered = false; |
| 1369 | auto guard = wil::scope_exit([this] |
| 1370 | { |
| 1371 | m_ResettingState = false; |
| 1372 | m_ResetStateReentered = false; |
| 1373 | }); |
| 1374 | |
| 1375 | // Clear state |
| 1376 | m_PowerSaver = false; |
| 1377 | m_PeekActive = false; |
| 1378 | m_TaskViewActive = false; |
| 1379 | m_CurrentStartMonitor = nullptr; |
| 1380 | m_CurrentSearchMonitor = nullptr; |
| 1381 | m_CurrentFindInStartMonitor = nullptr; |
| 1382 | m_ForegroundWindow = Window::NullWindow; |
| 1383 | |
| 1384 | m_Taskbars.clear(); |
| 1385 | m_NormalTaskbars.clear(); |
| 1386 | |
| 1387 | m_TaskbarService = nullptr; |
| 1388 | |
| 1389 | // Keep old hooks alive while we rehook to avoid DLL unload. |
| 1390 | auto oldHooks = std::move(m_Hooks); |
| 1391 | m_Hooks.clear(); |
| 1392 | |
| 1393 | for (const Window main_taskbar : Window::FindEnum(TASKBAR)) |
| 1394 | { |
| 1395 | if (main_taskbar.file().value_or({}).filename() == L"explorer.exe") |
| 1396 | { |
| 1397 | const auto pid = main_taskbar.process_id(); |
| 1398 | if (!manual) |
| 1399 | { |
| 1400 | if (m_LastExplorerPid != 0 && pid != m_LastExplorerPid) |
| 1401 | { |
| 1402 | const auto now = std::chrono::steady_clock::now(); |
| 1403 | if (now < m_LastExplorerRestart + std::chrono::seconds(30)) [[unlikely]] |
| 1404 | { |
| 1405 | Localization::ShowLocalizedMessageBox(IDS_EXPLORER_RESTARTED_TOO_MUCH, MB_OK | MB_ICONWARNING | MB_SETFOREGROUND, hinstance()).join(); |
| 1406 | ExitProcess(1); |
| 1407 | } |
| 1408 | |
| 1409 | m_LastExplorerRestart = now; |
| 1410 | } |
| 1411 | } |
| 1412 | |
| 1413 | m_LastExplorerPid = pid; |
| 1414 | |
| 1415 | m_TaskbarType = GetTaskbarType(main_taskbar); |
| 1416 | |
| 1417 | if (m_TaskbarType == TaskbarType::XAML) |
| 1418 | { |
no test coverage detected