패키지, 저장소 및 앱 카테고리 검색

window_focus 표지
패키지 상세v1.2.1

window_focus

Window Focus는 Flutter용 편리한 플러그인으로, 사용자 무반응 상태를 추적하고 맥OS 및 윈도우에서 활성 창의 제목 정보를 얻을 수 있습니다.

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

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.