Index: runtime/observatory/lib/src/repositories/target.dart |
diff --git a/runtime/observatory/lib/src/repositories/target.dart b/runtime/observatory/lib/src/repositories/target.dart |
index ec52128d96ea272456ef43d399590a9d9e8057fb..bb011600039f690113782b79570a3276326593bf 100644 |
--- a/runtime/observatory/lib/src/repositories/target.dart |
+++ b/runtime/observatory/lib/src/repositories/target.dart |
@@ -6,7 +6,8 @@ part of repositories; |
class TargetChangeEvent implements M.TargetChangeEvent { |
final TargetRepository repository; |
- TargetChangeEvent(this.repository); |
+ final bool disconnected; |
+ TargetChangeEvent(this.repository, [this.disconnected = false]); |
} |
class TargetRepository implements M.TargetRepository { |
@@ -28,14 +29,18 @@ class TargetRepository implements M.TargetRepository { |
TargetRepository._(this._onChange, this.onChange) { |
_restore(); |
- if (_list.isEmpty) { |
- _list.add(new SC.WebSocketVMTarget(_networkAddressOfDefaultTarget())); |
+ // Add the default address if it doesn't already exist. |
+ if (_find(_networkAddressOfDefaultTarget()) == null) { |
+ add(_networkAddressOfDefaultTarget()); |
} |
- current = _list.first; |
+ // Set the current target to the default target. |
+ current = _find(_networkAddressOfDefaultTarget()); |
} |
void add(String address) { |
- if (_find(address) != null) return; |
+ if (_find(address) != null) { |
+ return; |
+ } |
_list.insert(0, new SC.WebSocketVMTarget(address)); |
_onChange.add(new TargetChangeEvent(this)); |
_store(); |
@@ -45,13 +50,19 @@ class TargetRepository implements M.TargetRepository { |
void setCurrent(M.Target t) { |
SC.WebSocketVMTarget target = t as SC.WebSocketVMTarget; |
- if (!_list.contains(target)) return; |
+ if (!_list.contains(target)) { |
+ return; |
+ } |
current = target; |
current.lastConnectionTime = new DateTime.now().millisecondsSinceEpoch; |
_onChange.add(new TargetChangeEvent(this)); |
_store(); |
} |
+ void emitDisconnectEvent() { |
+ _onChange.add(new TargetChangeEvent(this, true)); |
+ } |
+ |
void delete(o) { |
if (_list.remove(o)) { |
if (o == current) { |