Skip to content

Instantly share code, notes, and snippets.

@felixblaschke
Created April 20, 2021 15:31
Show Gist options
  • Save felixblaschke/e6877c19a83dda82a5399c13073a6fd0 to your computer and use it in GitHub Desktop.
Save felixblaschke/e6877c19a83dda82a5399c13073a6fd0 to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:alfred/alfred.dart';
void main() async {
var app = Alfred();
app.get('*', (req, res) => Directory('public'));
await app.listen(8080);
registerUpdater(onExit: () => app.close());
}
void registerUpdater({required void Function() onExit}) {
Timer.periodic(Duration(seconds: 60), (timer) async {
var process = await Process.start('git', ['pull']);
var hasUpdated = false;
await process.stdout.transform(utf8.decoder).forEach((line) {
hasUpdated = line.startsWith('Updating') || hasUpdated;
});
await process.exitCode;
if (hasUpdated) {
print('Close app for update');
onExit();
timer.cancel();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment