|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | +import 'dart:convert'; |
| 5 | + |
| 6 | +import 'utils.dart'; |
| 7 | + |
| 8 | +class MacOSInfo { |
| 9 | + /// Print information collected from the operating system. |
| 10 | + /// |
| 11 | + /// Built in tools such as `system_profiler` and `defaults` are utilized. |
| 12 | + Future<void> printInformation() async { |
| 13 | + try { |
| 14 | + await _printSafariApplications(); |
| 15 | + } catch (error) { |
| 16 | + print('Error thrown while getting Safari Applications: $error'); |
| 17 | + } |
| 18 | + |
| 19 | + try { |
| 20 | + await _printSafariDefaults(); |
| 21 | + } catch (error) { |
| 22 | + print('Error thrown while getting Safari defaults: $error'); |
| 23 | + } |
| 24 | + |
| 25 | + try { |
| 26 | + await _printUserLimits(); |
| 27 | + } catch (error) { |
| 28 | + print('Error thrown while getting user limits defaults: $error'); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + /// Print information on applications in the system that contains string |
| 33 | + /// `Safari`. |
| 34 | + Future<void> _printSafariApplications() async { |
| 35 | + final String systemProfileJson = await evalProcess( |
| 36 | + 'system_profiler', ['SPApplicationsDataType', '-json']); |
| 37 | + |
| 38 | + final Map<String, dynamic> json = |
| 39 | + jsonDecode(systemProfileJson) as Map<String, dynamic>; |
| 40 | + final List<dynamic> systemProfile = json.values.first as List<dynamic>; |
| 41 | + for (int i = 0; i < systemProfile.length; i++) { |
| 42 | + final Map<String, dynamic> application = |
| 43 | + systemProfile[i] as Map<String, dynamic>; |
| 44 | + final String applicationName = application['_name'] as String; |
| 45 | + if (applicationName.contains('Safari')) { |
| 46 | + print('application: $applicationName ' |
| 47 | + 'fullInfo: ${application.toString()}'); |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + /// Print all the defaults in the system related to Safari. |
| 53 | + Future<void> _printSafariDefaults() async { |
| 54 | + final String defaults = |
| 55 | + await evalProcess('/usr/bin/defaults', ['find', 'Safari']); |
| 56 | + |
| 57 | + print('Safari related defaults:\n $defaults'); |
| 58 | + } |
| 59 | + |
| 60 | + /// Print user limits (file and process). |
| 61 | + Future<void> _printUserLimits() async { |
| 62 | + final String fileLimit = await evalProcess('ulimit', ['-n']); |
| 63 | + |
| 64 | + print('MacOS file limit: $fileLimit'); |
| 65 | + |
| 66 | + final String processLimit = await evalProcess('ulimit', ['-u']); |
| 67 | + |
| 68 | + print('MacOS process limit: $processLimit'); |
| 69 | + } |
| 70 | +} |
0 commit comments