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

Config: add saveConfig and resetConfig actions #7606

Merged
merged 24 commits into from
Aug 1, 2018

Conversation

josephsl
Copy link
Collaborator

@josephsl josephsl commented Sep 15, 2017

Link to issue number:

closes #7598

Summary of the issue:

Add actions to notify when configuration is being saved and reloaded.

Description of how this pull request fixes the issue:

This pull request adds two new extension point actions:

  • config.saveConfig: notifies listeners when config is saved.
  • config.resetConfig: notifies listeners when config is being reloaded or reset to defaults (controlled by a boolean that'll be passed around to handlers).

Testing performed:

Added a method that plays tones or prints a message when notifications arrive from these actions.

Known issues with pull request:

Add-ons will need to be updated to register and unregister when they initialize or terminate, respectivley.

Change log entry:

None, unless required (should be listed under "changes for developers" section).

… and perform appropriate actions when saving or reverting settings, respectivley. re nvaccess#7598.

Some add-ons do not participate in ConfigManager/profiles at the moment. For these, there's no easy way to revert settings or Control+NVDA+C cannot be used to let add-ons save settings.
To accomodate this, two new actions (extensionPoints.Action) are introduced:
* config.saveConfig: a new extension point that allows add-ons to save settings to custom location(s).
* config.resetConfig: allows add-ons to reload settings from anywhere and/or reset configuration to defaults (controlled by a boolean).
This requires NVDA 2017.4/extensionPoints support.
@josephsl
Copy link
Collaborator Author

Even though he is no longer an active member, I'd like to request comments from @jcsteh if this is something that could be useful for many. Thanks.

@josephsl
Copy link
Collaborator Author

@ctoth, @tspivey and @LeonarddeR, is this something Remote Support add-on can benefit? Also, for @nvdaes, do you find yourself using this PR in future versions of Read Feeds, Place Markers and what not? Thanks. CC @derekriemer

@nvdaes
Copy link
Collaborator

nvdaes commented Sep 15, 2017 via email

@jcsteh
Copy link
Contributor

jcsteh commented Sep 15, 2017 via email

@jcsteh
Copy link
Contributor

jcsteh commented Sep 15, 2017

On second thought, I can imagine there would be some use cases where config data isn't key/value based, in which case it could never be done with the core config framework and therefore would have to be managed by custom code. In that case, having these actions would be necessary. I think some underlying concerns about using core config need to be dealt with, but there's probably no harm in adding these either.

@LeonarddeR
Copy link
Collaborator

LeonarddeR commented Sep 15, 2017

@jcsteh commented on 15 sep. 2017 09:09 CEST:

It seems to me that the primary use cases for this relate to being dissatisfied in some way with the core config mechanism. So, rather than considering a workaround as the first option, I think it's worth considering whether and how the core config system can be improved to address these.

You just stole these words out of my mouth :)

Additional thought: The extension point for config profile switches is called configProfileSwitched. I'd like to propose sticking to this convention.

  • config.configSaved: notifies listeners when config is saved.
  • config.configReset: notifies listeners when config is being reloaded or reset to defaults (controlled by a boolean that'll be passed around to handlers).

@josephsl
Copy link
Collaborator Author

josephsl commented Sep 15, 2017 via email

@josephsl
Copy link
Collaborator Author

josephsl commented Sep 15, 2017 via email

@derekriemer
Copy link
Collaborator

That's actually a very interesting use case for this.

@Brian1Gaff
Copy link

Brian1Gaff commented Sep 15, 2017 via email

@derekriemer
Copy link
Collaborator

This isn't a user visible change, it's just allowing addons and things to receive save notifications when config is saved.

@LeonarddeR
Copy link
Collaborator

@josephsl commented on 15 Sep 2017, 09:34 CEST:

Hi, there are code such as someMod.handle* where the verb comes first, but I’m happy for my PR to be modified to reflect this. Thanks.

Note that I suggested configSaved, not configSave. Thus, the Past Participle of the verb.

@nvdaes
Copy link
Collaborator

nvdaes commented Sep 16, 2017

Replying to @LeonarddeR

Note that I suggested configSaved, not configSave. Thus, the Past Participle of the verb.

I agree.

I think this PR could help to improve the Emoticons add-on, to use profiles for activation deppending on different apps.
Cheers

@josephsl
Copy link
Collaborator Author

josephsl commented Sep 16, 2017 via email

@LeonarddeR
Copy link
Collaborator

@josephsl commented on 16 Sep 2017, 09:27 CEST:

I used “configSave” because this is essentially going to notify add-ons and other code that they should save config or deal with saved config.

Strictly spoken, when looking at your code, you are notifying registered parties that the NVDA configuration has been saved. Thus, this action isn't triggered when saving NVDA's configuration failed, which is exactly what should happen :)

