macos_window_toolkit 1.0.0
macos_window_toolkit: ^1.0.0 copied to clipboard
A Flutter plugin for macOS that provides window management functionality, allowing you to retrieve information about all open windows on the system.
macOS Window Toolkit #
A Flutter plugin for macOS that provides comprehensive window management functionality. This plugin allows Flutter applications to retrieve detailed information about all open windows on the macOS system, including window properties like title, bounds, owner application, and process ID.
Features #
- πͺ Window Enumeration: Get a list of all open windows on the system
- π Window Properties: Access detailed window information including:
- Window ID and title
- Owner application name
- Window bounds (position and size)
- Window layer level
- Visibility status
- Process ID
- π High Performance: Efficient native implementation using Core Graphics APIs
- π‘οΈ Privacy Compliant: Includes proper privacy manifest for App Store distribution
- π§ Easy Integration: Simple API with comprehensive error handling
Platform Support #
Platform | Support |
---|---|
macOS | β |
iOS | β |
Android | β |
Windows | β |
Linux | β |
Web | β |
Minimum Requirements:
- macOS 10.11 or later
- Flutter 3.3.0 or later
- Dart 3.8.1 or later
Installation #
Add this package to your pubspec.yaml
:
dependencies:
macos_window_toolkit: ^1.0.0
Then run:
flutter pub get
Quick Start #
import 'package:macos_window_toolkit/macos_window_toolkit.dart';
void main() async {
// Get all open windows
final windows = await MacosWindowToolkit.getAllWindows();
for (final window in windows) {
print('Window: ${window.name}');
print('App: ${window.ownerName}');
print('Bounds: ${window.bounds}');
print('---');
}
}
Usage #
Basic Window Enumeration #
import 'package:macos_window_toolkit/macos_window_toolkit.dart';
class WindowManager {
static Future<List<WindowInfo>> getVisibleWindows() async {
try {
final windows = await MacosWindowToolkit.getAllWindows();
return windows.where((window) => window.isOnScreen).toList();
} catch (e) {
print('Error getting windows: $e');
return [];
}
}
}
Window Information Structure #
Each window object contains the following properties:
class WindowInfo {
final int windowId; // Unique window identifier
final String name; // Window title
final String ownerName; // Application name that owns the window
final List<double> bounds; // [x, y, width, height]
final int layer; // Window layer level
final bool isOnScreen; // Whether window is visible
final int processId; // Process ID of the owning application
}
Filtering Windows #
// Filter by application
final chromeWindows = windows
.where((w) => w.ownerName.contains('Chrome'))
.toList();
// Filter by visibility
final visibleWindows = windows
.where((w) => w.isOnScreen)
.toList();
// Filter by size (width > 500px)
final largeWindows = windows
.where((w) => w.bounds[2] > 500)
.toList();
Error Handling #
try {
final windows = await MacosWindowToolkit.getAllWindows();
// Process windows
} on PlatformException catch (e) {
switch (e.code) {
case 'PERMISSION_DENIED':
print('Permission denied to access window information');
break;
case 'SYSTEM_ERROR':
print('System error occurred: ${e.message}');
break;
default:
print('Unknown error: ${e.message}');
}
} catch (e) {
print('Unexpected error: $e');
}
Example App #
The plugin includes a comprehensive example app that demonstrates all features:
cd example/
flutter run -d macos
The example app includes:
- Real-time window list updates
- Window search and filtering
- Detailed window information display
- Permission handling examples
Privacy and Permissions #
This plugin uses public macOS APIs that typically don't require explicit user permissions. However, some system configurations might require accessibility permissions for full functionality.
The plugin includes a privacy manifest (PrivacyInfo.xcprivacy
) that declares:
- No user data collection
- No tracking functionality
- No network requests
API Reference #
MacosWindowToolkit #
The main class providing window management functionality.
Methods
getAllWindows()
Returns a list of all open windows on the system.
Returns: Future<List<WindowInfo>>
Throws: PlatformException
if system error occurs
final windows = await MacosWindowToolkit.getAllWindows();
WindowInfo #
Data class representing a window's information.
Properties
Property | Type | Description |
---|---|---|
windowId |
int |
Unique system window identifier |
name |
String |
Window title or name |
ownerName |
String |
Name of the application that owns the window |
bounds |
List<double> |
Window bounds as [x, y, width, height] |
layer |
int |
Window layer level (higher = more front) |
isOnScreen |
bool |
Whether the window is currently visible |
processId |
int |
Process ID of the owning application |
Performance Considerations #
- Window enumeration is performed on-demand (not cached)
- Each call returns fresh system data
- Large numbers of windows may impact performance
- Consider implementing pagination for apps with many windows
Troubleshooting #
Common Issues #
- Empty window list: Check if other applications have windows open
- Permission errors: Verify system accessibility permissions if needed
- Build errors: Ensure minimum macOS version requirements are met
Debug Mode #
Enable verbose logging for debugging:
flutter run -d macos --verbose
Contributing #
Contributions are welcome! Please feel free to submit a Pull Request.
Development Setup #
- Fork the repository
- Clone your fork
- Create a feature branch
- Make your changes
- Run tests:
flutter test
- Submit a pull request
License #
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog #
See CHANGELOG.md for a detailed list of changes and version history.
Support #
- π Documentation
- π Issue Tracker
- π¬ Discussions
Made with β€οΈ for the Flutter community