Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arran4/dart_unix_single_instance
A library which uses unix sockets to ensure a single instance
https://github.com/arran4/dart_unix_single_instance
dart dart-library dartlang flutter flutter-library library single-instance unix
Last synced: about 2 months ago
JSON representation
A library which uses unix sockets to ensure a single instance
- Host: GitHub
- URL: https://github.com/arran4/dart_unix_single_instance
- Owner: arran4
- License: mit
- Created: 2024-04-29T03:22:40.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-06-21T01:11:49.000Z (7 months ago)
- Last Synced: 2024-10-13T08:41:23.936Z (3 months ago)
- Topics: dart, dart-library, dartlang, flutter, flutter-library, library, single-instance, unix
- Language: Dart
- Homepage: https://pub.dev/packages/unix_single_instance
- Size: 36.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-flutter-desktop - unix_single_instance - A library which uses unix sockets to ensure a single instance (Packages)
README
# Unix Single Instance
Restrict a Linux or Mac OS X app to only be able to open one instance at a time. (Currently per user)
This uses Unix sockets to ensure a single instance. There are other ways of doing this however this was
the most "portable." For windows support cosnider adding: windows_single_instancehttps://pub.dev/packages/unix_single_instance
## Installing
1. Add the `async` modifier to your apps `main` function.
1. Write a function `cmdProcessor(List decodedArgs)` which re-processes command line options
1. Add a call to `unixSingleInstance()` inside the appropriate conditions. Placement in the main function
to taste.## Notes
If using flutter, recommend using this with the: `window_manager` plugin
### Future expansion
Currently it is on a per-user basis and ignores multiple displays. It could be greatly improved with
options which allow you to toggle if it's per X, per user, etc. (If per X and per user and for linux only
consider using dbus -- not a strong recommendation.)## Example
```
import 'package:unix_single_instance/unix_single_instance.dart';void main(List args) async {
WidgetsFlutterBinding.ensureInitialized();
if (Platform.isLinux) {
if (!await unixSingleInstance(arguments, cmdProcessor)) {
exit(0);
return;
}
} else if (Platform.isMacOS) {
if (!await unixSingleInstance(arguments, cmdProcessor)) {
exit(0);
return;
}
}
runApp(const MyApp());
}void cmdProcessor(List decodedArgs) {
if (decodedArgs.isEmpty && !Platform.isWindows) {
windowManager.waitUntilReadyToShow(null, () async {
await windowManager.show();
await windowManager.focus();
});
}
for (var each in decodedArgs) {
if (each is! String) {
continue;
}
doSomethingWithThis(each);
}
}```