| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of repositories; | 5 part of repositories; |
| 6 | 6 |
| 7 typedef bool IsConnectedVMTargetDelegate(Target); |
| 8 |
| 7 class TargetChangeEvent implements M.TargetChangeEvent { | 9 class TargetChangeEvent implements M.TargetChangeEvent { |
| 8 final TargetRepository repository; | 10 final TargetRepository repository; |
| 9 final bool disconnected; | 11 final bool disconnected; |
| 10 TargetChangeEvent(this.repository, [this.disconnected = false]); | 12 TargetChangeEvent(this.repository, [this.disconnected = false]); |
| 11 } | 13 } |
| 12 | 14 |
| 13 class TargetRepository implements M.TargetRepository { | 15 class TargetRepository implements M.TargetRepository { |
| 14 static const _historyKey = 'history'; | 16 static const _historyKey = 'history'; |
| 15 | 17 |
| 16 final StreamController<TargetChangeEvent> _onChange; | 18 final StreamController<TargetChangeEvent> _onChange; |
| 17 final Stream<TargetChangeEvent> onChange; | 19 final Stream<TargetChangeEvent> onChange; |
| 18 final SettingsRepository _settings = new SettingsRepository('targetManager'); | 20 final SettingsRepository _settings = new SettingsRepository('targetManager'); |
| 19 | 21 |
| 20 final List<SC.WebSocketVMTarget> _list = <SC.WebSocketVMTarget>[]; | 22 final List<SC.WebSocketVMTarget> _list = <SC.WebSocketVMTarget>[]; |
| 21 SC.WebSocketVMTarget current; | 23 SC.WebSocketVMTarget current; |
| 24 final IsConnectedVMTargetDelegate _isConnectedVMTarget; |
| 22 | 25 |
| 23 factory TargetRepository() { | 26 factory TargetRepository(IsConnectedVMTargetDelegate isConnectedVMTarget) { |
| 24 var controller = new StreamController<TargetChangeEvent>(); | 27 var controller = new StreamController<TargetChangeEvent>(); |
| 25 var stream = controller.stream.asBroadcastStream(); | 28 var stream = controller.stream.asBroadcastStream(); |
| 26 return new TargetRepository._(controller, stream); | 29 return new TargetRepository._(isConnectedVMTarget, controller, stream); |
| 27 } | 30 } |
| 28 | 31 |
| 29 TargetRepository._(this._onChange, this.onChange) { | 32 TargetRepository._(this._isConnectedVMTarget, this._onChange, this.onChange) { |
| 30 _restore(); | 33 _restore(); |
| 31 // Add the default address if it doesn't already exist. | 34 // Add the default address if it doesn't already exist. |
| 32 if (find(_networkAddressOfDefaultTarget()) == null) { | 35 if (find(_networkAddressOfDefaultTarget()) == null) { |
| 33 add(_networkAddressOfDefaultTarget()); | 36 add(_networkAddressOfDefaultTarget()); |
| 34 } | 37 } |
| 35 // Set the current target to the default target. | 38 // Set the current target to the default target. |
| 36 current = find(_networkAddressOfDefaultTarget()); | 39 current = find(_networkAddressOfDefaultTarget()); |
| 37 } | 40 } |
| 38 | 41 |
| 39 void add(String address) { | 42 void add(String address) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 104 } |
| 102 | 105 |
| 103 static String _networkAddressOfDefaultTarget() { | 106 static String _networkAddressOfDefaultTarget() { |
| 104 if (!identical(1, 1.0)) { | 107 if (!identical(1, 1.0)) { |
| 105 // Dartium, assume we are developing. | 108 // Dartium, assume we are developing. |
| 106 return 'ws://127.0.0.1:8181/ws'; | 109 return 'ws://127.0.0.1:8181/ws'; |
| 107 } | 110 } |
| 108 Uri serverAddress = Uri.parse(window.location.toString()); | 111 Uri serverAddress = Uri.parse(window.location.toString()); |
| 109 return 'ws://${serverAddress.authority}${serverAddress.path}ws'; | 112 return 'ws://${serverAddress.authority}${serverAddress.path}ws'; |
| 110 } | 113 } |
| 114 |
| 115 bool isConnectedVMTarget(M.Target target) => _isConnectedVMTarget(target); |
| 111 } | 116 } |
| OLD | NEW |