microsoft / PowerToys

Windows system utilities to maximize productivity
MIT License
111.09k stars 6.53k forks source link

Settings API simplification #20069

Open yuyoyuppe opened 2 years ago

yuyoyuppe commented 2 years ago

Description of the new feature / enhancement

You have to manually reimplement Properties classes with all its fields, default values and json (de)serlialization logic at least in 3 places for each module. That creates a lot of manual coordination that could be a source of bugs.

For an example, see:

Scenario when this would be used?

This applies for developing/supporting any module, especially written in C++.

Supporting information

https://github.com/microsoft/CsWin32/ could be used to investigate code generators.

Aaron-Junker commented 2 years ago

Yes please. It really is too complicated

yuyoyuppe commented 2 years ago

@Aaron-Junker feel free to mention here any other pain points you've noticed while working with them - any examples/links would be also great.

Aaron-Junker commented 1 year ago

Could it be an option to use C# source generators to just generate the source code out of the XAML code. So that things like the json name of the setting is saved in a costum xaml field.

So for example:

<labs:SettingsCard ContentAlignment="Left">
    <CheckBox
        x:Uid="AlwaysOnTop_GameMode"
        IsChecked="{x:Bind Mode=TwoWay, Path=ViewModel.DoNotActivateOnGameMode}" />
</labs:SettingsCard>

and the whole c# code logic are just reduced to:

<labs:SettingsCard ContentAlignment="Left">
    <CheckBox
        x:Uid="AlwaysOnTop_GameMode"
        pt:propertyName="DoNotActivateOnGameMode"
        pt:defaultValue="true"
        pt:jsonName="do-not-activate-on-game-mode"
        pt:jsonType="bool" />
</labs:SettingsCard>

And then the whole c# code to this is just generated automatically.

Thoughts?

cc: @jaimecbernardo @niels9001