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

Support multiple navigation keys in the generic plugin #292

Merged
merged 2 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ Iterates over the available link:plugins[], picks the compatible one for present
[#generic]
=== `generic`

Emulates the end-user interaction by pressing the key with the specified `--key` option and iterates over the presentation as long as:
Emulates the end-user interaction by pressing the key with the specified `--key` option, and iterates over the presentation as long as:

[loweralpha]
. Any change to the DOM is detected by observing mutation events targeting the body element and its subtree nor
. the number of slides exported has reached the specified `--max-slides` option.
. Any change to the DOM is detected by observing mutation events targeting the body element and its subtree,
. Nor the number of slides exported has reached the specified `--max-slides` option.

The `--key` value must be one of the {uri-w3c-uievents-key}[UI events `KeyboardEvent` key values] and defaults to `ArrowRight`, e.g.:
The `--key` option must be a list of {uri-w3c-uievents-key}[UI events `KeyboardEvent` key values], and defaults to `['ArrowRight']`, e.g.:

$ decktape generic --key=ArrowDown
$ decktape generic --key=ArrowDown --key=ArrowRight

== Options

Expand Down
34 changes: 21 additions & 13 deletions plugins/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import { pause } from '../libs/util.js';

export const options = {
key : {
default : 'ArrowRight',
keys : {
full : 'key',
metavar : '<key>',
help : 'Key pressed to navigate to next slide',
list : true,
default : ['ArrowRight'],
help : 'Key pressed to navigate to next slide, can be repeated',
},
maxSlides : {
full : 'max-slides',
Expand All @@ -24,12 +26,13 @@ export const options = {
};

export const help =
`Emulates the end-user interaction by pressing the key with the specified --key option
`Emulates the end-user interaction by pressing the key with the specified --key option,
and iterates over the presentation as long as:
- Any change to the DOM is detected by observing mutation events targeting the body element
and its subtree,
- Nor the number of slides exported has reached the specified --max-slides option.
The --key option must be one of the 'KeyboardEvent' keys and defaults to [${options.key.default}].`;

The --key option must be a list of 'KeyboardEvent' keys, and defaults to [${options.keys.default}].`;

export const create = (page, opts) => new Generic(page, opts);

Expand All @@ -39,7 +42,7 @@ class Generic {
this.options = opts;
this.currentSlide = 1;
this.isNextSlideDetected = false;
this.key = this.options.key || options.key.default;
this.keys = this.options.keys || options.keys.default;
this.media = this.options.media || options.media.default;
}

Expand Down Expand Up @@ -74,17 +77,22 @@ class Generic {
if (this.options.maxSlides && this.currentSlide >= this.options.maxSlides) {
return false;
}
await this.page.keyboard.press(this.key);
// TODO: use mutation event directly instead of relying on a timeout
// TODO: detect cycle to avoid infinite navigation for frameworks
// that support loopable presentations like impress.js and flowtime.js
await pause(1000);
return this.isNextSlideDetected;
for (let key of this.keys) {
this.isNextSlideDetected = false;
await this.page.keyboard.press(key);
// TODO: use mutation event directly instead of relying on a timeout
// TODO: detect cycle to avoid infinite navigation for frameworks
// that support loopable presentations like impress.js and flowtime.js
await pause(1000);
if (this.isNextSlideDetected) {
return true;
}
}
return false;
}

nextSlide() {
this.currentSlide++;
this.isNextSlideDetected = false;
}

async currentSlideIndex() {
Expand Down