Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when saving any module settings while module being disabled #1259

Merged
merged 4 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; }
IFACEMETHOD_(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
44 changes: 27 additions & 17 deletions src/modules/shortcut_guide/shortcut_guide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,35 +66,45 @@ 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 (...)
{
// Improper JSON. TODO: handle the error.
return;
vldmr11080 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down