Created
April 20, 2021 15:31
-
-
Save felixblaschke/e6877c19a83dda82a5399c13073a6fd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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