@dkager
Copy link
Collaborator

dkager commented Sep 16, 2017

If nothing else I think all event handlers/actionsfilters/etc should have the same name structure. This doesn't necessarily have to be handleX, as long as it is somehow possible to easily identify something as an event handler (e.g. Java has Listeners and Adapters).

@josephsl
Copy link
Collaborator Author

josephsl commented Sep 16, 2017 via email

@ctoth
Copy link
Contributor

ctoth commented Sep 16, 2017

Let's try and do this the right way, rather than guessing

Pick a set of prefixes, assign meanings to them, make every signal send 3 signals
Something like should x, x, done_x
Problem solved.
You won't ever be able to figure out all the use cases people want to hook ahead of time, trust me. so you have to set a standard for what you're going to do, when you're doing it, and when it's done, then use that everywhere.

This is similar to how Apple does things, where they use should, will, and did.

@josephsl
Copy link
Collaborator Author

josephsl commented Sep 16, 2017 via email

@LeonarddeR
Copy link
Collaborator

@feerrenrut: Would you be able to give your opinion on the several things discussed here regarding the naming conventions and the current state of this pr?

@feerrenrut
Copy link
Contributor

I agree that the name of the action should be centered on what is being done internally rather than a suggestion of what subscribers should do. I like the idea of having a standard (documented) format for these actions.

I'm initially drawn to PreConfigSave, and ConfigSaved. However I am concerned that this pattern may not be able to apply in all situations. So perhaps PreConfigSave, and PostConfigSave is a better pair. I think to make the pattern more clear, I would recommend the introduction of an underscore EG Pre_configSave and Post_configSave.

…ess#7598.

Requested by many reviewers: there are times it is helpful to let modules perform actions prior to and/or after NVDA settings are saved, most likely when add-ons need to save settings and/or a module will transport settings to a cloud location for safekeeping or cynchronization purposes. Thus split configSaved action into configPreSave (prior to) and configPostSave (after) actions. Not all modules should listen to both events at once - for add-ons, configPreSave action is enough.
configPostSave = extensionPoints.Action()
#: Notifies when configuration is reloaded from disk or factory defaults are applied.
#: Handlers are called with a boolean argument indicating whether this is a factory reset (True) or just reloading from disk (False).
configReset = extensionPoints.Action()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good if this followed the pattern of pre / post. If there is no need to implement pre, please just rename this to postConfigReset.

#: Handlers can listen to "pre" or "post" action to perform tasks prior to or after NVDA's own configuration is saved.
#: Handlers are called with no arguments.
configPreSave = extensionPoints.Action()
configPostSave = extensionPoints.Action()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be much clearer that this is a general pattern (and make it easier to keep the names consistent) if these were:
preConfigSave and postConfigSave.

@josephsl
Copy link
Collaborator Author

josephsl commented May 7, 2018 via email

…s. Re nvaccess#7598.

During the pull request discussion, @ctoth advised splitting save/reset actions into three parts: pre, on, and post. With a possible case of these actions being cloud settings backup/restore, it would be best to divide it like this:
* preConfigSave/preConfigReset: for validation checks, preparing settings files for reset.
* onConfigSave/onConfigreset: called right after NvDA own settings are saved and reset, useful as the main action by add-ons and other modules to save and/or reload settings.
* postConfigSave/postConfigReset: the best use case is transporting settings to somewhere, especially to the cloud.
@josephsl
Copy link
Collaborator Author

