Compare commits
2 Commits
8578cde620
...
be414891ec
Author | SHA1 | Date | |
---|---|---|---|
be414891ec | |||
787876ab6a |
@@ -68,37 +68,6 @@ class UnixIpcServer extends IpcServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle IPC handshake
|
|
||||||
void _onIpcHandshake(
|
|
||||||
IpcSocketWrapper socket,
|
|
||||||
Map<String, dynamic> params,
|
|
||||||
Map<String, Function> handlers,
|
|
||||||
) {
|
|
||||||
developer.log('IPC handshake: $params', name: kRpcIpcLogPrefix);
|
|
||||||
|
|
||||||
final ver = int.tryParse(params['v']?.toString() ?? '1') ?? 1;
|
|
||||||
final clientId = params['client_id']?.toString() ?? '';
|
|
||||||
|
|
||||||
if (ver != 1) {
|
|
||||||
developer.log(
|
|
||||||
'IPC unsupported version requested: $ver',
|
|
||||||
name: kRpcIpcLogPrefix,
|
|
||||||
);
|
|
||||||
socket.closeWithCode(IpcErrorCodes.invalidVersion);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clientId.isEmpty) {
|
|
||||||
developer.log('IPC client ID required', name: kRpcIpcLogPrefix);
|
|
||||||
socket.closeWithCode(IpcErrorCodes.invalidClientId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
socket.clientId = clientId;
|
|
||||||
|
|
||||||
handlers['connection']?.call(socket);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<String> _getMacOsSystemTmpDir() async {
|
Future<String> _getMacOsSystemTmpDir() async {
|
||||||
final result = await Process.run('getconf', ['DARWIN_USER_TEMP_DIR']);
|
final result = await Process.run('getconf', ['DARWIN_USER_TEMP_DIR']);
|
||||||
return (result.stdout as String).trim();
|
return (result.stdout as String).trim();
|
||||||
|
@@ -13,7 +13,7 @@ class WindowsIpcServer extends IpcServer {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> start() async {
|
Future<void> start() async {
|
||||||
final pipeName = r'\\.\pipe\discord-ipc'.toNativeUtf16();
|
final pipeName = r'\\.\pipe\discord-ipc-0'.toNativeUtf16();
|
||||||
try {
|
try {
|
||||||
_pipeHandle = CreateNamedPipe(
|
_pipeHandle = CreateNamedPipe(
|
||||||
pipeName,
|
pipeName,
|
||||||
@@ -32,7 +32,7 @@ class WindowsIpcServer extends IpcServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
developer.log(
|
developer.log(
|
||||||
'IPC named pipe created at \\\\.\\pipe\\discord-ipc',
|
r'IPC named pipe created at \\.\pipe\discord-ipc-0',
|
||||||
name: kRpcIpcLogPrefix,
|
name: kRpcIpcLogPrefix,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -71,6 +71,7 @@ class WindowsIpcServer extends IpcServer {
|
|||||||
await Isolate.spawn(_windowsIpcIsolate, receivePort.sendPort);
|
await Isolate.spawn(_windowsIpcIsolate, receivePort.sendPort);
|
||||||
|
|
||||||
receivePort.listen((message) {
|
receivePort.listen((message) {
|
||||||
|
developer.log(message.toString(), name: kRpcIpcLogPrefix);
|
||||||
if (message is int) {
|
if (message is int) {
|
||||||
final socketWrapper = WindowsIpcSocketWrapper(message);
|
final socketWrapper = WindowsIpcSocketWrapper(message);
|
||||||
addSocket(socketWrapper);
|
addSocket(socketWrapper);
|
||||||
@@ -87,7 +88,7 @@ class WindowsIpcServer extends IpcServer {
|
|||||||
static void _windowsIpcIsolate(SendPort sendPort) {
|
static void _windowsIpcIsolate(SendPort sendPort) {
|
||||||
while (true) {
|
while (true) {
|
||||||
final pipeHandle = CreateNamedPipe(
|
final pipeHandle = CreateNamedPipe(
|
||||||
r'\\.\pipe\discord-ipc'.toNativeUtf16(),
|
r'\\.\pipe\discord-ipc-0'.toNativeUtf16(),
|
||||||
PIPE_ACCESS_DUPLEX,
|
PIPE_ACCESS_DUPLEX,
|
||||||
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
|
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
|
||||||
PIPE_UNLIMITED_INSTANCES,
|
PIPE_UNLIMITED_INSTANCES,
|
||||||
@@ -108,7 +109,7 @@ class WindowsIpcServer extends IpcServer {
|
|||||||
sendPort.send(pipeHandle);
|
sendPort.send(pipeHandle);
|
||||||
}
|
}
|
||||||
// Avoid tight loop
|
// Avoid tight loop
|
||||||
sleep(Duration(milliseconds: 100));
|
sleep(Duration(milliseconds: 500));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,37 +164,6 @@ class WindowsIpcServer extends IpcServer {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle IPC handshake
|
|
||||||
void _onIpcHandshake(
|
|
||||||
IpcSocketWrapper socket,
|
|
||||||
Map<String, dynamic> params,
|
|
||||||
Map<String, Function> handlers,
|
|
||||||
) {
|
|
||||||
developer.log('IPC handshake: $params', name: kRpcIpcLogPrefix);
|
|
||||||
|
|
||||||
final ver = int.tryParse(params['v']?.toString() ?? '1') ?? 1;
|
|
||||||
final clientId = params['client_id']?.toString() ?? '';
|
|
||||||
|
|
||||||
if (ver != 1) {
|
|
||||||
developer.log(
|
|
||||||
'IPC unsupported version requested: $ver',
|
|
||||||
name: kRpcIpcLogPrefix,
|
|
||||||
);
|
|
||||||
socket.closeWithCode(IpcErrorCodes.invalidVersion);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clientId.isEmpty) {
|
|
||||||
developer.log('IPC client ID required', name: kRpcIpcLogPrefix);
|
|
||||||
socket.closeWithCode(IpcErrorCodes.invalidClientId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
socket.clientId = clientId;
|
|
||||||
|
|
||||||
handlers['connection']?.call(socket);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class WindowsIpcSocketWrapper extends IpcSocketWrapper {
|
class WindowsIpcSocketWrapper extends IpcSocketWrapper {
|
||||||
|
Reference in New Issue
Block a user