Skip to content

Commit

Permalink
bitwindow: better shutdown screen on exit for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
octobocto committed Jan 29, 2025
1 parent e836a88 commit af366f7
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 50 deletions.
13 changes: 11 additions & 2 deletions clients/Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
format:
#!/usr/bin/env bash
set -euo pipefail
for dir in */; do
for dir in bitwindow faucet launcher sail_ui sidesail; do
if [ -d "$dir" ]; then
(cd "$dir" && find . -name "*.dart" -not -path "./lib/gen/*" | xargs dart format -l 120)
fi
Expand All @@ -11,10 +11,19 @@ format:
fix:
#!/usr/bin/env bash
set -euo pipefail
for dir in */; do
for dir in bitwindow faucet launcher sail_ui sidesail; do
if [ -d "$dir" ]; then
(cd "$dir" && dart fix --apply)
fi
done
lint: format fix

gen-router:
#!/usr/bin/env bash
set -euo pipefail
for dir in sail_ui bitwindow faucet launcher sidesail; do
if [ -d "$dir" ]; then
(cd "$dir" && dart run build_runner build --delete-conflicting-outputs)
fi
done
7 changes: 7 additions & 0 deletions clients/bitwindow/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ Future<void> initDependencies(Logger log, File logFile) async {
() => ContentProvider(),
);

final mainchain = await MainchainRPCLive.create(
ParentChain(),
);
GetIt.I.registerLazySingleton<MainchainRPC>(
() => mainchain,
);

var serverLogFile = [logFile.parent.path, 'debug.log'].join(Platform.pathSeparator);
log.i('logging server logs to: $serverLogFile');
final bitwindow = await BitwindowRPCLive.create(
Expand Down
3 changes: 3 additions & 0 deletions clients/bitwindow/lib/pages/root_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:bitwindow/routing/router.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:sail_ui/gen/bitcoind/v1/bitcoind.pbgrpc.dart';
import 'package:sail_ui/pages/router.gr.dart' as sailroutes;
import 'package:sail_ui/providers/balance_provider.dart';
import 'package:sail_ui/rpcs/bitwindow_api.dart';
import 'package:sail_ui/sail_ui.dart';
Expand Down Expand Up @@ -115,6 +116,8 @@ class _RootPageState extends State<RootPage> with WidgetsBindingObserver {
}

Future<bool> onShutdown(BuildContext context) async {
final router = GetIt.I.get<AppRouter>();
unawaited(router.push(const sailroutes.ShuttingDownRoute()));
final bitwindow = GetIt.I.get<BitwindowRPC>();
final processProvider = GetIt.I.get<ProcessProvider>();

Expand Down
3 changes: 3 additions & 0 deletions clients/bitwindow/lib/routing/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,8 @@ class AppRouter extends RootStackRouter {
AutoRoute(
page: SailLogRoute.page,
),
AutoRoute(
page: ShuttingDownRoute.page,
),
];
}
6 changes: 0 additions & 6 deletions clients/bitwindow/macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
PODS:
- flutter_platform_alert (0.0.1):
- FlutterMacOS
- FlutterMacOS (1.0.0)
- path_provider_foundation (0.0.1):
- Flutter
Expand All @@ -16,7 +14,6 @@ PODS:
- FlutterMacOS

DEPENDENCIES:
- flutter_platform_alert (from `Flutter/ephemeral/.symlinks/plugins/flutter_platform_alert/macos`)
- FlutterMacOS (from `Flutter/ephemeral`)
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
- screen_retriever_macos (from `Flutter/ephemeral/.symlinks/plugins/screen_retriever_macos/macos`)
Expand All @@ -25,8 +22,6 @@ DEPENDENCIES:
- window_manager (from `Flutter/ephemeral/.symlinks/plugins/window_manager/macos`)

EXTERNAL SOURCES:
flutter_platform_alert:
:path: Flutter/ephemeral/.symlinks/plugins/flutter_platform_alert/macos
FlutterMacOS:
:path: Flutter/ephemeral
path_provider_foundation:
Expand All @@ -41,7 +36,6 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/window_manager/macos

SPEC CHECKSUMS:
flutter_platform_alert: 8fa7a7c21f95b26d08b4a3891936ca27e375f284
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
path_provider_foundation: 080d55be775b7414fd5a5ef3ac137b97b097e564
screen_retriever_macos: 452e51764a9e1cdb74b3c541238795849f21557f
Expand Down
6 changes: 5 additions & 1 deletion clients/launcher/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();

final log = Logger();
final router = AppRouter();
await initDependencies(log);

await windowManager.ensureInitialized();
Expand All @@ -44,6 +43,8 @@ void main() async {
}),
);

