From f5dc197e8bb6d14c1b70bd110f28bad2521cbd7c Mon Sep 17 00:00:00 2001 From: stefansjfw <57057282+stefansjfw@users.noreply.github.com> Date: Thu, 4 Jun 2020 12:28:30 +0200 Subject: [PATCH] [example_powertoy] Remove example_powertoy (#3955) * Remove example_powertoy * Address PR comments --- PowerToys.sln | 12 +- doc/devdocs/modules/example_powertoy.md | 5 - doc/devdocs/modules/interface.md | 175 +-------- doc/devdocs/readme.md | 5 - .../example_settings.png} | Bin src/modules/example_powertoy/dllmain.cpp | 341 ------------------ .../example_powertoy/example_powertoy.rc | 34 -- .../example_powertoy/example_powertoy.vcxproj | 135 ------- .../example_powertoy.vcxproj.filters | 19 - src/modules/example_powertoy/packages.config | 4 - src/modules/example_powertoy/pch.cpp | 2 - src/modules/example_powertoy/pch.h | 6 - src/modules/example_powertoy/resource.h | 0 src/modules/example_powertoy/trace.cpp | 29 -- src/modules/example_powertoy/trace.h | 9 - .../interface/powertoy_module_interface.h | 2 +- tools/project_template/README.md | 11 +- 17 files changed, 11 insertions(+), 778 deletions(-) delete mode 100644 doc/devdocs/modules/example_powertoy.md rename doc/images/{example_powertoy/settings.png => settings/example_settings.png} (100%) delete mode 100644 src/modules/example_powertoy/dllmain.cpp delete mode 100644 src/modules/example_powertoy/example_powertoy.rc delete mode 100644 src/modules/example_powertoy/example_powertoy.vcxproj delete mode 100644 src/modules/example_powertoy/example_powertoy.vcxproj.filters delete mode 100644 src/modules/example_powertoy/packages.config delete mode 100644 src/modules/example_powertoy/pch.cpp delete mode 100644 src/modules/example_powertoy/pch.h delete mode 100644 src/modules/example_powertoy/resource.h delete mode 100644 src/modules/example_powertoy/trace.cpp delete mode 100644 src/modules/example_powertoy/trace.h diff --git a/PowerToys.sln b/PowerToys.sln index e66dc028e0..722bc3f73e 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -34,12 +34,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "runner", "src\runner\runner EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common", "src\common\common.vcxproj", "{74485049-C722-400F-ABE5-86AC52D929B3}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shortcut_guide", "src\modules\shortcut_guide\shortcut_guide.vcxproj", "{A46629C4-1A6C-40FA-A8B6-10E5102BB0BA}" - ProjectSection(ProjectDependencies) = postProject - {74485049-C722-400F-ABE5-86AC52D929B3} = {74485049-C722-400F-ABE5-86AC52D929B3} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_powertoy", "src\modules\example_powertoy\example_powertoy.vcxproj", "{44CC9375-3E6E-4D99-8913-7FB748807EBD}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ShortcutGuide", "src\modules\shortcut_guide\shortcut_guide.vcxproj", "{A46629C4-1A6C-40FA-A8B6-10E5102BB0BA}" ProjectSection(ProjectDependencies) = postProject {74485049-C722-400F-ABE5-86AC52D929B3} = {74485049-C722-400F-ABE5-86AC52D929B3} EndProjectSection @@ -275,10 +270,6 @@ Global {A46629C4-1A6C-40FA-A8B6-10E5102BB0BA}.Debug|x64.Build.0 = Debug|x64 {A46629C4-1A6C-40FA-A8B6-10E5102BB0BA}.Release|x64.ActiveCfg = Release|x64 {A46629C4-1A6C-40FA-A8B6-10E5102BB0BA}.Release|x64.Build.0 = Release|x64 - {44CC9375-3E6E-4D99-8913-7FB748807EBD}.Debug|x64.ActiveCfg = Debug|x64 - {44CC9375-3E6E-4D99-8913-7FB748807EBD}.Debug|x64.Build.0 = Debug|x64 - {44CC9375-3E6E-4D99-8913-7FB748807EBD}.Release|x64.ActiveCfg = Release|x64 - {44CC9375-3E6E-4D99-8913-7FB748807EBD}.Release|x64.Build.0 = Release|x64 {07C389E3-6BC8-41CF-923E-307B1265FA2D}.Debug|x64.ActiveCfg = Debug|x64 {07C389E3-6BC8-41CF-923E-307B1265FA2D}.Debug|x64.Build.0 = Debug|x64 {07C389E3-6BC8-41CF-923E-307B1265FA2D}.Release|x64.ActiveCfg = Release|x64 @@ -506,7 +497,6 @@ Global GlobalSection(NestedProjects) = preSolution {74485049-C722-400F-ABE5-86AC52D929B3} = {1AFB6476-670D-4E80-A464-657E01DFF482} {A46629C4-1A6C-40FA-A8B6-10E5102BB0BA} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC} - {44CC9375-3E6E-4D99-8913-7FB748807EBD} = {BEEAB7F2-FFF6-45AB-9CDB-B04CC0734B88} {3BB8493E-D18E-4485-A320-CB40F90F55AE} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC} {D1D6BC88-09AE-4FB4-AD24-5DED46A791DD} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC} {F9C68EDF-AC74-4B77-9AF1-005D9C9F6A99} = {D1D6BC88-09AE-4FB4-AD24-5DED46A791DD} diff --git a/doc/devdocs/modules/example_powertoy.md b/doc/devdocs/modules/example_powertoy.md deleted file mode 100644 index e07a072127..0000000000 --- a/doc/devdocs/modules/example_powertoy.md +++ /dev/null @@ -1,5 +0,0 @@ -#### [`dllmain.cpp`](/src/modules/example_powertoy/dllmain.cpp) -Contains DLL boilerplate code and implementation of the [PowerToys interface](/src/modules/interface/). - -#### [`trace.cpp`](/src/modules/example_powertoy/trace.cpp) -Contains code for telemetry. diff --git a/doc/devdocs/modules/interface.md b/doc/devdocs/modules/interface.md index 358b87e8f3..d8928b56dd 100644 --- a/doc/devdocs/modules/interface.md +++ b/doc/devdocs/modules/interface.md @@ -67,18 +67,6 @@ The returned PowerToy should be in the disabled state. The runner will call the In case of errors returns `nullptr`. -Sample code from [`the example PowerToy`](/src/modules/example_powertoy/dllmain.cpp): - -```cpp -extern "C" __declspec(dllexport) PowertoyModuleIface* __cdecl powertoy_create() { - return new ExamplePowertoy(); -} - -ExamplePowertoy::ExamplePowertoy() { - init_settings(); -} -``` - ## get_name ```cpp @@ -87,13 +75,6 @@ virtual const wchar_t* get_name() Returns the name of the PowerToy, it will be cached by the runner. -Sample code from [`the example PowerToy`](/src/modules/example_powertoy/dllmain.cpp): -```cpp - virtual const wchar_t* get_name() override { - return L"Example Powertoy"; - } -``` - ## get_events ```cpp @@ -106,17 +87,6 @@ Returns a null-terminated table of the names of the events the PowerToy wants to A nullptr can be returned to signal that the PowerToy does not want to subscribe to any event. -Sample code from [`the example PowerToy`](/src/modules/example_powertoy/dllmain.cpp): - -```cpp - virtual const wchar_t** get_events() override { - static const wchar_t* events[] = { ll_keyboard, - win_hook_event, - nullptr }; - return events; - } -``` - ## get_config ``` @@ -129,44 +99,6 @@ If `buffer` is a null pointer or the buffer size is not large enough sets the re Returns true if successful. -Sample code from [`the example PowerToy`](/src/modules/example_powertoy/dllmain.cpp): - -```cpp - 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(L"Serves as an example powertoy, with example settings."); - - // Add an overview link to show in the Settings. - settings.set_overview_link(L"https://github.com/microsoft/PowerToys"); - - // Add a video link to show in the Settings. - settings.set_video_link(L"https://www.youtube.com/watch?v=d3LHo2yXKoY&t=21462"); - - // Add a bool property with a toggle editor. - settings.add_bool_toggle( - L"test_bool_toggle", // property name. - L"This is what a BoolToggle property looks like", // description or resource id of the localized string. - test_bool_prop // property value. - ); - -// More settings -... - - // Add a custom action property. When using this settings type, the "call_custom_action()" method should be overridden as well. - settings.add_custom_action( - L"test_custom_action", // action name. - L"This is what a CustomAction property looks like", // label above the field. - L"Call a custom action", // button text. - L"Press the button to call a custom action in the Example PowerToy" // display values / extended info. - ); - - return settings.serialize_to_buffer(buffer, buffer_size); - } -``` - ## set_config ```cpp @@ -175,31 +107,6 @@ virtual void set_config(const wchar_t* config) After the user has changed the module settings in the Settings editor, the runner calls this method to pass to the module the updated values. It's a good place to save the settings as well. -Sample code from [`the example PowerToy`](/src/modules/example_powertoy/dllmain.cpp): - -```cpp - virtual void set_config(const wchar_t* config) override { - try { - // Parse the PowerToysValues object from the received json string. - PowerToysSettings::PowerToyValues _values = - PowerToysSettings::PowerToyValues::from_json_string(config); - - // Update the bool property. - if (_values.is_bool_value(L"test bool_toggle")) { - test_bool_prop = _values.get_bool_value(L"test bool_toggle"); - } - -// More settings -... - - save_settings(); - } - catch (std::exception ex) { - // Improper JSON. - } - } -``` - ## call_custom_action ```cpp @@ -209,31 +116,6 @@ Sample code from [`the example PowerToy`](/src/modules/example_powertoy/dllmain. Calls a custom action in response to the user pressing the custom action button in the Settings editor. This can be used to spawn custom editors defined by the PowerToy. -Sample code from [`the example PowerToy`](/src/modules/example_powertoy/dllmain.cpp): - -```cpp - virtual void call_custom_action(const wchar_t* action) override { - try { - // Parse the action values, including name. - PowerToysSettings::CustomActionObject action_object = - PowerToysSettings::CustomActionObject::from_json_string(action); - - if (action_object.get_name() == L"test_custom_action") { - - // Custom action code to increase and show a counter. - ++this->test_custom_action_num_calls; - std::wstring msg(L"I have been called "); - msg += std::to_wstring(this->test_custom_action_num_calls); - msg += L" time(s)."; - MessageBox(NULL, msg.c_str(), L"Custom action call.", MB_OK | MB_TOPMOST); - } - } - catch (std::exception ex) { - // Improper JSON. - } - } -``` - ## enable ```cpp @@ -242,14 +124,6 @@ Sample code from [`the example PowerToy`](/src/modules/example_powertoy/dllmain. Enables the PowerToy. -Sample code from [`the example PowerToy`](/src/modules/example_powertoy/dllmain.cpp): - -```cpp - virtual void enable() { - m_enabled = true; - } -``` - ## disable ```cpp @@ -258,14 +132,6 @@ Sample code from [`the example PowerToy`](/src/modules/example_powertoy/dllmain. Disables the PowerToy, should free as much memory as possible. -Sample code from [`the example PowerToy`](/src/modules/example_powertoy/dllmain.cpp): - -```cpp - virtual void disable() { - m_enabled = false; - } -``` - ## is_enabled ```cpp @@ -274,13 +140,6 @@ Sample code from [`the example PowerToy`](/src/modules/example_powertoy/dllmain. Returns the PowerToy state. -Sample code from [`the example PowerToy`](/src/modules/example_powertoy/dllmain.cpp): - -```cpp - virtual bool is_enabled() override { - return m_enabled; - } -``` ## signal_event ```cpp @@ -294,24 +153,6 @@ The data argument and return value meaning are event-specific: Please note that some of the events are currently being signalled from a separate thread. -Sample code from [`the example PowerToy`](/src/modules/example_powertoy/dllmain.cpp): - -```cpp - 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_system_menu_helper ```cpp @@ -338,14 +179,6 @@ Item name is passed as an argument, so that module can distinguish between diffe ``` Destroy the PowerToy and free all memory. -Sample code from [`the example PowerToy`](/src/modules/example_powertoy/dllmain.cpp): - -```cpp - virtual void destroy() override { - delete this; - } -``` - ## Powertoys system menu helper interface Interface for helper class responsible for handling all system menu related actions. @@ -393,15 +226,15 @@ Process action taken on specific system menu item. # Code organization -### [`powertoy_module_interface.h`](/src/modules/example_powertoy/powertoy_module_interface.h) +### [`powertoy_module_interface.h`](/src/modules/interface/powertoy_module_interface.h) Contains the PowerToys interface definition. -### [`powertoy_system_menu.h`](/src/modules/example_powertoy/powertoy_system_module.h) +### [`powertoy_system_menu.h`](/src/modules/interface/powertoy_system_module.h) Contains the PowerToys system menu helper interface definition. -### [`lowlevel_keyboard_event_data.h`](/src/modules/example_powertoy/lowlevel_keyboard_event_data.h) +### [`lowlevel_keyboard_event_data.h`](/src/modules/interface/lowlevel_keyboard_event_data.h) Contains the `LowlevelKeyboardEvent` structure that's passed to `signal_event` for `ll_keyboard` events. -### [`win_hook_event_data.h`](/src/modules/example_powertoy/win_hook_event_data.h) +### [`win_hook_event_data.h`](/src/modules/interface/win_hook_event_data.h) Contains the `WinHookEvent` structure that's passed to `signal_event` for `win_hook_event` events. diff --git a/doc/devdocs/readme.md b/doc/devdocs/readme.md index 61d22ba21a..2f1a328f67 100644 --- a/doc/devdocs/readme.md +++ b/doc/devdocs/readme.md @@ -134,11 +134,6 @@ PowerRename is a Windows Shell Context Menu Extension for advanced bulk renaming ### [`Shortcut Guide`](modules/shortcut_guide.md) The Windows Shortcut Guide, displayed when the WinKey is held for some time. -### _obsolete_ [`example_powertoy`](modules/example_powertoy.md) -An example PowerToy, that demonstrates how to create new ones. Please note, that this is going to become a Visual Studio project template soon. - -This PowerToy serves as a sample to show how to implement the [PowerToys interface](/src/modules/interface/) when creating a PowerToy. It also showcases the currently implemented settings. - #### Options This module has a setting to serve as an example for each of the currently implemented settings property: diff --git a/doc/images/example_powertoy/settings.png b/doc/images/settings/example_settings.png similarity index 100% rename from doc/images/example_powertoy/settings.png rename to doc/images/settings/example_settings.png diff --git a/src/modules/example_powertoy/dllmain.cpp b/src/modules/example_powertoy/dllmain.cpp deleted file mode 100644 index 95d899551f..0000000000 --- a/src/modules/example_powertoy/dllmain.cpp +++ /dev/null @@ -1,341 +0,0 @@ -#include "pch.h" -#include -#include -#include -#include "trace.h" -#include - -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; -} - -// PowerToy sample settings. -struct SampleSettings -{ - bool test_bool_prop = true; - int test_int_prop = 10; - std::wstring test_string_prop = L"The quick brown fox jumps over the lazy dog"; - std::wstring test_color_prop = L"#1212FF"; -} g_settings; - -// Implement the PowerToy Module Interface and all the required methods. -class ExamplePowertoy : public PowertoyModuleIface -{ -private: - // The PowerToy state. - bool m_enabled = false; - - // Load and save Settings. - void init_settings(); - void save_settings(); - -public: - // Constructor - ExamplePowertoy() - { - 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 - virtual const wchar_t* get_name() override - { - return L"Example Powertoy"; - } - - // 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 returned for empty - // list. - // Right now there is only lowlevel keyboard hook event - virtual const wchar_t** get_events() override - { - static const wchar_t* events[] = { ll_keyboard, - win_hook_event, - nullptr }; - return events; - } - - // Return JSON with the configuration options. - virtual bool get_config(_Out_ wchar_t* buffer, _Out_ int* buffer_size) override - { - HINSTANCE hinstance = reinterpret_cast(&__ImageBase); - - // Create a Settings object. - PowerToysSettings::Settings settings(hinstance, get_name()); - settings.set_description(L"Serves as an example powertoy, with example settings."); - - // Show an overview link in the Settings page - settings.set_overview_link(L"https://github.com/microsoft/PowerToys"); - - // Show a video link in the Settings page. - settings.set_video_link(L"https://www.youtube.com/watch?v=d3LHo2yXKoY&t=21462"); - - // Add a bool property with a toggle editor. - settings.add_bool_toggle( - L"test_bool_toggle", // property name. - L"This is what a BoolToggle property looks like", // description or resource id of the localized string. - g_settings.test_bool_prop // property value. - ); - - // Add an integer property with a spinner editor. - settings.add_int_spinner( - L"test_int_spinner", // property name - L"This is what a IntSpinner property looks like", // description or resource id of the localized string. - g_settings.test_int_prop, // property value. - 0, // min value. - 100, // max value. - 10 // incremental step. - ); - - // Add a string property with a textbox editor. - settings.add_string( - L"test_string_text", // property name. - L"This is what a String property looks like", // description or resource id of the localized string. - g_settings.test_string_prop // property value. - ); - - // Add a string property with a color picker editor. - settings.add_color_picker( - L"test_color_picker", // property name. - L"This is what a ColorPicker property looks like", // description or resource id of the localized string. - g_settings.test_color_prop // property value. - ); - - // Add a custom action property. When using this settings type, the "PowertoyModuleIface::call_custom_action()" - // method should be overridden as well. - settings.add_custom_action( - L"test_custom_action", // action name. - L"This is what a CustomAction property looks like", // label above the field. - L"Call a custom action", // button text. - L"Press the button to call a custom action in the Example PowerToy" // display values / extended info. - ); - - 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); - - if (action_object.get_name() == L"test_custom_action") - { - // Custom action code to increase and show a counter. - ++custom_action_num_calls; - std::wstring msg(L"I have been called "); - msg += std::to_wstring(custom_action_num_calls); - msg += L" time(s)."; - MessageBox(NULL, msg.c_str(), L"Custom action call.", MB_OK | MB_TOPMOST); - } - } - catch (std::exception& ) - { - // 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); - - // Update the bool property. - auto testBoolProp = values.get_bool_value(L"test_bool_toggle"); - if (testBoolProp) - { - g_settings.test_bool_prop = testBoolProp.value(); - } - - // Update the int property. - auto testIntSpinner = values.get_int_value(L"test_int_spinner"); - if (testIntSpinner) - { - g_settings.test_int_prop = testIntSpinner.value(); - } - - // Update the string property. - auto testStringText = values.get_string_value(L"test_int_spinner"); - if (testStringText) - { - g_settings.test_string_prop = testStringText.value(); - } - - // Update the color property. - auto testColorPicker = values.get_string_value(L"test_color_picker"); - if (testColorPicker) - { - g_settings.test_color_prop = testColorPicker.value(); - } - - // 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&) - { - // Improper JSON. - } - } - - // Enable the powertoy - virtual void enable() - { - m_enabled = true; - } - - // Disable the powertoy - virtual void disable() - { - 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; - } - - virtual void register_system_menu_helper(PowertoySystemMenuIface* helper) override {} - virtual void signal_system_menu_action(const wchar_t* name) override {} -}; - -// Load the settings file. -void ExamplePowertoy::init_settings() -{ - try - { - // Load and parse the settings file for this PowerToy. - PowerToysSettings::PowerToyValues settings = - PowerToysSettings::PowerToyValues::load_from_settings_file(ExamplePowertoy::get_name()); - - // Load the bool property. - auto testBoolToggle = settings.get_bool_value(L"test_bool_toggle"); - if (testBoolToggle) - { - g_settings.test_bool_prop = testBoolToggle.value(); - } - - // Load the int property. - auto testIntSpinner = settings.get_int_value(L"test_int_spinner"); - if (testIntSpinner) - { - g_settings.test_int_prop = testIntSpinner.value(); - } - - // Load the string property. - auto testStringText = settings.get_string_value(L"test_string_text"); - if (testStringText) - { - g_settings.test_string_prop = testStringText.value(); - } - - // Load the color property. - auto testColorPicker = settings.get_string_value(L"test_color_picker"); - if (testColorPicker) - { - g_settings.test_color_prop = testColorPicker.value(); - } - } - catch (std::exception&) - { - // Error while loading from the settings file. Let default values stay as they are. - } -} - -// This method of saving the module settings is only required if you need to do any -// custom processing of the settings before saving them to disk. -void ExamplePowertoy::save_settings() -{ - try - { - // Create a PowerToyValues object for this PowerToy - PowerToysSettings::PowerToyValues values(get_name()); - - // Save the bool property. - values.add_property( - L"test_bool_toggle", // property name - g_settings.test_bool_prop // property value - ); - - // Save the int property. - values.add_property( - L"test_int_spinner", // property name - g_settings.test_int_prop // property value - ); - - // Save the string property. - values.add_property( - L"test_string_text", // property name - g_settings.test_string_prop // property value - ); - - // Save the color property. - values.add_property( - L"test_color_picker", // property name - g_settings.test_color_prop // property value - ); - - // Save the PowerToyValues JSON to the power toy settings file. - values.save_to_settings_file(); - } - catch (std::exception&) - { - // Couldn't save the settings. - } -} - -extern "C" __declspec(dllexport) PowertoyModuleIface* __cdecl powertoy_create() -{ - return new ExamplePowertoy(); -} diff --git a/src/modules/example_powertoy/example_powertoy.rc b/src/modules/example_powertoy/example_powertoy.rc deleted file mode 100644 index 2caf10b5b7..0000000000 --- a/src/modules/example_powertoy/example_powertoy.rc +++ /dev/null @@ -1,34 +0,0 @@ -ÿþ#include "../../common/version.h" - -1 VERSIONINFO - FILEVERSION FILE_VERSION - PRODUCTVERSION PRODUCT_VERSION - 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", "Example PowerToy Module" - VALUE "FileVersion", FILE_VERSION_STRING - VALUE "InternalName", "Example PowerToy" - VALUE "LegalCopyright", COPYRIGHT_NOTE - VALUE "OriginalFilename", "example_powertoy.dll" - VALUE "ProductName", "Example PowerToy" - VALUE "ProductVersion", PRODUCT_VERSION_STRING - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END \ No newline at end of file diff --git a/src/modules/example_powertoy/example_powertoy.vcxproj b/src/modules/example_powertoy/example_powertoy.vcxproj deleted file mode 100644 index 0197043051..0000000000 --- a/src/modules/example_powertoy/example_powertoy.vcxproj +++ /dev/null @@ -1,135 +0,0 @@ - - - - - - Debug - x64 - - - Release - x64 - - - - 15.0 - {44CC9375-3E6E-4D99-8913-7FB748807EBD} - Win32Proj - examplepowertoy - 10.0.17134.0 - - - - DynamicLibrary - true - v142 - Unicode - Spectre - - - DynamicLibrary - false - v142 - true - Unicode - Spectre - - - - - - - - - - - - - - - true - $(SolutionDir)$(Platform)\$(Configuration)\modules\ - $(SolutionDir)$(Platform)\$(Configuration)\obj\$(ProjectName)\ - - - false - $(SolutionDir)$(Platform)\$(Configuration)\modules\ - $(SolutionDir)$(Platform)\$(Configuration)\obj\$(ProjectName)\ - - - - Level3 - Disabled - true - _DEBUG;EXAMPLEPOWERTOY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - ..\..\common\inc;..\..\common\Telemetry;..\;..\..\;..\..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories) - MultiThreadedDebug - stdcpplatest - - - Windows - true - $(OutDir)$(TargetName)$(TargetExt) - - - - - Level3 - MaxSpeed - true - true - true - NDEBUG;EXAMPLEPOWERTOY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - ..\..\common\inc;..\..\common\Telemetry;..\;..\..\;..\..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories) - MultiThreaded - stdcpplatest - - - Windows - true - true - true - $(OutDir)$(TargetName)$(TargetExt) - - - - - Use - pch.h - - - - - - - - - - - Create - - - - - - {74485049-c722-400f-abe5-86ac52d929b3} - - - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - \ No newline at end of file diff --git a/src/modules/example_powertoy/example_powertoy.vcxproj.filters b/src/modules/example_powertoy/example_powertoy.vcxproj.filters deleted file mode 100644 index e69fd9068f..0000000000 --- a/src/modules/example_powertoy/example_powertoy.vcxproj.filters +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/modules/example_powertoy/packages.config b/src/modules/example_powertoy/packages.config deleted file mode 100644 index 26002072f1..0000000000 --- a/src/modules/example_powertoy/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/modules/example_powertoy/pch.cpp b/src/modules/example_powertoy/pch.cpp deleted file mode 100644 index 6db1b5fa29..0000000000 --- a/src/modules/example_powertoy/pch.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "pch.h" -#pragma comment(lib, "windowsapp") \ No newline at end of file diff --git a/src/modules/example_powertoy/pch.h b/src/modules/example_powertoy/pch.h deleted file mode 100644 index fe34ebab4b..0000000000 --- a/src/modules/example_powertoy/pch.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once -#define WIN32_LEAN_AND_MEAN -#include -#include -#include -#include \ No newline at end of file diff --git a/src/modules/example_powertoy/resource.h b/src/modules/example_powertoy/resource.h deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/modules/example_powertoy/trace.cpp b/src/modules/example_powertoy/trace.cpp deleted file mode 100644 index d8c81500f8..0000000000 --- a/src/modules/example_powertoy/trace.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#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_MyEvent", - ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), - TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"), - TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE)); -} diff --git a/src/modules/example_powertoy/trace.h b/src/modules/example_powertoy/trace.h deleted file mode 100644 index 3939f62fd1..0000000000 --- a/src/modules/example_powertoy/trace.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -class Trace -{ -public: - static void RegisterProvider(); - static void UnregisterProvider(); - static void MyEvent(); -}; diff --git a/src/modules/interface/powertoy_module_interface.h b/src/modules/interface/powertoy_module_interface.h index 0bff2d4c84..7e90217a44 100644 --- a/src/modules/interface/powertoy_module_interface.h +++ b/src/modules/interface/powertoy_module_interface.h @@ -4,7 +4,7 @@ DLL Interface for PowerToys. The powertoy_create() (see below) must return an object that implements this interface. - See src/modules/example_powertoy for simple, noop, PowerToy implementation. + See tools/project_template/ModuleTemplate for simple, noop, PowerToy implementation. The PowerToys runner will, for each PowerToy DLL: - load the DLL, diff --git a/tools/project_template/README.md b/tools/project_template/README.md index 65abee2b29..1e19ff1c34 100644 --- a/tools/project_template/README.md +++ b/tools/project_template/README.md @@ -11,8 +11,7 @@ If you'd like to work on a PowerToy template, make required modifications to `\t ## Create a new PowerToy Module - Add the new PowerToy project to the `src\modules\` folder for all the relative paths to work. -- For the module interface implementation take a look at [the interface](/src/modules/interface) and - [the example PowerToy implementation](/src/modules/example_powertoy/dllmain.cpp) +- For the module interface implementation take a look at [the interface](/src/modules/interface). - Each PowerToy is built as a DLL and in order to be loaded at run-time, the PowerToy's DLL name needs to be added to the `known_dlls` map in [src/runner/main.cpp](/src/runner/main.cpp). ## DPI Awareness @@ -48,7 +47,7 @@ A PowerToy can define settings of the following types: Here's an example of what the settings look like in the Settings screen: -![Image of the Options](/doc/images/example_powertoy/settings.png) +![Image of the Options](/doc/images/settings/example_settings.png) ### How to add your module's settings page @@ -56,7 +55,7 @@ The PowerToy can set its settings information and controls by overriding the [Po The PowerToy can receive the new values by overriding the [PowerToy's Interface `set_config` method](/src/modules/interface/README.md#set_config), parsing the serialized [`PowerToysSettings::PowerToyValues`](/src/common/settings_object.h) object and applying the new settings. -Here's an example from [the example PowerToy implementation](/src/modules/example_powertoy/dllmain.cpp): +Here's an example settings implementation: ```cpp // Return JSON with the configuration options. virtual bool get_config(wchar_t* buffer, int* buffer_size) override { @@ -343,7 +342,7 @@ Loading and saving the settings in the default location can be achieved through The PowerToy can load the saved `PowerToyValues` object through the use of the `load_from_settings_file` method. -Here's an example from [the example PowerToy implementation](/src/modules/example_powertoy/dllmain.cpp): +Here's an example: ```cpp // Load the settings file. void ExamplePowertoy::init_settings() { @@ -382,7 +381,7 @@ void ExamplePowertoy::init_settings() { The PowerToy can save the `PowerToyValues` object received in `set_config` through the use of the `save_to_settings_file` method. -Here's an example from [the example PowerToy implementation](/src/modules/example_powertoy/dllmain.cpp): +Here's an example: ```cpp // Called by the runner to pass the updated settings values as a serialized JSON. virtual void set_config(const wchar_t* config) override {