Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bootstrap): don't check for updates in _initInstallerApp #592

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/ubuntu_bootstrap/lib/installer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ Future<void> _initInstallerApp(Endpoint endpoint) async {
final services = [
getService<InstallerService>().init(),
tryGetService<DesktopService>()?.inhibit() ?? Future.value(),
getService<RefreshService>().check(),
getService<PageConfigService>().load(),
geo.init(),
telemetry.init({
Expand Down
11 changes: 1 addition & 10 deletions packages/ubuntu_bootstrap/lib/installer/installer_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,25 @@ final restartProvider = StateProvider((_) => 0);
final installerModelProvider = ChangeNotifierProvider.autoDispose(
(_) => InstallerModel(
getService<InstallerService>(),
getService<RefreshService>(),
),
);

class InstallerModel extends SafeChangeNotifier {
InstallerModel(this._installer, this._refresh);
InstallerModel(this._installer);

final InstallerService _installer;
final RefreshService _refresh;

ApplicationStatus? _status;
StreamSubscription<ApplicationStatus?>? _statusChange;
StreamSubscription<RefreshState>? _refreshChange;

ApplicationStatus? get status => _status;
bool get isInstalling => status?.isInstalling ?? false;
bool get isRefreshing => _refresh.state.busy;

Future<void> init() async {
_statusChange = _installer.monitorStatus().listen((status) {
_status = status;
notifyListeners();
});
_refreshChange = _refresh.stateChanged.listen((_) {
notifyListeners();
});
}

bool hasRoute(String route) => _installer.hasRoute(route);
Expand All @@ -44,8 +37,6 @@ class InstallerModel extends SafeChangeNotifier {
Future<void> dispose() async {
await _statusChange?.cancel();
_statusChange = null;
await _refreshChange?.cancel();
_refreshChange = null;
super.dispose();
}
}
13 changes: 2 additions & 11 deletions packages/ubuntu_bootstrap/test/installer_model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,31 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:subiquity_client/subiquity_client.dart';
import 'package:ubuntu_bootstrap/installer/installer_model.dart';
import 'package:ubuntu_bootstrap/services/refresh_service.dart';

import 'test_utils.dart';

void main() {
test('init', () async {
final statusController = StreamController<ApplicationStatus>();
final refreshController = StreamController<RefreshState>();

final installer = MockInstallerService();
when(installer.monitorStatus()).thenAnswer((_) => statusController.stream);

final refresh = MockRefreshService();
when(refresh.state).thenReturn(const RefreshState.checking());
when(refresh.stateChanged).thenAnswer((_) => refreshController.stream);

final model = InstallerModel(installer, refresh);
final model = InstallerModel(installer);
await model.init();
verify(installer.monitorStatus()).called(1);
expect(statusController.hasListener, isTrue);
verify(refresh.stateChanged).called(1);
expect(refreshController.hasListener, isTrue);

await model.dispose();
expect(statusController.hasListener, isFalse);
expect(refreshController.hasListener, isFalse);
});

test('has route', () async {
final installer = MockInstallerService();
when(installer.hasRoute('a')).thenReturn(true);
when(installer.hasRoute('b')).thenReturn(false);

final model = InstallerModel(installer, MockRefreshService());
final model = InstallerModel(installer);

expect(model.hasRoute('a'), isTrue);
expect(model.hasRoute('b'), isFalse);
Expand Down