パッケージ、リポジトリ、アプリカテゴリを検索

window_focus のカバー
パッケージ詳細v1.2.1

window_focus

Window Focus は、Flutter用の便利なプラグインで、ユーザーの非アクティブ状態を追跡し、Mac OSおよびWindows上のアクティブなウィンドウのタイトル情報を取得できます。

macOSWindowsLinux
30日間ダウンロード
20
いいね数
8
Pub ポイント
140

パッケージをインストール

flutter pub add window_focus

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Window Focus は、macOS および Windows でユーザーの非活動状態を追跡し、アクティブなウィンドウのタイトルを取得できる Flutter プラグインです。現在フォーカスされているアプリケーションまたはウィンドウをモニタリングすることで、開発者がユーザー行動に関するインサイトを得ることができます。このプラグインは生産性ツール、タイムトラッキングアプリ、デスクトッププラットフォーム間でのユーザー状況認識が必要なアプリに特に役立ちます。macOS、Windows、Linux をサポートしており、クロスプラットフォームのデスクトップ開発に適しています。パッケージは pub を通じて Flutter エコシステムとシームレスに統合されます。

用途

  • 時間追跡アプリケーション
  • 生産性と集中を高めるツール
  • ユーザー活動の監視
  • クロスプラットフォームデスクトップアプリ
  • コンテキスト対応アプリケーション

主な機能

  • アクティブなウィンドウタイトルをトラックする
  • ユーザーの非活動状態を監視する
  • macOS、Windows、Linux をサポートしています
  • 軽量で統合が簡単
  • リアルタイムでのウィンドウ状態の更新を提供します

適している対象

  • デスクトップアプリ開発者
  • 生産性ツールの作成者
  • タイムマネジメントソフトウェア
  • ユーザーのコンテキスト認識を必要とするアプリケーション
  • クロスプラットフォームデスクトッププロジェクト

注意事項

  • 一部のシステムでは、プラットフォーム固有の権限が必要です
  • macOS、Windows、Linux に限定
  • Linux で追加の構成が必要になる場合があります
  • モバイルプラットフォームでは利用できません
  • 機能の実現にネイティブシステムAPIに依存しています

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Window focus plugin

Language Versions

Usage_example

Pub

Window Focus is a Flutter plugin that allows you to track user activity and focus on the active window for Windows and macOS platforms. The plugin provides features such as detecting user inactivity, identifying the active application, and enabling debug mode for enhanced logging.

Key Features:

User Inactivity Tracking:

The plugin enables you to detect periods of user inactivity within your Flutter application. You can customize the inactivity threshold and handle inactivity events according to your needs.

Active Window Title Retrieval:

Provides the ability to retrieve the title of the active window of the operating system.

  • Windows: Full window title support.
  • macOS: Improved detection using CGWindowList. Supports capturing titles for the active process. Requires Screen Recording permission for accurate window titles.
Debug Mode

Enable detailed logs for troubleshooting during development.

Set Custom Idle Threshold

Define the timeout period after which the user is considered inactive.

Screenshot Capture

Capture the entire screen or just the active window. This is useful for time tracking applications.

Plugin Installation

Windows

No action required.

Mac OS

Setup for window focus tracking

You need to add the following code to the Info.plist file for MacOS:

<key>NSApplicationSupportsSecureRestorableState</key>
<true/>
Setup for screen recording (screenshots)

To use the screenshot functionality on macOS 10.15+, you must request screen recording permission. You can check the permission status using checkScreenRecordingPermission() and request it using requestScreenRecordingPermission().

The user must manually enable this in: System Preferences > Security & Privacy > Privacy > Screen Recording

Setup for Global Keyboard Tracking (macOS)

To track keyboard activity globally (outside the app) on macOS, the application requires Accessibility permissions. Crucial: Without these permissions, the plugin will only detect mouse movements and clicks outside the app, but keyboard events will be ignored for security reasons.

