Skip to content

Commit

Permalink
Merge pull request #592 from d-loose/no-refresh-on-loading
Browse files Browse the repository at this point in the history
feat(bootstrap): don't check for updates in `_initInstallerApp`
  • Loading branch information
d-loose authored and GitHub Actions committed Apr 5, 2024
2 parents bf41bd2 + 3f5a9d6 commit cb19807
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 22 deletions.
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
12 changes: 12 additions & 0 deletions snap/local/ubuntu-desktop-init.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Desktop Entry]
Name=Ubuntu Desktop Init
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
Icon=preferences-system
Exec=ubuntu-desktop-init
Terminal=false
Type=Application
StartupNotify=true
Categories=GNOME;GTK;System;
OnlyShowIn=GNOME;Unity;
NoDisplay=true
X-GNOME-HiddenUnderSystemd=true
115 changes: 115 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: ubuntu-desktop-init
version: git
summary: Ubuntu Desktop Init
description: |
A first boot initialisation wizard for new Ubuntu and variants.
It comprises a Flutter-based UI and a go backend packaged separately as a deb.
grade: stable
confinement: strict
base: core22
architectures:
- build-on: amd64
- build-on: arm64

apps:
ubuntu-desktop-init:
command: bin/ubuntu_init
extensions: [gnome]
desktop: usr/share/applications/ubuntu-desktop-init.desktop
environment:
LOG_LEVEL: debug
plugs:
- usr-share-desktop-provision
- run-provd-socket
- network
- network-manager
- tmp
- var-log-installer

parts:
flutter-git:
plugin: nil
source: .
override-pull: |
# necessary when reruns using the same container
if [ -d "flutter" ]; then
rm -rf "flutter"
fi
craftctl default
FLUTTER_VERSION=$(sed -n "s/^flutter \([0-9.]\+\).*/\1/p" .tool-versions)
git clone -b $FLUTTER_VERSION --depth 1 https://github.com/flutter/flutter.git
override-build: |
mkdir -p $CRAFT_PART_INSTALL/usr/bin
mkdir -p $CRAFT_PART_INSTALL/usr/libexec
cp -r $CRAFT_PART_SRC/flutter $CRAFT_PART_INSTALL/usr/libexec/flutter
ln -s $CRAFT_PART_INSTALL/usr/libexec/flutter/bin/flutter $CRAFT_PART_INSTALL/usr/bin/flutter
ln -s $CRAFT_PART_INSTALL/usr/libexec/flutter/bin/dart $CRAFT_PART_INSTALL/usr/bin/dart
$CRAFT_PART_INSTALL/usr/bin/flutter doctor
build-packages:
- clang
- cmake
- curl
- libgtk-3-dev
- ninja-build
- unzip
- xz-utils
- zip
override-prime: ""

ubuntu-desktop-init:
after: [flutter-git]
plugin: nil
source: .
override-build: |
set -eux
mkdir -p $CRAFT_PART_INSTALL/bin/lib
mkdir -p $CRAFT_PART_INSTALL/usr/share/applications
cp snap/local/ubuntu-desktop-init.desktop $CRAFT_PART_INSTALL/usr/share/applications/
dart pub global activate melos
dart pub global run melos bootstrap
# patch config directory path
sed -i 's|/usr/share|/var/lib/snapd/hostfs/usr/share|' packages/ubuntu_provision/lib/src/services/config_service.dart
cd packages/ubuntu_init
flutter build linux --release -v
cp -r build/linux/*/release/bundle/* $CRAFT_PART_INSTALL/bin/
stage-packages:
- libsysmetrics1
- pciutils
- util-linux

lint:
ignore:
- library:
- usr/lib/**/libsysmetrics.so.1

plugs:
run-provd-socket:
interface: system-files
read:
- /run/gnome-initial-setup/desktop-provision/init.socket
write:
- /run/gnome-initial-setup/desktop-provision/init.socket
tmp:
interface: system-files
read:
- /var/lib/snapd/hostfs/tmp
write:
- /var/lib/snapd/hostfs/tmp
usr-share-desktop-provision:
interface: system-files
read:
- /var/lib/snapd/hostfs/usr/share/desktop-provision
var-log-installer:
interface: system-files
write:
- /var/log/installer

slots:
dbus-name:
interface: dbus
bus: session
name: com.canonical.ubuntu_init

0 comments on commit cb19807

Please sign in to comment.