🐛 Disable ipc rpc server on macos
This commit is contained in:
		| @@ -3,6 +3,7 @@ import 'dart:convert'; | |||||||
| import 'dart:developer' as developer; | import 'dart:developer' as developer; | ||||||
| import 'dart:io'; | import 'dart:io'; | ||||||
| import 'dart:typed_data'; | import 'dart:typed_data'; | ||||||
|  | import 'package:flutter/foundation.dart' show kReleaseMode; | ||||||
| import 'package:hooks_riverpod/hooks_riverpod.dart'; | import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||||||
| import 'package:shelf/shelf.dart'; | import 'package:shelf/shelf.dart'; | ||||||
| import 'package:shelf/shelf_io.dart' as shelf_io; | import 'package:shelf/shelf_io.dart' as shelf_io; | ||||||
| @@ -78,18 +79,37 @@ class ActivityRpcServer { | |||||||
|  |  | ||||||
|   // Find available IPC socket path |   // Find available IPC socket path | ||||||
|   Future<String> _findAvailableIpcPath() async { |   Future<String> _findAvailableIpcPath() async { | ||||||
|     final baseDirs = [ |     // Build list of directories to try, with macOS-specific handling | ||||||
|       if (Platform.isMacOS) await _getMacOsSystemTmpDir(), |     final baseDirs = <String>[]; | ||||||
|  |  | ||||||
|  |     if (Platform.isMacOS) { | ||||||
|  |       try { | ||||||
|  |         final macTempDir = await _getMacOsSystemTmpDir(); | ||||||
|  |         if (macTempDir.isNotEmpty) { | ||||||
|  |           baseDirs.add(macTempDir); | ||||||
|  |         } | ||||||
|  |       } catch (e) { | ||||||
|  |         developer.log( | ||||||
|  |           'Failed to get macOS system temp dir: $e', | ||||||
|  |           name: kRpcIpcLogPrefix, | ||||||
|  |         ); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     // Add other standard directories | ||||||
|  |     final otherDirs = [ | ||||||
|       Platform.environment['XDG_RUNTIME_DIR'], // User runtime directory |       Platform.environment['XDG_RUNTIME_DIR'], // User runtime directory | ||||||
|       Platform.environment['TMPDIR'], // App container temp (fallback) |       Platform.environment['TMPDIR'], // App container temp (fallback) | ||||||
|       Platform.environment['TMP'], |       Platform.environment['TMP'], | ||||||
|       Platform.environment['TEMP'], |       Platform.environment['TEMP'], | ||||||
|       '/temp', |  | ||||||
|       '/tmp', // System temp directory - most compatible |       '/tmp', // System temp directory - most compatible | ||||||
|     ]; |     ]; | ||||||
|  |  | ||||||
|  |     baseDirs.addAll( | ||||||
|  |       otherDirs.where((dir) => dir != null && dir.isNotEmpty).cast<String>(), | ||||||
|  |     ); | ||||||
|  |  | ||||||
|     for (final baseDir in baseDirs) { |     for (final baseDir in baseDirs) { | ||||||
|       if (baseDir == null || baseDir.isEmpty) continue; |  | ||||||
|       for (int i = 0; i < 10; i++) { |       for (int i = 0; i < 10; i++) { | ||||||
|         final socketPath = path.join(baseDir, '$kIpcBasePath-$i'); |         final socketPath = path.join(baseDir, '$kIpcBasePath-$i'); | ||||||
|         try { |         try { | ||||||
| @@ -173,21 +193,29 @@ class ActivityRpcServer { | |||||||
|       ); |       ); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // Start IPC server |     // Start IPC server (skip on macOS in production due to sandboxing) | ||||||
|     try { |     final shouldStartIpc = !(Platform.isMacOS && kReleaseMode); | ||||||
|       final ipcPath = await _findAvailableIpcPath(); |     if (shouldStartIpc) { | ||||||
|       _ipcServer = await ServerSocket.bind( |       try { | ||||||
|         InternetAddress(ipcPath, type: InternetAddressType.unix), |         final ipcPath = await _findAvailableIpcPath(); | ||||||
|         0, |         _ipcServer = await ServerSocket.bind( | ||||||
|       ); |           InternetAddress(ipcPath, type: InternetAddressType.unix), | ||||||
|       developer.log('IPC listening at $ipcPath', name: kRpcIpcLogPrefix); |           0, | ||||||
|  |         ); | ||||||
|  |         developer.log('IPC listening at $ipcPath', name: kRpcIpcLogPrefix); | ||||||
|  |  | ||||||
|       _ipcServer!.listen((Socket socket) { |         _ipcServer!.listen((Socket socket) { | ||||||
|         _onIpcConnection(socket); |           _onIpcConnection(socket); | ||||||
|       }); |         }); | ||||||
|     } catch (e) { |       } catch (e) { | ||||||
|       developer.log('IPC server error: $e', name: kRpcIpcLogPrefix); |         developer.log('IPC server error: $e', name: kRpcIpcLogPrefix); | ||||||
|       // Continue without IPC if it fails |         // Continue without IPC if it fails | ||||||
|  |       } | ||||||
|  |     } else { | ||||||
|  |       developer.log( | ||||||
|  |         'IPC server disabled on macOS in production mode due to sandboxing', | ||||||
|  |         name: kRpcIpcLogPrefix, | ||||||
|  |       ); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user