Hands the player this condition, replacing the one it has (without a
leave for the old one). A condition already true is entered at once,
except a range list given again for the same source while the
position is still in the range it was entered with (the same start,
end and lead; a list that grew as a scan went on): that range stays
entered, with no second enter, and an enter of it still on its way
(a plugin woken for it) reaches enter all the same. The same
condition again changes nothing. A refusal (invalid,
limit) reaches the plugin's error handlers.
A command arms the trigger for the file open now: its condition holds
from ten seconds before the end, and enter pauses. Pressing it again
replaces the condition, without a leave for the old one.
const { when, player } = plugin;
const nearEnd = plugin.trigger("near-end").enter(() => player.setPaused(true));
plugin.commands.add({
id: "pause-near-end",
path: ["Tools", "Pause Near the End"],
run: () => {
const duration = player.state.duration;
// Bound to the current file: another file never matches it.
if (duration !== null)
nearEnd.firesOn(when.position.in([{ start: Math.max(0, duration - 10) }]));
},
});
fn runs each time the condition turns from false to true. One
trigger's functions run one after another: the next waits for the
promise of the one before. A second call replaces the function.
The OSD names the part of the file as playback reaches it. range
says which of the ranges was entered: index is its place in the
list the condition was given.
const { when, osd } = plugin;
plugin
.trigger()
.firesOn(when.position.in(parts))
// `range` is set because the condition has a position list.
.enter(async ({ range }) => {
if (range) await osd.show("Now: {}", [parts[range.index].name]);
});
Optional: fn runs each time the condition turns from true to false.
A second call replaces the function.
Removes the condition, without a leave. The trigger stays declared
and can be given a new condition.
A second command disarms the timer the first one set: the player forgets the condition, so the plugin is not started for it.
const sleep = plugin.trigger("sleep").enter(() => plugin.player.setPaused(true));
plugin.commands.add({
id: "sleep-cancel",
path: ["Tools", "Cancel Sleep Timer"],
run: () => sleep.off(), // the trigger stays; only its condition goes
});
A trigger (
plugin.trigger()): a place for one condition the player keeps and evaluates, also while the plugin is in standby, and the functions to call when it becomes true (enter) and false (leave).Remarks
When it flips while the plugin has no process, the player starts the plugin;
activate()declares the same triggers again and the waiting notification reaches the same trigger. Every method returns the trigger, so the calls chain.Example: On top while playing in fullscreen
The window stays on top while a file plays in fullscreen and goes back when either ends. The player evaluates the condition itself, so the plugin may be in standby in between.
Since
1.10.0