diff --git a/PowerToys.sln b/PowerToys.sln index 85674fdf18..6b4e70c89a 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -152,6 +152,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Shell", "src\mod EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Folder", "src\modules\launcher\Plugins\Wox.Plugin.Folder\Wox.Plugin.Folder.csproj", "{787B8AA6-CA93-4C84-96FE-DF31110AD1C4}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Wox.Launcher", "src\modules\launcher\Wox.Launcher\Wox.Launcher.vcxproj", "{E364F67B-BB12-4E91-B639-355866EBCD8B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -370,6 +372,12 @@ Global {787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Release|Any CPU.Build.0 = Release|Any CPU {787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Release|x64.ActiveCfg = Release|Any CPU {787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Release|x64.Build.0 = Release|Any CPU + {E364F67B-BB12-4E91-B639-355866EBCD8B}.Debug|Any CPU.ActiveCfg = Debug|x64 + {E364F67B-BB12-4E91-B639-355866EBCD8B}.Debug|x64.ActiveCfg = Debug|x64 + {E364F67B-BB12-4E91-B639-355866EBCD8B}.Debug|x64.Build.0 = Debug|x64 + {E364F67B-BB12-4E91-B639-355866EBCD8B}.Release|Any CPU.ActiveCfg = Release|x64 + {E364F67B-BB12-4E91-B639-355866EBCD8B}.Release|x64.ActiveCfg = Release|x64 + {E364F67B-BB12-4E91-B639-355866EBCD8B}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -410,6 +418,7 @@ Global {FDB3555B-58EF-4AE6-B5F1-904719637AB4} = {4AFC9975-2456-4C70-94A4-84073C1CED93} {C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0} = {4AFC9975-2456-4C70-94A4-84073C1CED93} {787B8AA6-CA93-4C84-96FE-DF31110AD1C4} = {4AFC9975-2456-4C70-94A4-84073C1CED93} + {E364F67B-BB12-4E91-B639-355866EBCD8B} = {C140A3EF-6DBF-4084-9D4C-4EB5A99FEE68} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0} diff --git a/src/modules/launcher/Wox.Launcher/Wox.Launcher.rc b/src/modules/launcher/Wox.Launcher/Wox.Launcher.rc new file mode 100644 index 0000000000..ceb12a24d8 --- /dev/null +++ b/src/modules/launcher/Wox.Launcher/Wox.Launcher.rc @@ -0,0 +1,40 @@ +ÿþ#include "resource.h" + +STRINGTABLE +BEGIN + IDS_LAUNCHER_NAME L"Launcher" + IDS_LAUNCHER_SETTINGS_DESC L"<No description>" +END + +1 VERSIONINFO + FILEVERSION 0,1,0,0 + PRODUCTVERSION 0,1,0,0 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "Company Name" + VALUE "FileDescription", "Wox.Launcher Module" + VALUE "FileVersion", "0.1.0.0" + VALUE "InternalName", "Wox.Launcher" + VALUE "LegalCopyright", "Copyright (C) 2019 Company Name" + VALUE "OriginalFilename", "Wox.Launcher.dll" + VALUE "ProductName", "Wox.Launcher" + VALUE "ProductVersion", "0.1.0.0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END \ No newline at end of file diff --git a/src/modules/launcher/Wox.Launcher/Wox.Launcher.vcxproj b/src/modules/launcher/Wox.Launcher/Wox.Launcher.vcxproj new file mode 100644 index 0000000000..992ac59354 --- /dev/null +++ b/src/modules/launcher/Wox.Launcher/Wox.Launcher.vcxproj @@ -0,0 +1,123 @@ + + + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {e364f67b-bb12-4e91-b639-355866ebcd8b} + Win32Proj + Wox_Launcher + 10.0 + Wox.Launcher + + + + DynamicLibrary + true + v142 + Unicode + + + DynamicLibrary + false + v142 + true + Unicode + + + + + + + + + + + + + + + true + $(SolutionDir)$(Platform)\$(Configuration)\modules\ + + + false + $(SolutionDir)$(Platform)\$(Configuration)\modules\ + + + + Use + Level3 + Disabled + true + _DEBUG;EXAMPLEPOWERTOY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + pch.h + ..\..\..\common\inc;..\..\..\common\Telemetry;..\..\;..\..\..\;..\..\..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories) + MultiThreadedDebug + stdcpplatest + + + Windows + true + $(OutDir)$(TargetName)$(TargetExt) + + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;EXAMPLEPOWERTOY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + pch.h + ..\..\..\common\inc;..\..\..\common\Telemetry;..\..\;..\..\..\;..\..\..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories) + MultiThreaded + stdcpplatest + + + Windows + true + true + true + $(OutDir)$(TargetName)$(TargetExt) + + + + + + + + + + + Create + Create + pch.h + pch.h + + + + + + + + + {74485049-c722-400f-abe5-86ac52d929b3} + + + + + + \ No newline at end of file diff --git a/src/modules/launcher/Wox.Launcher/Wox.Launcher.vcxproj.filters b/src/modules/launcher/Wox.Launcher/Wox.Launcher.vcxproj.filters new file mode 100644 index 0000000000..da67056517 --- /dev/null +++ b/src/modules/launcher/Wox.Launcher/Wox.Launcher.vcxproj.filters @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/modules/launcher/Wox.Launcher/dllmain.cpp b/src/modules/launcher/Wox.Launcher/dllmain.cpp new file mode 100644 index 0000000000..d3ee29e670 --- /dev/null +++ b/src/modules/launcher/Wox.Launcher/dllmain.cpp @@ -0,0 +1,189 @@ +#include "pch.h" +#include +#include +#include +#include +#include "trace.h" +#include "resource.h" + +extern "C" IMAGE_DOS_HEADER __ImageBase; + +BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { + switch (ul_reason_for_call) { + case DLL_PROCESS_ATTACH: + Trace::RegisterProvider(); + break; + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + break; + case DLL_PROCESS_DETACH: + Trace::UnregisterProvider(); + break; + } + return TRUE; +} + + +// These are the properties shown in the Settings page. +struct ModuleSettings { +} g_settings; + +// Implement the PowerToy Module Interface and all the required methods. +class Wox_Launcher : public PowertoyModuleIface { +private: + // The PowerToy state. + bool m_enabled = false; + + // Load initial settings from the persisted values. + void init_settings(); + + // Handle to launch and terminate the launcher + HANDLE m_hProcess; + + //contains the name of the powerToys + std::wstring app_name; + +public: + // Constructor + Wox_Launcher() { + app_name = GET_RESOURCE_STRING(IDS_LAUNCHER_NAME); + init_settings(); + }; + + // Destroy the powertoy and free memory + virtual void destroy() override { + delete this; + } + + // Return the display name of the powertoy, this will be cached by the runner + virtual const wchar_t* get_name() override { + return app_name.c_str(); + } + + // Return array of the names of all events that this powertoy listens for, with + // nullptr as the last element of the array. Nullptr can also be retured for empty + // list. + virtual const wchar_t** get_events() override { + static const wchar_t* events[] = { nullptr }; + // Available events: + // - ll_keyboard + // - win_hook_event + // + // static const wchar_t* events[] = { ll_keyboard, + // win_hook_event, + // nullptr }; + + return events; + } + + // Return JSON with the configuration options. + virtual bool get_config(wchar_t* buffer, int* buffer_size) override { + HINSTANCE hinstance = reinterpret_cast(&__ImageBase); + + // Create a Settings object. + PowerToysSettings::Settings settings(hinstance, get_name()); + settings.set_description(GET_RESOURCE_STRING(IDS_LAUNCHER_SETTINGS_DESC)); + return settings.serialize_to_buffer(buffer, buffer_size); + } + + // Signal from the Settings editor to call a custom action. + // This can be used to spawn more complex editors. + virtual void call_custom_action(const wchar_t* action) override { + static UINT custom_action_num_calls = 0; + try { + // Parse the action values, including name. + PowerToysSettings::CustomActionObject action_object = + PowerToysSettings::CustomActionObject::from_json_string(action); + } + catch (std::exception ex) { + // Improper JSON. + } + } + + // Called by the runner to pass the updated settings values as a serialized JSON. + virtual void set_config(const wchar_t* config) override { + try { + // Parse the input JSON string. + PowerToysSettings::PowerToyValues values = + PowerToysSettings::PowerToyValues::from_json_string(config); + + // If you don't need to do any custom processing of the settings, proceed + // to persists the values calling: + values.save_to_settings_file(); + // Otherwise call a custom function to process the settings before saving them to disk: + // save_settings(); + } + catch (std::exception ex) { + // Improper JSON. + } + } + + // Enable the powertoy + virtual void enable() + { + SHELLEXECUTEINFO sei{ sizeof(sei) }; + sei.fMask = { SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI }; + sei.lpFile = L"modules\\launcher\\Wox.exe"; + sei.nShow = SW_SHOWNORMAL; + ShellExecuteEx(&sei); + + m_hProcess = sei.hProcess; + + m_enabled = true; + } + + // Disable the powertoy + virtual void disable() + { + if (m_enabled) + { + TerminateProcess(m_hProcess, 1); + } + + m_enabled = false; + } + + // Returns if the powertoys is enabled + virtual bool is_enabled() override { + return m_enabled; + } + + // Handle incoming event, data is event-specific + virtual intptr_t signal_event(const wchar_t* name, intptr_t data) override { + if (wcscmp(name, ll_keyboard) == 0) { + auto& event = *(reinterpret_cast(data)); + // Return 1 if the keypress is to be suppressed (not forwarded to Windows), + // otherwise return 0. + return 0; + } + else if (wcscmp(name, win_hook_event) == 0) { + auto& event = *(reinterpret_cast(data)); + // Return value is ignored + return 0; + } + return 0; + } + + /* Register helper class to handle system menu items related actions. */ + virtual void register_system_menu_helper(PowertoySystemMenuIface* helper) {} + /* Handle action on system menu item. */ + virtual void signal_system_menu_action(const wchar_t* name) {} +}; + +// Load the settings file. +void Wox_Launcher::init_settings() { + try { + // Load and parse the settings file for this PowerToy. + PowerToysSettings::PowerToyValues settings = + PowerToysSettings::PowerToyValues::load_from_settings_file(get_name()); + + } + catch (std::exception ex) { + // Error while loading from the settings file. Let default values stay as they are. + } +} + + +extern "C" __declspec(dllexport) PowertoyModuleIface* __cdecl powertoy_create() { + return new Wox_Launcher(); +} diff --git a/src/modules/launcher/Wox.Launcher/pch.cpp b/src/modules/launcher/Wox.Launcher/pch.cpp new file mode 100644 index 0000000000..a3d1ff4225 --- /dev/null +++ b/src/modules/launcher/Wox.Launcher/pch.cpp @@ -0,0 +1,3 @@ +#include "pch.h" +#pragma comment(lib, "windowsapp") +#pragma comment(lib, "shlwapi.lib") \ No newline at end of file diff --git a/src/modules/launcher/Wox.Launcher/pch.h b/src/modules/launcher/Wox.Launcher/pch.h new file mode 100644 index 0000000000..8cb4314b9c --- /dev/null +++ b/src/modules/launcher/Wox.Launcher/pch.h @@ -0,0 +1,7 @@ +#pragma once +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include \ No newline at end of file diff --git a/src/modules/launcher/Wox.Launcher/resource.h b/src/modules/launcher/Wox.Launcher/resource.h new file mode 100644 index 0000000000..aad6c4bbdc --- /dev/null +++ b/src/modules/launcher/Wox.Launcher/resource.h @@ -0,0 +1,2 @@ +#define IDS_LAUNCHER_NAME 601 +#define IDS_LAUNCHER_SETTINGS_DESC 602 diff --git a/src/modules/launcher/Wox.Launcher/trace.cpp b/src/modules/launcher/Wox.Launcher/trace.cpp new file mode 100644 index 0000000000..94ae6d8fd9 --- /dev/null +++ b/src/modules/launcher/Wox.Launcher/trace.cpp @@ -0,0 +1,26 @@ +#include "pch.h" +#include "trace.h" + +TRACELOGGING_DEFINE_PROVIDER( + g_hProvider, + "Microsoft.PowerToys", + // {38e8889b-9731-53f5-e901-e8a7c1753074} + (0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74), + TraceLoggingOptionProjectTelemetry()); + +void Trace::RegisterProvider() { + TraceLoggingRegister(g_hProvider); +} + +void Trace::UnregisterProvider() { + TraceLoggingUnregister(g_hProvider); +} + +void Trace::MyEvent() { + TraceLoggingWrite( + g_hProvider, + "PowerToyName::Event::MyEvent", + ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), + TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"), + TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE)); +} diff --git a/src/modules/launcher/Wox.Launcher/trace.h b/src/modules/launcher/Wox.Launcher/trace.h new file mode 100644 index 0000000000..92cef7fc80 --- /dev/null +++ b/src/modules/launcher/Wox.Launcher/trace.h @@ -0,0 +1,8 @@ +#pragma once + +class Trace { +public: + static void RegisterProvider(); + static void UnregisterProvider(); + static void MyEvent(); +}; diff --git a/src/runner/main.cpp b/src/runner/main.cpp index 8b0ac14f8f..c5aad127e2 100644 --- a/src/runner/main.cpp +++ b/src/runner/main.cpp @@ -175,7 +175,8 @@ int runner(bool isProcessElevated) std::unordered_set known_dlls = { L"shortcut_guide.dll", L"fancyzones.dll", - L"PowerRenameExt.dll" + L"PowerRenameExt.dll", + L"Wox.Launcher.dll" }; for (auto& file : std::filesystem::directory_iterator(L"modules/")) {