flutter_alone 2.0.0 copy "flutter_alone: ^2.0.0" to clipboard
flutter_alone: ^2.0.0 copied to clipboard

A Flutter plugin for preventing duplicate execution of desktop applications with customizable message support and cross-user detection

flutter_alone #

A robust Flutter plugin for preventing duplicate execution of desktop applications, offering advanced process management and cross-user detection.

pub package

Features #

  • Duplicate Execution Prevention

    • System-wide mutex management
    • Cross-user account detection
    • Process-level duplicate checking
  • Window Management

    • Automatic window focusing
    • Window restoration handling
    • Bring to front functionality
  • Customizable Messaging

    • Multi-language support (English/Korean)
    • Custom message templates
    • Configurable message box display
    • UTF-8 text encoding support
  • Process Management

    • Detailed process information tracking
    • Safe resource cleanup
    • Robust error handling

Platform Support #

Windows macOS Linux
🚧 🚧

Getting Started #

Add flutter_alone to your pubspec.yaml:

dependencies:
  flutter_alone: ^2.0.0

Usage #

Import the package:

import 'package:flutter_alone/flutter_alone.dart';

Basic Usage with Default Settings #

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  if (!await FlutterAlone.instance.checkAndRun()) {  // Uses EnMessageConfig by default
    exit(0);
  }
  
  runApp(const MyApp());
}

Using Korean Messages #

if (!await FlutterAlone.instance.checkAndRun(
  messageConfig: const KoMessageConfig(),
)) {
  exit(0);
}

Custom Message Configuration #

final messageConfig = CustomMessageConfig(
  customTitle: 'Application Notice',
  customMessage: 'Application is already running',
  showMessageBox: true,  // Optional, defaults to true
);

if (!await FlutterAlone.instance.checkAndRun(messageConfig: messageConfig)) {
  exit(0);
}

Resource Cleanup #

Always remember to dispose of resources when your application closes:

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void dispose() {
    FlutterAlone.instance.dispose();
    super.dispose();
  }

  // ... rest of your widget implementation
}

Advanced Features #

Message Configuration Classes #

The plugin provides three types of message configurations:

  • EnMessageConfig: Default English messages
  • KoMessageConfig: Korean messages
  • CustomMessageConfig: Custom messages with template support

Windows Implementation Details #

  • Uses Windows Named Mutex for system-wide instance detection
  • Implements robust cross-user detection through global mutex naming
  • Ensures proper cleanup of system resources
  • Full Unicode support for international character sets
  • Advanced window management capabilities

Error Handling #

The plugin provides detailed error information through the AloneException class:

try {
  await FlutterAlone.instance.checkAndRun();
} on AloneException catch (e) {
  print('Error Code: ${e.code}');
  print('Message: ${e.message}');
  print('Details: ${e.details}');
}

Contributing #

Contributions are welcome! Please read our contributing guidelines before submitting pull requests.

2
likes
0
points
32
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for preventing duplicate execution of desktop applications with customizable message support and cross-user detection

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_alone

Packages that implement flutter_alone