feat(garage_updates): an auto updater for garage apps

Asks Garage for the newest release of a project, downloads it with resume,
checks the sha256, installs it beside the old one and restarts into it.
Splash on garage_ui, a native stub and a first time installer for windows,
bundle swap on mac, the system installer on android. No-op on web.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KHotisA4hV2xmuZsHTksFX
This commit is contained in:
ImBenji
2026-10-12 06:37:02 +01:00
co-authored by Claude Opus 5.5
parent 444933b004
commit d3b232f0ee
56 changed files with 9031 additions and 0 deletions
+117
View File
@@ -0,0 +1,117 @@
import "package:flutter/widgets.dart";
import "package:garage_ui/garage_ui.dart";
import "package:garage_updates/garage_updates.dart";
import "package:go_router/go_router.dart";
// The whole integration is the one call at the top of main. Everything under
// it is just an app with a "restart to update" button, which is the only
// other thing an app has to do for itself.
//
// Run it with `flutter run` and the updater prints that this copy isnt an
// install and stays out of the way - it only ever touches a release build
// that the installer (or a previous update) put in place.
Future<void> main(List<String> args) async {
// an app with helpers of its own (an agent, a tray) stops them here
GarageUpdater.instance.onBeforeRestart = () async {
print("about to restart into the new build");
};
await GarageUpdater.launch(
args: args,
project: "proj_example",
build: 12, // the number after the + in pubspec's version
label: "v2610-1",
branding: const UpdaterBranding(
name: "Example App",
logo: Icon(LucideIcons.package),
),
mode: UpdateMode.prompt,
);
runApp(const ExampleApp());
}
final _theme = ThemeData(
colorScheme: GarageSchemes.carbon,
density: const Density.product(),
);
final _router = GoRouter(
routes: [
GoRoute(path: "/", builder: (context, state) => const HomePage()),
],
);
class ExampleApp extends StatelessWidget {
const ExampleApp({super.key});
@override
Widget build(BuildContext context) {
return GarageApp.router(routerConfig: _router, theme: _theme, title: "Example App");
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
String? _error;
Future<void> _restart() async {
try {
await GarageUpdater.instance.restartToUpdate();
} on UpdateError catch (e) {
// a UAC prompt turned down, say. the update is still waiting
print("couldnt restart into the update: $e");
if (mounted) setState(() => _error = e.message);
}
}
@override
Widget build(BuildContext context) {
final updater = GarageUpdater.instance;
return Scaffold(
child: Center(
child: ValueListenableBuilder<UpdateInfo?>(
valueListenable: updater.ready,
builder: (context, waiting, _) {
final latest = waiting?.latest;
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Text("Example App ${updater.label}").large().semiBold(),
const Gap.sm(),
if (latest == null)
const Text("Up to date").muted()
else ...[
Text("${latest.label} is ready to install").muted(),
const Gap.sm(),
// the notes are the apps to show, the splash never does
if (latest.notes.isNotEmpty) Text(latest.notes).muted(),
const Gap.lg(),
Button(
style: const ButtonStyle.primary(),
onPressed: _restart,
child: const Text("Restart to update"),
),
],
if (_error != null) ...[
const Gap.md(),
Text(_error!).muted(),
],
],
);
},
),
),
);
}
}
+24
View File
@@ -0,0 +1,24 @@
name: garage_updates_example
description: "Minimal example of an app that updates itself with garage_updates."
publish_to: 'none'
version: 0.1.0+12
environment:
sdk: ^3.10.0
flutter: ">=3.5.0"
dependencies:
flutter:
sdk: flutter
garage_ui:
path: ../../garage_ui
garage_updates:
path: ../
go_router: ^14.6.2
dev_dependencies:
flutter_lints: ^6.0.0
flutter: