Release KSwitcher v0.6.73 with autostart path repair

This commit is contained in:
agrynco committed 2026-11-13 10:28:41 +02:00
1 parent 3117b2d9c8
commit 3bcbfeee15
13 files changed
+265 -63

No files matched your search

+57
View File
@@ -12,6 +12,7 @@
#include <algorithm>
#include <commctrl.h>
#include <set>
#include <shlobj.h>
#include <wrl/client.h>
namespace ks
@@ -23,6 +24,7 @@ namespace
{
constexpr UINT SnippetPopupMessage = WM_APP + 81;
constexpr UINT SnippetCaretMessage = WM_APP + 82;
constexpr UINT CheckAutostartMessage = WM_APP + 83;
constexpr UINT_PTR SnippetPopupTimer = 21;
constexpr size_t SnippetVisibleRows = 7;
constexpr wchar_t SnippetPopupClass[] = L"KSwitcher.SnippetSuggestions";
@@ -857,6 +859,56 @@ Bytes App::lanCommand(const Bytes &command)
void App::applySettings(const Settings &requested)
{
applySettings(requested, true);
if (settings.autostart && !smoke && !isLocalBuild())
PostMessageW(window, CheckAutostartMessage, 0, 0);
}
void App::checkAutostartPath()
{
if (checkingAutostartPath || !settings.autostart || installingUpdate)
return;
checkingAutostartPath = true;
try
{
const bool elevated = settings.elevatedAutostart;
const auto oldPath = staleAutostartPath(elevated);
if (!oldPath.empty())
{
const auto attributes = GetFileAttributesW(oldPath.c_str());
const auto error = attributes == INVALID_FILE_ATTRIBUTES ? GetLastError() : ERROR_SUCCESS;
const bool missingFile = error == ERROR_FILE_NOT_FOUND || error == ERROR_PATH_NOT_FOUND;
const bool needsApproval = elevated && !IsUserAnAdmin();
bool approved = missingFile && !needsApproval;
if (!approved)
{
const auto text = L"Registered path:\n" + oldPath + L"\n\nCurrent path:\n" + executable() +
(needsApproval ? L"\n\nWindows will ask for administrator approval." : L"");
const TASKDIALOG_BUTTON update{IDYES, L"Update autostart path"};
TASKDIALOGCONFIG dialog{sizeof(dialog)};
dialog.dwFlags = TDF_ALLOW_DIALOG_CANCELLATION;
dialog.dwCommonButtons = TDCBF_CANCEL_BUTTON;
dialog.pszWindowTitle = L"KSwitcher";
dialog.pszMainInstruction = L"Windows autostart points to a different copy of KSwitcher";
dialog.pszContent = text.c_str();
dialog.cButtons = 1;
dialog.pButtons = &update;
dialog.nDefaultButton = IDCANCEL;
int button{};
approved = SUCCEEDED(TaskDialogIndirect(&dialog, &button, nullptr, nullptr)) && button == IDYES;
}
if (approved && settings.autostart && settings.elevatedAutostart == elevated &&
!installingUpdate && staleAutostartPath(elevated) == oldPath)
{
repairAutostartPath(elevated);
log(L"Updated Windows autostart path to " + executable());
}
}
}
catch (const std::exception &e)
{
report(L"Windows autostart: " + wide(e.what()));
}
checkingAutostartPath = false;
}
void App::applySettings(const Settings &requested, bool validateOcrInstallation)
{
@@ -3008,6 +3060,9 @@ LRESULT CALLBACK App::windowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
Shell_NotifyIconW(NIM_MODIFY, &icon);
return 0;
}
case CheckAutostartMessage:
app->checkAutostartPath();
return 0;
case WM_COPYDATA:
{
auto *data = (COPYDATASTRUCT *)lp;
@@ -3238,6 +3293,8 @@ int App::execute()
log(std::wstring(L"Update completed; running version ") + AppVersion);
if (startCommand)
PostMessageW(window, WM_HOTKEY, startCommand, 0);
if (!smoke && !isLocalBuild() && settings.autostart)
PostMessageW(window, CheckAutostartMessage, 0, 0);
try { notificationRegistration = startScreenshotNotificationRegistration(); }
catch(const std::exception &e) { log(L"Screenshot notification registration: "+wide(e.what())); }
auto screenshotActivation=startScreenshotActivationListener();