Kaleidoscope icon indicating copy to clipboard operation
Kaleidoscope copied to clipboard

Focus: Add a mechanism to discover commands eligible for backup

Open algernon opened this issue 1 year ago • 2 comments

The goal here is to make it easier for Chrysalis and other tools to make structured backups. Chrysalis currently has a hard-coded list of commands to run and backup the results of - not ideal. We want a solution where a tool can automatically discover what can be backed up safely.

We can't just call every command in the help output without an argument, because some of them (device.reset, eeprom.erase, etc) are destructive. We do not wish to maintain a deny list, either.

We'd like a mechanism where plugins themselves can tell which commands they can offer for backing up. This patch implements such a solution, one very similar to how we handle help. In addition to responding to help, plugins can now respond to backup, and write a list of commands in the same format as for help: one per line.

The tool on the host side can take this list of commands, execute them, and store their values for backup purposes. Simple, straightforward, lightweight.

On top of adding the mechanism, the patch also changes all bundled plugins to respond to the backup command if appropriate, with the commands that should be backed up.

Fixes #1279.

algernon avatar Oct 16 '22 12:10 algernon

To test if this works correctly, I implemented a backup and a restore command for one of the tools in kaleidoscope-focus.rs: keyboardio/kaleidoscope-focus.rs#1.

It seems to be working quite well, and can backup any command that opts into the mechanism.

algernon avatar Oct 16 '22 12:10 algernon

While this does add a bit of code size (~146 bytes on the default Model01 firmware, our tightest one), considering how much it buys us, I'm quite happy with that. The Model01 firmware still fits, too.

algernon avatar Oct 16 '22 12:10 algernon

I feel like this demonstrates @argonblue's suggestion that we get focus processing into focus and out of the plugins.

For this specific use case, that might look like a new 'handleFocusBlahblahBackupBlah" hook that plugins can implement, possibly also adding a handleFocusHelpCommand hook next to it at the same time.

On Sun, Oct 16, 2022 at 5:58 AM Gergely Nagy @.***> wrote:

While this does add a bit of code size (~146 bytes on the default Model01 firmware, our tightest one), considering how much it buys us, I'm quite happy with that. The Model01 firmware still fits, too.

— Reply to this email directly, view it on GitHub https://github.com/keyboardio/Kaleidoscope/pull/1280#issuecomment-1279964797, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAALC2FGO2WTS7WZ7J6TOALWDP3ZBANCNFSM6AAAAAARGKTM3U . You are receiving this because your review was requested.Message ID: @.***>

obra avatar Oct 24 '22 20:10 obra

We should go all the way then, and go with their suggestion of using a command table (#1285), otherwise we'll either end up duplicating a lot of strings, or pushing them into the plugin class - which would get us halfway to having a command table, but only half.

I do like the command table idea, so lets close this one, and move forward with #1285? We can even delete the branch, because backup-eligible command list is now in Chrysalis and in kaleidoscope-focus.rs too, in a more compact, easier to re-use format.

algernon avatar Oct 24 '22 21:10 algernon