Skip to content

Commit

Permalink
Fix crash when saving any module settings while module being disabled (
Browse files Browse the repository at this point in the history
  • Loading branch information
vldmr11080 authored and udit3333 committed Feb 20, 2020
1 parent 88a757f commit 7873ada
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/modules/fancyzones/dll/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class FancyZonesModule : public PowertoyModuleIface
}
m_app->Destroy();
m_app = nullptr;
m_settings->ResetCallback();
}
}

Expand Down
1 change: 1 addition & 0 deletions src/modules/fancyzones/lib/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct FancyZonesSettings : winrt::implements<FancyZonesSettings, IFancyZonesSet
}

IFACEMETHODIMP_(void) SetCallback(IFancyZonesCallback* callback) { m_callback = callback; }
IFACEMETHODIMP_(void) ResetCallback() { m_callback = nullptr; }
IFACEMETHODIMP_(bool) GetConfig(_Out_ PWSTR buffer, _Out_ int *buffer_sizeg) noexcept;
IFACEMETHODIMP_(void) SetConfig(PCWSTR config) noexcept;
IFACEMETHODIMP_(void) CallCustomAction(PCWSTR action) noexcept;
Expand Down
1 change: 1 addition & 0 deletions src/modules/fancyzones/lib/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct Settings
interface __declspec(uuid("{BA4E77C4-6F44-4C5D-93D3-CBDE880495C2}")) IFancyZonesSettings : public IUnknown
{
IFACEMETHOD_(void, SetCallback)(interface IFancyZonesCallback* callback) = 0;
IFACEMETHOD_(void, ResetCallback)() = 0;
IFACEMETHOD_(bool, GetConfig)(_Out_ PWSTR buffer, _Out_ int *buffer_size) = 0;
IFACEMETHOD_(void, SetConfig)(PCWSTR serializedPowerToysSettingsJson) = 0;
IFACEMETHOD_(void, CallCustomAction)(PCWSTR action) = 0;
Expand Down
43 changes: 26 additions & 17 deletions src/modules/shortcut_guide/shortcut_guide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,40 @@ void OverlayWindow::set_config(const wchar_t* config)
{
try
{
// save configuration
PowerToysSettings::PowerToyValues _values =
PowerToysSettings::PowerToyValues::from_json_string(config);
if (const auto press_delay_time = _values.get_int_value(pressTime.name))
_values.save_to_settings_file();
Trace::SettingsChanged(pressTime.value, overlayOpacity.value, theme.value);

// apply new settings if powertoy is enabled
if (_enabled)
{
pressTime.value = *press_delay_time;
if (target_state)
if (const auto press_delay_time = _values.get_int_value(pressTime.name))
{
target_state->set_delay(*press_delay_time);
pressTime.value = *press_delay_time;
if (target_state)
{
target_state->set_delay(*press_delay_time);
}
}
}
if (const auto overlay_opacity = _values.get_int_value(overlayOpacity.name))
{
overlayOpacity.value = *overlay_opacity;
if (winkey_popup)
if (const auto overlay_opacity = _values.get_int_value(overlayOpacity.name))
{
winkey_popup->apply_overlay_opacity(((float)overlayOpacity.value) / 100.0f);
overlayOpacity.value = *overlay_opacity;
if (winkey_popup)
{
winkey_popup->apply_overlay_opacity(((float)overlayOpacity.value) / 100.0f);
}
}
if (auto val = _values.get_string_value(theme.name))
{
theme.value = std::move(*val);
if (winkey_popup)
{
winkey_popup->set_theme(theme.value);
}
}
}
if (auto val = _values.get_string_value(theme.name))
{
theme.value = std::move(*val);
winkey_popup->set_theme(theme.value);
}
_values.save_to_settings_file();
Trace::SettingsChanged(pressTime.value, overlayOpacity.value, theme.value);
}
catch (...)
{
Expand Down

0 comments on commit 7873ada

Please sign in to comment.