josephsl commented Jul 2, 2018

Hi,

As of the latest commit, config save/reset actions are divided into three parts as suggested by @ctoth a while ago. This also brings consistency with @LeonarddeR's work on isValid/onSave/postSave methods for settings panels (NVDA 2018.2).

The actions are:

  • preConfigSave/preConfigReset: to be used in scenarios where config validation must take place, or in case of reset, preparing config backup from the cloud.
  • onConfigSave/onConfigReset: the main action to be taken by add-ons and other modules.
  • postConfigSave/postConfigReset: reserved for add-ons and modules that deal with configuration as a whole such as saving settings to the cloud and/or making corrections to restored settings.

Thanks.

Copy link
Contributor

@feerrenrut feerrenrut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the introduction of onConfigReset/onConfigSave only introduces confusion. Especially in the documentation, saying "during", indicates concurrency when there is none. For all intents and purposes, it is equivalent in both cases to the "post" extension point. I don't think it's a good idea to try to draw comparisons or try to be consistent with the settings dialogs. If you were trying to be consistent, then one action should be a decider, in a similar vein to isValid (eg shouldDoConfigSave / shouldDoConfigReset), and should allow an addon to decide if the config save / reset should take place at all. This would be a big decision in itself, which I don't think should be made here.

@josephsl
Copy link
Collaborator Author

josephsl commented Jul 3, 2018 via email

Reviewed by Reef Turner (NV Access): just because settings dialogs have pre/on/post save handlers does not mean config should be made consistent with it. Thus remove onConfig* actions for now until future work justifies this.
josephsl added 2 commits July 5, 2018 23:01
…). Re nvaccess#7598.

Advised by Reef Turner (NV Access) and @LeonarddeR (Babbage): use the following variable identifier format: 'pre_/post_actionname'. This means:
* config.postConfigSave -> config.post_configSave.
* config.preConfigSave -> config.pre_configSave.
* config.postConfigReset -> config.post_configReset.
* config.preConfigReset -> config.pre_configReset.
* config.postConfigProfileSwitch -> config.post_configProfileSwitch.
@josephsl
Copy link
Collaborator Author

josephsl commented Jul 6, 2018

Hi,

Done, ready for more checkup/review. Thanks.

Copy link
Contributor

@feerrenrut feerrenrut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Joseph!

Copy link
Contributor

@feerrenrut feerrenrut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry Joseph, one more thing, could you update the changes.t2t file as a part of this pull request? The release process has changed now and although it doesn't yet document this, I think it's possible that pull requests can include this change since they are going straight to master.

@LeonarddeR
Copy link
Collaborator

@feerrenrut: I recall that @michaelDCurran said that changes still should be applied manually to the changes.t2t, as it will cause merge conflicts if every pr is supposed to update the changes file by itself.

@LeonarddeR
Copy link
Collaborator

@leonardder commented on 6 Jul 2018, 10:45 CEST:

@feerrenrut: I recall that @michaelDCurran said that changes still should be applied manually to the changes.t2t, as it will cause merge conflicts if every pr is supposed to update the changes file by itself.

Quote from @michaelDCurran:

I am starting to not like the pr carrying the change to changes.t2t with a possible conflict, as by quick glancing at the pr, it simply looks like there are merge conflicts. It is not obvious that it is just because of changes.t2t.

@josephsl
Copy link
Collaborator Author

josephsl commented Jul 6, 2018 via email

@LeonarddeR
Copy link
Collaborator

@josephsl: Seem that consensus has changed in such a way that changes.t2t additions are now expected before merging a pr. Could you please deal with this?

@josephsl
Copy link
Collaborator Author

josephsl commented Jul 30, 2018 via email

@josephsl
Copy link
Collaborator Author

Hi,

Thought I added what's new entries... I stand corrected.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add-on config: allow add-ons to respond to config save/reload/reset actions via a new extension points action
10 participants