| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 app; | 5 part of app; |
| 6 | 6 |
| 7 /// The observatory application. Instances of this are created and owned | 7 /// The observatory application. Instances of this are created and owned |
| 8 /// by the observatory_application custom element. | 8 /// by the observatory_application custom element. |
| 9 class ObservatoryApplication { | 9 class ObservatoryApplication { |
| 10 static ObservatoryApplication app; | 10 static ObservatoryApplication app; |
| 11 final RenderingQueue queue = new RenderingQueue(); | 11 final RenderingQueue queue = new RenderingQueue(); |
| 12 final TargetRepository targets = new TargetRepository(); | 12 final TargetRepository targets = new TargetRepository(isConnectedVMTarget); |
| 13 final EventRepository events = new EventRepository(); | 13 final EventRepository events = new EventRepository(); |
| 14 final NotificationRepository notifications = new NotificationRepository(); | 14 final NotificationRepository notifications = new NotificationRepository(); |
| 15 final _pageRegistry = new List<Page>(); | 15 final _pageRegistry = new List<Page>(); |
| 16 LocationManager _locationManager; | 16 LocationManager _locationManager; |
| 17 LocationManager get locationManager => _locationManager; | 17 LocationManager get locationManager => _locationManager; |
| 18 Page currentPage; | 18 Page currentPage; |
| 19 bool _vmConnected = false; | 19 bool _vmConnected = false; |
| 20 VM _vm; | 20 VM _vm; |
| 21 VM get vm => _vm; | 21 VM get vm => _vm; |
| 22 | 22 |
| 23 bool isConnectedVMTarget(WebSocketVMTarget target) { | 23 static bool isConnectedVMTarget(WebSocketVMTarget target) { |
| 24 if (_vm is CommonWebSocketVM) { | 24 if (app._vm is CommonWebSocketVM) { |
| 25 if ((_vm as CommonWebSocketVM).target == target) { | 25 if ((app._vm as CommonWebSocketVM).target == target) { |
| 26 return _vm.isConnected; | 26 return app._vm.isConnected; |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 return false; | 29 return false; |
| 30 } | 30 } |
| 31 | 31 |
| 32 _switchVM(VM newVM) { | 32 _switchVM(VM newVM) { |
| 33 final VM oldVM = _vm; | 33 final VM oldVM = _vm; |
| 34 | 34 |
| 35 Logger.root.info('_switchVM from:${oldVM} to:${newVM}'); | 35 Logger.root.info('_switchVM from:${oldVM} to:${newVM}'); |
| 36 | 36 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 228 |
| 229 ObservatoryApplication(this.rootElement) { | 229 ObservatoryApplication(this.rootElement) { |
| 230 _locationManager = new LocationManager(this); | 230 _locationManager = new LocationManager(this); |
| 231 targets.onChange.listen((TargetChangeEvent e) { | 231 targets.onChange.listen((TargetChangeEvent e) { |
| 232 if (e.disconnected) { | 232 if (e.disconnected) { |
| 233 // We don't care about disconnected events. | 233 // We don't care about disconnected events. |
| 234 return; | 234 return; |
| 235 } | 235 } |
| 236 if (targets.current == null) { | 236 if (targets.current == null) { |
| 237 _switchVM(null); | 237 _switchVM(null); |
| 238 } | 238 } else { |
| 239 final bool currentTarget = | 239 final bool currentTarget = |
| 240 (_vm as WebSocketVM)?.target == targets.current; | 240 (_vm as WebSocketVM)?.target == targets.current; |
| 241 final bool currentTargetConnected = (_vm != null) && !_vm.isDisconnected; | 241 final bool currentTargetConnected = (_vm != null) && _vm.isConnected; |
| 242 if (!currentTarget || !currentTargetConnected) { | 242 if (!currentTarget || !currentTargetConnected) { |
| 243 _switchVM(new WebSocketVM(targets.current)); | 243 _switchVM(new WebSocketVM(targets.current)); |
| 244 app.locationManager.go(Uris.vm()); | 244 _vm.onConnect.then((_) { |
| 245 app.locationManager.go(Uris.vm()); |
| 246 }); |
| 247 } else if (currentTargetConnected) { |
| 248 app.locationManager.go(Uris.vm()); |
| 249 } |
| 245 } | 250 } |
| 246 }); | 251 }); |
| 247 | 252 |
| 248 Logger.root.info('Setting initial target to ${targets.current.name}'); | 253 Logger.root.info('Setting initial target to ${targets.current.name}'); |
| 249 _switchVM(new WebSocketVM(targets.current)); | 254 _switchVM(new WebSocketVM(targets.current)); |
| 250 _initOnce(); | 255 _initOnce(); |
| 251 | 256 |
| 252 // delete pause events. | 257 // delete pause events. |
| 253 events.onIsolateExit.listen(_deletePauseEvents); | 258 events.onIsolateExit.listen(_deletePauseEvents); |
| 254 events.onResume.listen(_deletePauseEvents); | 259 events.onResume.listen(_deletePauseEvents); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 282 } | 287 } |
| 283 | 288 |
| 284 // TODO(turnidge): Report this failure via analytics. | 289 // TODO(turnidge): Report this failure via analytics. |
| 285 Logger.root.warning('Caught exception: ${e}\n${st}'); | 290 Logger.root.warning('Caught exception: ${e}\n${st}'); |
| 286 notifications.add(new ExceptionNotification(e, stacktrace: st)); | 291 notifications.add(new ExceptionNotification(e, stacktrace: st)); |
| 287 } | 292 } |
| 288 | 293 |
| 289 // This map keeps track of which curly-blocks have been expanded by the user. | 294 // This map keeps track of which curly-blocks have been expanded by the user. |
| 290 Map<String, bool> expansions = {}; | 295 Map<String, bool> expansions = {}; |
| 291 } | 296 } |
| OLD | NEW |