mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
runner: periodically check if there's a new version available on github and offer a visit
This commit is contained in:
committed by
Andrey Nekrasov
parent
c543b7585a
commit
0016836022
@@ -107,6 +107,7 @@
|
||||
<ClInclude Include="dpi_aware.h" />
|
||||
<ClInclude Include="com_object_factory.h" />
|
||||
<ClInclude Include="notifications.h" />
|
||||
<ClInclude Include="timeutil.h" />
|
||||
<ClInclude Include="window_helpers.h" />
|
||||
<ClInclude Include="icon_helpers.h" />
|
||||
<ClInclude Include="json.h" />
|
||||
|
||||
@@ -90,6 +90,9 @@
|
||||
<ClInclude Include="com_object_factory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="timeutil.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="d2d_svg.cpp">
|
||||
@@ -148,4 +151,4 @@
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -3,15 +3,21 @@
|
||||
|
||||
#include <msi.h>
|
||||
#include <common/common.h>
|
||||
#include <common/json.h>
|
||||
|
||||
#include <common/winstore.h>
|
||||
#include <common/notifications.h>
|
||||
#include <MsiQuery.h>
|
||||
|
||||
#include <winrt/Windows.Web.Http.h>
|
||||
#include <winrt/Windows.Web.Http.Headers.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
const wchar_t* POWER_TOYS_UPGRADE_CODE = L"{42B84BF7-5FBF-473B-9C8B-049DC16F7708}";
|
||||
const wchar_t* DONT_SHOW_AGAIN_RECORD_REGISTRY_PATH = L"delete_previous_powertoys_confirm";
|
||||
const wchar_t* USER_AGENT = L"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)";
|
||||
const wchar_t* LATEST_RELEASE_ENDPOINT = L"https://api.github.com/repos/microsoft/PowerToys/releases/latest";
|
||||
}
|
||||
|
||||
namespace localized_strings
|
||||
@@ -82,3 +88,32 @@ bool uninstall_msi_version(const std::wstring& package_path)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::future<std::optional<new_version_download_info>> check_for_new_github_release_async()
|
||||
{
|
||||
try
|
||||
{
|
||||
winrt::Windows::Web::Http::HttpClient client;
|
||||
auto headers = client.DefaultRequestHeaders();
|
||||
headers.UserAgent().TryParseAdd(USER_AGENT);
|
||||
|
||||
auto response = co_await client.GetAsync(winrt::Windows::Foundation::Uri{ LATEST_RELEASE_ENDPOINT });
|
||||
(void)response.EnsureSuccessStatusCode();
|
||||
const auto body = co_await response.Content().ReadAsStringAsync();
|
||||
auto json_body = json::JsonValue::Parse(body).GetObjectW();
|
||||
auto new_version = json_body.GetNamedString(L"tag_name");
|
||||
winrt::Windows::Foundation::Uri release_page_uri{ json_body.GetNamedString(L"html_url") };
|
||||
|
||||
const auto current_version = get_product_version();
|
||||
if (new_version == current_version)
|
||||
{
|
||||
co_return std::nullopt;
|
||||
}
|
||||
|
||||
co_return new_version_download_info{ std::move(release_page_uri), new_version.c_str() };
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
co_return std::nullopt;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,17 @@
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <future>
|
||||
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
|
||||
std::wstring get_msi_package_path();
|
||||
bool uninstall_msi_version(const std::wstring& package_path);
|
||||
bool offer_msi_uninstallation();
|
||||
bool offer_msi_uninstallation();
|
||||
|
||||
struct new_version_download_info
|
||||
{
|
||||
winrt::Windows::Foundation::Uri release_page_uri;
|
||||
std::wstring version_string;
|
||||
};
|
||||
std::future<std::optional<new_version_download_info>> check_for_new_github_release_async();
|
||||
|
||||
@@ -97,6 +97,7 @@
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<AdditionalOptions>/await %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
@@ -134,6 +135,7 @@
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<AdditionalOptions>/await %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
namespace PTSettingsHelper {
|
||||
|
||||
std::wstring get_module_save_folder_location(std::wstring_view powertoy_name);
|
||||
std::wstring get_root_save_folder_location();
|
||||
|
||||
void save_module_settings(std::wstring_view powertoy_name, json::JsonObject& settings);
|
||||
json::JsonObject load_module_settings(std::wstring_view powertoy_name);
|
||||
|
||||
57
src/common/timeutil.h
Normal file
57
src/common/timeutil.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <ctime>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
|
||||
#include <winrt/base.h>
|
||||
|
||||
namespace timeutil
|
||||
{
|
||||
inline std::wstring to_string(const time_t time)
|
||||
{
|
||||
return std::to_wstring(static_cast<uint64_t>(time));
|
||||
}
|
||||
|
||||
inline std::optional<std::time_t> from_string(const std::wstring& s)
|
||||
{
|
||||
try
|
||||
{
|
||||
uint64_t i = std::stoull(s);
|
||||
return static_cast<std::time_t>(i);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
inline std::time_t now()
|
||||
{
|
||||
return winrt::clock::to_time_t(winrt::clock::now());
|
||||
}
|
||||
|
||||
namespace diff
|
||||
{
|
||||
inline int64_t in_seconds(const std::time_t to, const std::time_t from)
|
||||
{
|
||||
return static_cast<int64_t>(std::difftime(to, from));
|
||||
}
|
||||
|
||||
inline int64_t in_minutes(const std::time_t to, const std::time_t from)
|
||||
{
|
||||
return static_cast<int64_t>(std::difftime(to, from) / 60);
|
||||
}
|
||||
|
||||
inline int64_t in_hours(const std::time_t to, const std::time_t from)
|
||||
{
|
||||
return static_cast<int64_t>(std::difftime(to, from) / 3600);
|
||||
}
|
||||
|
||||
inline int64_t in_days(const std::time_t to, const std::time_t from)
|
||||
{
|
||||
return static_cast<int64_t>(std::difftime(to, from) / (3600 * 24));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user