The user must manually enable this in: System Preferences > Security & Privacy > Privacy > Accessibility (Or System Settings > Privacy & Security > Accessibility on macOS Ventura and newer).

Plugin Usage

Import the plugin:

import 'package:window_focus/window_focus.dart';

Example

  void main() {
  final windowFocus = WindowFocus(debug: true, duration: Duration(seconds: 10));

  // Add focus change listener
  windowFocus.addFocusChangeListener((appWindow) {
    print('Active window: ${appWindow.appName}, Title: ${appWindow.windowTitle}');
  });

  // Add user activity listener
  windowFocus.addUserActiveListener((isActive) {
    if (isActive) {
      print('User is active');
    } else {
      print('User is inactive');
    }
  });
}

API Reference

Constructor

WindowFocus({bool debug = false, Duration duration = const Duration(seconds: 1)})
  • debug (optional): Enables debug mode for detailed logs.
  • duration (optional): Sets the user inactivity timeout. Default is 1 second.

Methods

Future setIdleThreshold(Duration duration)

Sets the threshold for detecting user inactivity.

  • Parameters:
    • duration: The duration after which the user is considered inactive.
    await windowFocus.setIdleThreshold(Duration(seconds: 15));
    
Future getIdleThreshold()

Gets the current idle threshold.

  • Returns: Duration - The currently set idle threshold.
final threshold = await windowFocus.getIdleThreshold();
print('Idle threshold: ${threshold.inSeconds} seconds');
void addFocusChangeListener(Function(AppWindowDto) listener)

Adds a listener for changes in the focused window.

  • Parameters:
    • listener: A callback function that receives an AppWindowDto object containing:
      • appName: The name of the active application.
      • windowTitle: The title of the active window.

Platform-specific Details

  • Windows:
    • appName is the name of the executable file (e.g., chrome.exe).
    • windowTitle is the title of the active window (e.g., Flutter Documentation).
  • macOS:
    • appName is the name of the active application (e.g., Safari).
    • windowTitle is the title of the active window (if available, otherwise same as appName). May require Screen Recording permission.
windowFocus.addFocusChangeListener((appWindow) {
  print('Active application: ${appWindow.appName}, Window title: ${appWindow.windowTitle}');
});
void addUserActiveListener(Function(bool) listener)

Adds a listener for user activity changes.

  • Parameters:
    • listener: A callback function that receives a bool indicating user activity (true for active, false for inactive).
windowFocus.addUserActiveListener((isActive) {
  if (isActive) {
    print('User is active');
  } else {
    print('User is inactive');
  }
});
Future setDebug(bool value)

Enables or disables debug mode.

  • Parameters:
    • value: true to enable debug mode, false to disable it.
await windowFocus.setDebug(true);
Future<Uint8List?> takeScreenshot({bool activeWindowOnly = false})

Takes a screenshot of the entire screen or just the active window.

  • Parameters:
    • activeWindowOnly: If true, captures only the currently focused window.
  • Returns: Future<Uint8List?> - PNG image data.
Uint8List? screenshot = await windowFocus.takeScreenshot(activeWindowOnly: true);
Future checkScreenRecordingPermission()

Checks if screen recording permission is granted (macOS).

Future requestScreenRecordingPermission()

Requests screen recording permission (macOS).

DTO: AppWindowDto

Represents the active application and window information.

Properties

  • appName: String - The name of the active application.
  • windowTitle: String - The title of the active window.

Example

final appWindow = AppWindowDto(appName: "Chrome", windowTitle: "Flutter Documentation");
print(appWindow); // Output: Window title: Flutter Documentation. AppName: Chrome

About the author

My telegram channel - @kotelnikoff_dev Contributions

Contributions are welcome! Feel free to open issues or create pull requests on the GitHub repository.

カテゴリー

依存関係

依存関係一覧 1 件

  • plugin_platform_interface^2.0.2

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。