anotherim-desktop/plugins/windows-notification/api/src/win32.cpp

64 lines
1.5 KiB
C++
Raw Normal View History

2021-03-26 11:22:55 +00:00
#include <windows.h>
#include <shlobj.h>
#include "win32.hpp"
#include "converter.hpp"
#include "ginvoke.hpp"
2021-03-26 11:22:55 +00:00
std::optional<std::wstring> GetCurrentModulePath()
{
2021-02-22 09:18:53 +00:00
std::wstring exePath(MAX_PATH, 0);
2021-03-26 11:22:55 +00:00
auto charWritten = GetModuleFileName(nullptr, exePath.data(), exePath.size());
if (charWritten > 0)
{
2021-02-23 10:04:43 +00:00
exePath.resize(charWritten);
2021-02-22 09:18:53 +00:00
return exePath;
2021-03-26 11:22:55 +00:00
}
return std::nullopt;
}
std::optional<std::wstring> GetShortcutPath()
{
2021-02-22 09:18:53 +00:00
std::wstring shortcutPath(MAX_PATH, 0);
2021-03-26 11:22:55 +00:00
auto charWritten = GetEnvironmentVariable(L"APPDATA", shortcutPath.data(), shortcutPath.size());
if (charWritten > 0)
{
2021-02-23 10:04:43 +00:00
shortcutPath.resize(charWritten);
2021-02-22 09:18:53 +00:00
return shortcutPath;
2021-03-26 11:22:55 +00:00
}
return std::nullopt;
}
bool SetAppModelIDInternal(const char *const aumid)
2021-03-26 11:22:55 +00:00
{
auto waumid = sview_to_wstr(aumid);
if (waumid.empty())
{
return false;
}
return SUCCEEDED(SetCurrentProcessExplicitAppUserModelID(waumid.c_str()));
2021-03-26 11:22:55 +00:00
}
extern "C"
{
// Not available in mingw headers, but linking works.
NTSTATUS NTAPI RtlGetVersion(PRTL_OSVERSIONINFOW);
gboolean SupportsModernNotifications() noexcept
2021-03-26 11:22:55 +00:00
{
RTL_OSVERSIONINFOW rovi = { 0 };
rovi.dwOSVersionInfoSize = sizeof(rovi);
if (S_OK == RtlGetVersion(&rovi))
{
return rovi.dwMajorVersion > 6;
}
return FALSE;
}
gboolean SetAppModelID(const gchar* aumid) noexcept
2021-03-26 11:22:55 +00:00
{
return g_try_invoke(SetAppModelIDInternal, aumid);
2021-03-26 11:22:55 +00:00
}
}