Compatibility with quicksync
This commit is contained in:
parent
1ed771add3
commit
efd6125425
|
|
@ -23,9 +23,10 @@ class Downloader extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _DownloaderState extends State<Downloader> {
|
class _DownloaderState extends State<Downloader> {
|
||||||
final pattern = RegExp("( [0-9]+%)");
|
final pattern = RegExp("( [0-9.]+%)");
|
||||||
late final Stream<double> _progressStream;
|
late final Stream<double> _progressStream;
|
||||||
bool _downloadFinished = false;
|
bool _downloadFinished = false;
|
||||||
|
var controller = StreamController<double>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
|
@ -33,24 +34,28 @@ class _DownloaderState extends State<Downloader> {
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void parseProgress(String line) {
|
||||||
|
print(line);
|
||||||
|
var matches = pattern.allMatches(line).toList();
|
||||||
|
if (matches.isNotEmpty) {
|
||||||
|
var percent = matches[0].group(1);
|
||||||
|
if (percent != null) {
|
||||||
|
var value = double.parse(percent.replaceAll('%', '')) / 100.0;
|
||||||
|
controller.add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Stream<double> progressStream() {
|
Stream<double> progressStream() {
|
||||||
var options = [widget.operatingSystem.code, widget.version.version];
|
var options = [widget.operatingSystem.code, widget.version.version];
|
||||||
if (widget.option != null) {
|
if (widget.option != null) {
|
||||||
options.add(widget.option!);
|
options.add(widget.option!);
|
||||||
}
|
}
|
||||||
var controller = StreamController<double>();
|
|
||||||
Process.start('quickget', options).then((process) {
|
Process.start('quickget', options).then((process) {
|
||||||
process.stderr.transform(utf8.decoder).forEach((line) {
|
process.stdout.transform(utf8.decoder).forEach(parseProgress);
|
||||||
var matches = pattern.allMatches(line).toList();
|
process.stderr.transform(utf8.decoder).forEach(parseProgress);
|
||||||
if (matches.isNotEmpty) {
|
|
||||||
var percent = matches[0].group(1);
|
|
||||||
if (percent != null) {
|
|
||||||
var value = double.parse(percent.replaceAll('%', '')) / 100.0;
|
|
||||||
controller.add(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
process.exitCode.then((value) {
|
process.exitCode.then((value) {
|
||||||
|
print("Process exited with exit code $value");
|
||||||
controller.close();
|
controller.close();
|
||||||
setState(() {
|
setState(() {
|
||||||
_downloadFinished = true;
|
_downloadFinished = true;
|
||||||
|
|
@ -62,69 +67,63 @@ class _DownloaderState extends State<Downloader> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
//process.then((process) {
|
|
||||||
// process.stderr.transform(utf8.decoder).forEach((e) {
|
|
||||||
// var matches = pattern.allMatches(e).toList();
|
|
||||||
// var percent = matches[0].group(1);
|
|
||||||
// if (percent != null) {}
|
|
||||||
// });
|
|
||||||
//});
|
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text('Downloading ${widget.operatingSystem.name} ${widget.version.version}' + (widget.option != null ? ' (${widget.option})' : '')),
|
title: Text('Downloading ${widget.operatingSystem.name} ${widget.version.version}' + (widget.option != null ? ' (${widget.option})' : '')),
|
||||||
automaticallyImplyLeading: false,
|
automaticallyImplyLeading: false,
|
||||||
),
|
),
|
||||||
body: Column(children: [
|
body: Column(
|
||||||
Expanded(
|
children: [
|
||||||
child: StreamBuilder(
|
Expanded(
|
||||||
stream: _progressStream,
|
child: StreamBuilder(
|
||||||
builder: (context, AsyncSnapshot<double> snapshot) {
|
stream: _progressStream,
|
||||||
return Column(
|
builder: (context, AsyncSnapshot<double> snapshot) {
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
return Column(
|
||||||
children: [
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
Padding(
|
children: [
|
||||||
padding: const EdgeInsets.all(8.0),
|
Padding(
|
||||||
child: _downloadFinished
|
padding: const EdgeInsets.all(8.0),
|
||||||
? const Text('Download finished.')
|
child: _downloadFinished
|
||||||
: snapshot.hasData
|
? const Text('Download finished.')
|
||||||
? Text('Downloading...${(snapshot.data! * 100).toInt()}%')
|
: snapshot.hasData
|
||||||
: const Text('Waiting for download to start'),
|
? Text('Downloading...${(snapshot.data! * 100).toInt()}%')
|
||||||
),
|
: const Text('Waiting for download to start'),
|
||||||
Padding(
|
),
|
||||||
padding: const EdgeInsets.all(8.0),
|
Padding(
|
||||||
child: SizedBox(
|
padding: const EdgeInsets.all(8.0),
|
||||||
width: 200,
|
child: SizedBox(
|
||||||
child: LinearProgressIndicator(
|
width: 200,
|
||||||
value: _downloadFinished
|
child: LinearProgressIndicator(
|
||||||
? 1
|
value: _downloadFinished
|
||||||
: snapshot.hasData
|
? 1
|
||||||
? snapshot.data!
|
: snapshot.hasData
|
||||||
: null,
|
? snapshot.data!
|
||||||
|
: null,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
);
|
||||||
);
|
},
|
||||||
},
|
),
|
||||||
),
|
),
|
||||||
),
|
Padding(
|
||||||
Padding(
|
padding: const EdgeInsets.all(8.0),
|
||||||
padding: const EdgeInsets.all(8.0),
|
child: Row(
|
||||||
child: Row(
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
children: [
|
||||||
children: [
|
ElevatedButton(
|
||||||
ElevatedButton(
|
onPressed: _downloadFinished
|
||||||
onPressed: _downloadFinished
|
? () {
|
||||||
? () {
|
Navigator.of(context).pop();
|
||||||
Navigator.of(context).pop();
|
}
|
||||||
}
|
: null,
|
||||||
: null,
|
child: _downloadFinished ? const Text('Dimiss') : const Text('Cancel'))
|
||||||
child: _downloadFinished ? const Text('Dimiss') : const Text('Cancel'))
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
]),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ class MainPage extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
Directory.current = '/home/yannick';
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
|
|
@ -75,32 +74,19 @@ class _HomePageButtonsState extends State<HomePageButtons> {
|
||||||
onPressed: (_selectedVersion == null)
|
onPressed: (_selectedVersion == null)
|
||||||
? null
|
? null
|
||||||
: () {
|
: () {
|
||||||
Navigator.of(context).push(MaterialPageRoute(
|
Navigator.of(context).push(
|
||||||
|
MaterialPageRoute(
|
||||||
builder: (context) => Downloader(
|
builder: (context) => Downloader(
|
||||||
operatingSystem: _selectedOperatingSystem!,
|
operatingSystem: _selectedOperatingSystem!,
|
||||||
version: _selectedVersion!,
|
version: _selectedVersion!,
|
||||||
option: _selectedOption,
|
option: _selectedOption,
|
||||||
)));
|
),
|
||||||
/*
|
),
|
||||||
showLoadingIndicator(text: 'Downloading');
|
|
||||||
//await Process.run('quickget', [_selectedOperatingSystem!.code, _selectedVersion!.version]);
|
|
||||||
var options = [_selectedOperatingSystem!.code, _selectedVersion!.version];
|
|
||||||
if (_selectedOption != null) {
|
|
||||||
options.add(_selectedOption!);
|
|
||||||
}
|
|
||||||
var process = await Process.start('quickget', options);
|
|
||||||
process.stderr.transform(utf8.decoder).forEach(
|
|
||||||
|
|
||||||
);
|
);
|
||||||
var exitCode = await process.exitCode;
|
|
||||||
hideLoadingIndicator();
|
|
||||||
showDoneDialog(operatingSystem: _selectedOperatingSystem!.code, version: _selectedVersion!.version);
|
|
||||||
*/
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void showLoadingIndicator({String text = ''}) {
|
void showLoadingIndicator({String text = ''}) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue