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/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:umbrix/bootstrap.dart';
|
import 'package:umbrix/bootstrap.dart';
|
||||||
import 'package:umbrix/core/model/environment.dart';
|
import 'package:umbrix/core/model/environment.dart';
|
||||||
|
|
||||||
void main() async {
|
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();
|
final widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||||
|
|||||||
@@ -108,8 +108,9 @@ install(CODE "
|
|||||||
set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
|
set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
|
||||||
set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
|
set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
|
||||||
|
|
||||||
install(FILES "../libcore/bin/lib/libcore.so" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
|
# Libcore is copied by build script, not cmake
|
||||||
COMPONENT Runtime)
|
# install(FILES "../libcore/bin/lib/libcore.so" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
|
||||||
|
# COMPONENT Runtime)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
FILES "../libcore/bin/HiddifyCli"
|
FILES "../libcore/bin/HiddifyCli"
|
||||||
|
|||||||
@@ -137,6 +137,6 @@ MyApplication *my_application_new()
|
|||||||
{
|
{
|
||||||
return MY_APPLICATION(g_object_new(my_application_get_type(),
|
return MY_APPLICATION(g_object_new(my_application_get_type(),
|
||||||
"application-id", APPLICATION_ID,
|
"application-id", APPLICATION_ID,
|
||||||
"flags", G_APPLICATION_DEFAULT_FLAGS,
|
"flags", G_APPLICATION_NON_UNIQUE,
|
||||||
nullptr));
|
nullptr));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user