flutter_alone 1.0.0
flutter_alone: ^1.0.0 copied to clipboard
Flutter desktop application single instance plugin
flutter_alone #
A Flutter plugin to prevent duplicate execution of desktop applications.
Features #
- Prevent multiple instances of your Flutter desktop application
- Cross-user detection on Windows
- Safe resource cleanup
- System-wide mutex management
Platform Support #
| Windows | macOS | Linux |
|---|---|---|
| ✅ | 🚧 | 🚧 |
Getting started #
Add flutter_alone to your pubspec.yaml:
dependencies:
flutter_alone: ^1.0.0
Usage #
Import the package:
import 'package:flutter_alone/flutter_alone.dart';
Initialize in your main function:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final flutterAlone = FlutterAlone.instance;
final canRun = await flutterAlone.checkAndRun();
if (!canRun) {
// Another instance is already running
exit(0);
}
runApp(const MyApp());
}
Clean up resources when your app closes:
@override
void dispose() {
FlutterAlone.instance.dispose();
super.dispose();
}
Additional information #
Windows Implementation Details #
- Uses Windows Named Mutex for system-wide instance detection
- Supports cross-user detection through global mutex naming
- Proper cleanup of system resources
Contributing #
Feel free to contribute to this project.
- Fork it
- Create your feature branch (git checkout -b feature/fooBar)
- Commit your changes (git commit -am 'Add some fooBar')
- Push to the branch (git push origin feature/fooBar)
- Create a new Pull Request
License #
This project is licensed under the MIT License - see the LICENSE file for details