fix: single instance with lock file only
This commit is contained in:
@@ -1,9 +1,44 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:umbrix/bootstrap.dart';
|
||||
import 'package:umbrix/core/model/environment.dart';
|
||||
|
||||
void main() async {
|
||||
// Single instance check - BEFORE Flutter initialization
|
||||
if (Platform.isLinux || Platform.isWindows) {
|
||||
final lockFile = File('/tmp/umbrix.lock');
|
||||
|
||||
if (await lockFile.exists()) {
|
||||
try {
|
||||
final pidString = await lockFile.readAsString();
|
||||
final pid = int.tryParse(pidString.trim());
|
||||
|
||||
if (pid != null) {
|
||||
// Check if process is still alive
|
||||
final result = await Process.run('ps', ['-p', pid.toString()]);
|
||||
|
||||
if (result.exitCode == 0) {
|
||||
// Process alive - just exit without trying to activate
|
||||
print('Umbrix уже запущен');
|
||||
exit(0);
|
||||
} else {
|
||||
// Stale lock - remove it
|
||||
await lockFile.delete();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
try { await lockFile.delete(); } catch (_) {}
|
||||
}
|
||||
}
|
||||
|
||||
// Create lock file with current PID
|
||||
try {
|
||||
await lockFile.create();
|
||||
await lockFile.writeAsString(pid.toString());
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
final widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
|
||||
Reference in New Issue
Block a user