final router = GetIt.I.get<AppRouter>();

return runApp(
ChangeNotifierProvider(
create: (_) => GetIt.I.get<QuotesProvider>(),
Expand Down Expand Up @@ -74,6 +75,9 @@ Future<void> initDependencies(Logger log) async {
// Register the logger
GetIt.I.registerLazySingleton<Logger>(() => log);

// Register the router
GetIt.I.registerLazySingleton<AppRouter>(() => AppRouter());

// Needed for sidesail_ui to work
GetIt.I.registerLazySingleton<ClientSettings>(
() => ClientSettings(
Expand Down
4 changes: 4 additions & 0 deletions clients/launcher/lib/pages/root_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io';
import 'dart:ui';

Expand All @@ -9,6 +10,7 @@ import 'package:launcher/widgets/wallet_button.dart';
import 'package:launcher/widgets/welcome_modal.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';
import 'package:sail_ui/pages/router.gr.dart' as sailroutes;
import 'package:sail_ui/providers/binary_provider.dart';
import 'package:sail_ui/sail_ui.dart';
import 'package:sail_ui/widgets/nav/top_nav.dart';
Expand Down Expand Up @@ -126,6 +128,8 @@ class _RootPageState extends State<RootPage> with WidgetsBindingObserver {
}

Future<bool> onShutdown(BuildContext context) async {
final router = GetIt.I.get<AppRouter>();
unawaited(router.push(const sailroutes.ShuttingDownRoute()));
final binaryProvider = GetIt.I.get<BinaryProvider>();
final proccessProvider = GetIt.I.get<ProcessProvider>();

Expand Down
6 changes: 5 additions & 1 deletion clients/launcher/lib/routing/router.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:auto_route/auto_route.dart';
import 'package:launcher/pages/overview_page.dart';
import 'package:launcher/pages/root_page.dart';
import 'package:launcher/pages/tools_page.dart';
import 'package:launcher/pages/settings_page.dart';
import 'package:launcher/pages/tools_page.dart';
import 'package:sail_ui/pages/router.gr.dart';

part 'router.gr.dart';

Expand Down Expand Up @@ -49,5 +50,8 @@ class AppRouter extends RootStackRouter {
),
],
),
AutoRoute(
page: ShuttingDownRoute.page,
),
];
}
10 changes: 2 additions & 8 deletions clients/sail_ui/lib/classes/rpc_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,8 @@ abstract class RPCConnection extends ChangeNotifier {
if (newError.contains('Connection refused') ||
newError.contains('SocketException') ||
newError.contains('computer refused the network')) {
if (connectionError != null) {
// an error is already set, and we don't want to override it with
// a generic non-informative message!
newError = connectionError!;
} else {
// don't show a generic Connection refused as the first error
newError = null;
}
// don't show a generic Connection refused as the first error
newError = connectionError;
}

connected = false;
Expand Down
1 change: 1 addition & 0 deletions clients/sail_ui/lib/pages/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class AppRouter extends RootStackRouter {
// HomeScreen is generated as HomeRoute because
// of the replaceInRouteName property
AutoRoute(page: SailLogRoute.page),
AutoRoute(page: ShuttingDownRoute.page),
];

@override
Expand Down
44 changes: 27 additions & 17 deletions clients/sail_ui/lib/pages/router.gr.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// dart format width=80
// GENERATED CODE - DO NOT MODIFY BY HAND

// **************************************************************************
Expand All @@ -8,31 +9,28 @@
// coverage:ignore-file

// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:auto_route/auto_route.dart' as _i2;
import 'package:flutter/material.dart' as _i3;
import 'package:auto_route/auto_route.dart' as _i3;
import 'package:flutter/material.dart' as _i4;
import 'package:sail_ui/pages/log_page.dart' as _i1;
import 'package:sail_ui/pages/shutdown_page.dart' as _i2;

/// generated route for
/// [_i1.SailLogPage]
class SailLogRoute extends _i2.PageRouteInfo<SailLogRouteArgs> {
class SailLogRoute extends _i3.PageRouteInfo<SailLogRouteArgs> {
SailLogRoute({
_i3.Key? key,
_i4.Key? key,
required String name,
required String logPath,
List<_i2.PageRouteInfo>? children,
List<_i3.PageRouteInfo>? children,
}) : super(
SailLogRoute.name,
args: SailLogRouteArgs(
key: key,
name: name,
logPath: logPath,
),
args: SailLogRouteArgs(key: key, name: name, logPath: logPath),
initialChildren: children,
);

static const String name = 'SailLogRoute';

static _i2.PageInfo page = _i2.PageInfo(
static _i3.PageInfo page = _i3.PageInfo(
name,
builder: (data) {
final args = data.argsAs<SailLogRouteArgs>();
Expand All @@ -46,13 +44,9 @@ class SailLogRoute extends _i2.PageRouteInfo<SailLogRouteArgs> {
}

class SailLogRouteArgs {
const SailLogRouteArgs({
this.key,
required this.name,
required this.logPath,
});
const SailLogRouteArgs({this.key, required this.name, required this.logPath});

final _i3.Key? key;
final _i4.Key? key;

final String name;

Expand All @@ -63,3 +57,19 @@ class SailLogRouteArgs {
return 'SailLogRouteArgs{key: $key, name: $name, logPath: $logPath}';
}
}

/// generated route for
/// [_i2.ShuttingDownPage]
class ShuttingDownRoute extends _i3.PageRouteInfo<void> {
const ShuttingDownRoute({List<_i3.PageRouteInfo>? children})
: super(ShuttingDownRoute.name, initialChildren: children);

static const String name = 'ShuttingDownRoute';

static _i3.PageInfo page = _i3.PageInfo(
name,
builder: (data) {
return const _i2.ShuttingDownPage();
},
);
}
31 changes: 31 additions & 0 deletions clients/sail_ui/lib/pages/shutdown_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:sail_ui/sail_ui.dart';

@RoutePage()
class ShuttingDownPage extends StatelessWidget {
const ShuttingDownPage({super.key});

@override
Widget build(BuildContext context) {
final theme = SailTheme.of(context);
return QtPage(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(
color: theme.colors.primary,
strokeWidth: 4,
),
const SizedBox(height: 32),
SailText.primary24(
'Shutting down safely...',
bold: true,
),
],
),
),
);
}
}
20 changes: 5 additions & 15 deletions clients/sail_ui/lib/providers/binary_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,12 @@ class BinaryProvider extends ChangeNotifier {
bool get thunderStopping => thunderRPC.stoppingBinary;
bool get bitnamesStopping => bitnamesRPC.stoppingBinary;

// Add a flag to track if binaries were explicitly launched
final Map<String, bool> _explicitlyLaunched = {};

// Only show errors for explicitly launched binaries
String? get mainchainError => _explicitlyLaunched[ParentChain().name] == true ? mainchainRPC.connectionError : null;
String? get enforcerError => _explicitlyLaunched[Enforcer().name] == true ? enforcerRPC.connectionError : null;
String? get bitwindowError => _explicitlyLaunched[BitWindow().name] == true ? bitwindowRPC.connectionError : null;
String? get thunderError => _explicitlyLaunched[Thunder().name] == true ? thunderRPC.connectionError : null;
String? get bitnamesError => _explicitlyLaunched[Bitnames().name] == true ? bitnamesRPC.connectionError : null;
String? get mainchainError => mainchainRPC.connectionError;
String? get enforcerError => enforcerRPC.connectionError;
String? get bitwindowError => bitwindowRPC.connectionError;
String? get thunderError => thunderRPC.connectionError;
String? get bitnamesError => bitnamesRPC.connectionError;

bool get inIBD => mainchainRPC.inIBD;

Expand Down Expand Up @@ -230,12 +227,6 @@ class BinaryProvider extends ChangeNotifier {
default:
log.i('is $binary');
}
Future.delayed(const Duration(seconds: 3), () {
// give it a bit of time to clean fucked up error messages
_explicitlyLaunched[binary.name] = true;
notifyListeners();
});

// Wait for connection or timeout
await Future.any([
() async {
Expand Down Expand Up @@ -377,7 +368,6 @@ class BinaryProvider extends ChangeNotifier {
}

Future<void> stop(Binary binary) async {
_explicitlyLaunched[binary.name] = false;
switch (binary) {
case ParentChain():
await mainchainRPC.stop();
Expand Down
3 changes: 3 additions & 0 deletions clients/sidesail/lib/routing/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class AppRouter extends RootStackRouter {
AutoRoute(
page: SailLogRoute.page,
),
AutoRoute(
page: ShuttingDownRoute.page,
),

/// This route is used in tests so that we can pump a widget into a route
/// and use the real router for our test
Expand Down

0 comments on commit af366f7

Please sign in to comment.