WindowFocus constructor
Creates an instance of WindowFocus
for tracking user activity and window focus.
The constructor allows enabling debug mode and setting the user inactivity timeout when creating an instance.
debug
: Iftrue
, the plugin will output debug messages to the console. Useful for diagnosing plugin behavior during development.duration
: The user inactivity timeout after which the plugin sends an event indicating that the user is inactive. Default is 1 second.
Example usage:
Enable debug mode:
final windowFocus = WindowFocus(debug: true);
Set a custom inactivity timeout:
final windowFocus = WindowFocus(duration: Duration(seconds: 30));
Enable debug mode and set a custom timeout:
final windowFocus = WindowFocus(
debug: true,
duration: Duration(seconds: 10),
);
Implementation
WindowFocus({bool debug = false,Duration duration=const Duration(seconds: 1)}) {
_debug = debug;
_channel.setMethodCallHandler(_handleMethodCall);
if (_debug) {
setDebug(_debug);
}
setIdleThreshold(duration: duration);
}