Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3b32c07

Browse files
committed
Show error on macOS if missing Local Network permissions
1 parent9bf4e89 commit3b32c07

File tree

2 files changed

+80
-33
lines changed

2 files changed

+80
-33
lines changed

‎packages/flutter_tools/lib/src/mdns_discovery.dart‎

Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class MDnsVmServiceDiscovery {
9696
finalList<MDnsVmServiceDiscoveryResult> results=await_pollingVmService(
9797
_preliminaryClient??MDnsClient(),
9898
applicationId: applicationId,
99-
deviceVmservicePort: deviceVmservicePort,
99+
deviceVmServicePort: deviceVmservicePort,
100100
ipv6: ipv6,
101101
useDeviceIPAsHost: useDeviceIPAsHost,
102102
timeout:constDuration(seconds:5),
@@ -192,7 +192,7 @@ class MDnsVmServiceDiscovery {
192192
finalList<MDnsVmServiceDiscoveryResult> results=await_pollingVmService(
193193
client,
194194
applicationId: applicationId,
195-
deviceVmservicePort: deviceVmservicePort,
195+
deviceVmServicePort: deviceVmservicePort,
196196
deviceName: deviceName,
197197
ipv6: ipv6,
198198
useDeviceIPAsHost: useDeviceIPAsHost,
@@ -208,7 +208,67 @@ class MDnsVmServiceDiscovery {
208208
Future<List<MDnsVmServiceDiscoveryResult>>_pollingVmService(
209209
MDnsClient client, {
210210
String? applicationId,
211-
int? deviceVmservicePort,
211+
int? deviceVmServicePort,
212+
String? deviceName,
213+
bool ipv6=false,
214+
bool useDeviceIPAsHost=false,
215+
requiredDuration timeout,
216+
bool quitOnFind=false,
217+
})async {
218+
finalCompleter<List<MDnsVmServiceDiscoveryResult>> completer=
219+
Completer<List<MDnsVmServiceDiscoveryResult>>();
220+
unawaited(
221+
runZonedGuarded(
222+
()async {
223+
completer.complete(
224+
await_doPollingVmService(
225+
client,
226+
applicationId: applicationId,
227+
deviceVmServicePort: deviceVmServicePort,
228+
deviceName: deviceName,
229+
ipv6: ipv6,
230+
useDeviceIPAsHost: useDeviceIPAsHost,
231+
timeout: timeout,
232+
quitOnFind: quitOnFind,
233+
),
234+
);
235+
},
236+
(Object error,StackTrace stackTrace) {
237+
if (!completer.isCompleted) {
238+
completer.completeError(error, stackTrace);
239+
}
240+
},
241+
),
242+
);
243+
244+
try {
245+
returnawait completer.future;
246+
}onSocketExceptioncatch (e, stackTrace) {
247+
if (!globals.platform.isMacOS) {
248+
rethrow;
249+
}
250+
251+
_logger.printTrace(stackTrace.toString());
252+
253+
throwToolExit(
254+
'Flutter could not connect to the Dart VM service.\n'
255+
'\n'
256+
'Please ensure your IDE or terminal app has permission to access '
257+
'devices on the local network. This allows Flutter to connect to '
258+
'the Dart VM.\n'
259+
'\n'
260+
'You can grant this permission in System Settings > Privacy & '
261+
'Security > Local Network.\n'
262+
'\n'
263+
'$e'
264+
);
265+
}
266+
}
267+
268+
Future<List<MDnsVmServiceDiscoveryResult>>_doPollingVmService(
269+
MDnsClient client, {
270+
String? applicationId,
271+
int? deviceVmServicePort,
212272
String? deviceName,
213273
bool ipv6=false,
214274
bool useDeviceIPAsHost=false,
@@ -232,27 +292,10 @@ class MDnsVmServiceDiscovery {
232292
finalSet<String> uniqueDomainNamesInResults=<String>{};
233293

234294
// Listen for mDNS connections until timeout.
235-
finalStream<PtrResourceRecord> ptrResourceStream;
236-
237-
try {
238-
ptrResourceStream= client.lookup<PtrResourceRecord>(
239-
ResourceRecordQuery.serverPointer(dartVmServiceName),
240-
timeout: timeout,
241-
);
242-
}onSocketExceptioncatch (e, stacktrace) {
243-
_logger.printError(e.message);
244-
_logger.printTrace(stacktrace.toString());
245-
if (globals.platform.isMacOS) {
246-
throwToolExit(
247-
'You might be having a permissions issue with your IDE. '
248-
'Please try going to '
249-
'System Settings -> Privacy & Security -> Local Network -> '
250-
'[Find your IDE] -> Toggle ON, then restart your phone.',
251-
);
252-
}else {
253-
rethrow;
254-
}
255-
}
295+
finalStream<PtrResourceRecord> ptrResourceStream= client.lookup<PtrResourceRecord>(
296+
ResourceRecordQuery.serverPointer(dartVmServiceName),
297+
timeout: timeout,
298+
);
256299

257300
awaitfor (finalPtrResourceRecord ptrin ptrResourceStream) {
258301
uniqueDomainNames.add(ptr.domainName);
@@ -292,8 +335,8 @@ class MDnsVmServiceDiscovery {
292335
);
293336
}
294337

295-
// IfdeviceVmservicePort is set, only use records that match it
296-
if (deviceVmservicePort!=null&& srvRecord.port!=deviceVmservicePort) {
338+
// IfdeviceVmServicePort is set, only use records that match it
339+
if (deviceVmServicePort!=null&& srvRecord.port!=deviceVmServicePort) {
297340
continue;
298341
}
299342

@@ -355,8 +398,8 @@ class MDnsVmServiceDiscovery {
355398
// the applicationId were found but other results were found, throw an error.
356399
if (applicationId!=null&& quitOnFind&& results.isEmpty&& uniqueDomainNames.isNotEmpty) {
357400
String message='Did not find a Dart VM Service advertised for $applicationId';
358-
if (deviceVmservicePort!=null) {
359-
message+=' on port $deviceVmservicePort';
401+
if (deviceVmServicePort!=null) {
402+
message+=' on port $deviceVmServicePort';
360403
}
361404
throwToolExit('$message.');
362405
}

‎packages/flutter_tools/test/general.shard/mdns_discovery_test.dart‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ void main() {
329329
flutterUsage:TestUsage(),
330330
analytics:constNoOpAnalytics(),
331331
);
332-
expect(()async=>portDiscovery.queryForAttach(), throwsException);
332+
expect(portDiscovery.queryForAttach(), throwsException);
333333
});
334334

335335
testWithoutContext('Correctly builds VM Service URI with hostVmservicePort == 0', ()async {
@@ -630,10 +630,14 @@ void main() {
630630
portDiscovery.firstMatchingVmService(client),
631631
throwsToolExit(
632632
message:
633-
'You might be having a permissions issue with your IDE. '
634-
'Please try going to '
635-
'System Settings -> Privacy & Security -> Local Network -> '
636-
'[Find your IDE] -> Toggle ON, then restart your phone.',
633+
'Flutter could not connect to the Dart VM service.\n'
634+
'\n'
635+
'Please ensure your IDE or terminal app has permission to access '
636+
'devices on the local network. This allows Flutter to connect to '
637+
'the Dart VM.\n'
638+
'\n'
639+
'You can grant this permission in System Settings > Privacy & '
640+
'Security > Local Network.\n',
637641
),
638642
);
639643
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp