mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-07-22 17:19:42 +02:00
Finished switch to new download/install process
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:obtainium/pages/home.dart';
|
import 'package:obtainium/pages/home.dart';
|
||||||
import 'package:obtainium/services/apps_provider.dart';
|
import 'package:obtainium/services/apps_provider.dart';
|
||||||
import 'package:obtainium/services/source_service.dart';
|
import 'package:obtainium/services/source_service.dart';
|
||||||
@@ -30,6 +31,10 @@ void backgroundUpdateCheck() {
|
|||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
SystemChrome.setSystemUIOverlayStyle(
|
||||||
|
const SystemUiOverlayStyle(systemNavigationBarColor: Colors.transparent),
|
||||||
|
);
|
||||||
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||||
Workmanager().initialize(
|
Workmanager().initialize(
|
||||||
backgroundUpdateCheck,
|
backgroundUpdateCheck,
|
||||||
);
|
);
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:obtainium/services/apps_provider.dart';
|
import 'package:obtainium/services/apps_provider.dart';
|
||||||
import 'package:obtainium/services/source_service.dart';
|
|
||||||
import 'package:webview_flutter/webview_flutter.dart';
|
import 'package:webview_flutter/webview_flutter.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
@@ -23,77 +22,82 @@ class _AppPageState extends State<AppPage> {
|
|||||||
}
|
}
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text('${app!.app.author}/${app.app.name}'),
|
title: Text('${app?.app.author}/${app?.app.name}'),
|
||||||
),
|
),
|
||||||
body: WebView(
|
body: WebView(
|
||||||
initialUrl: app.app.url,
|
initialUrl: app?.app.url,
|
||||||
),
|
|
||||||
bottomSheet: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding:
|
|
||||||
const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: (app.app.installedVersion == null ||
|
|
||||||
appsProvider.checkAppObjectForUpdate(
|
|
||||||
app.app)) &&
|
|
||||||
app.downloadProgress == null
|
|
||||||
? () {
|
|
||||||
appsProvider.downloadAndInstallLatestApp(
|
|
||||||
app.app.id);
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
child: Text(app.app.installedVersion == null
|
|
||||||
? 'Install'
|
|
||||||
: 'Update'))),
|
|
||||||
const SizedBox(width: 16.0),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: app.downloadProgress != null
|
|
||||||
? null
|
|
||||||
: () {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (BuildContext ctx) {
|
|
||||||
return AlertDialog(
|
|
||||||
title: const Text('Remove App?'),
|
|
||||||
content: Text(
|
|
||||||
'This will remove \'${app.app.name}\' from Obtainium.${app.app.installedVersion != null ? '\n\nNote that while Obtainium will no longer track its updates, the App will remain installed.' : ''}'),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
appsProvider
|
|
||||||
.removeApp(app.app.id)
|
|
||||||
.then((_) {
|
|
||||||
int count = 0;
|
|
||||||
Navigator.of(context).popUntil(
|
|
||||||
(_) => count++ >= 2);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: const Text('Remove')),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
child: const Text('Cancel'))
|
|
||||||
],
|
|
||||||
);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
style: TextButton.styleFrom(
|
|
||||||
foregroundColor: Theme.of(context).errorColor,
|
|
||||||
surfaceTintColor: Theme.of(context).errorColor),
|
|
||||||
child: const Text('Remove'),
|
|
||||||
),
|
|
||||||
])),
|
|
||||||
if (app.downloadProgress != null)
|
|
||||||
LinearProgressIndicator(value: app.downloadProgress)
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
|
bottomSheet: Padding(
|
||||||
|
padding: EdgeInsets.fromLTRB(
|
||||||
|
0, 0, 0, MediaQuery.of(context).padding.bottom),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: (app?.app.installedVersion == null ||
|
||||||
|
appsProvider
|
||||||
|
.checkAppObjectForUpdate(
|
||||||
|
app!.app)) &&
|
||||||
|
app?.downloadProgress == null
|
||||||
|
? () {
|
||||||
|
appsProvider
|
||||||
|
.downloadAndInstallLatestApp(
|
||||||
|
app!.app.id);
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
child: Text(app?.app.installedVersion == null
|
||||||
|
? 'Install'
|
||||||
|
: 'Update'))),
|
||||||
|
const SizedBox(width: 16.0),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: app?.downloadProgress != null
|
||||||
|
? null
|
||||||
|
: () {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext ctx) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Remove App?'),
|
||||||
|
content: Text(
|
||||||
|
'This will remove \'${app?.app.name}\' from Obtainium.${app?.app.installedVersion != null ? '\n\nNote that while Obtainium will no longer track its updates, the App will remain installed.' : ''}'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
appsProvider
|
||||||
|
.removeApp(app!.app.id)
|
||||||
|
.then((_) {
|
||||||
|
int count = 0;
|
||||||
|
Navigator.of(context)
|
||||||
|
.popUntil((_) =>
|
||||||
|
count++ >= 2);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: const Text('Remove')),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: const Text('Cancel'))
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
foregroundColor: Theme.of(context).errorColor,
|
||||||
|
surfaceTintColor: Theme.of(context).errorColor),
|
||||||
|
child: const Text('Remove'),
|
||||||
|
),
|
||||||
|
])),
|
||||||
|
if (app?.downloadProgress != null)
|
||||||
|
LinearProgressIndicator(value: app!.downloadProgress! / 100)
|
||||||
|
],
|
||||||
|
)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,21 +21,21 @@ class _HomePageState extends State<HomePage> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: const Text('Obtainium')),
|
appBar: AppBar(title: const Text('Obtainium')),
|
||||||
body: pages.elementAt(selectedIndex),
|
body: pages.elementAt(selectedIndex),
|
||||||
bottomNavigationBar: NavigationBar(
|
bottomNavigationBar: NavigationBar(
|
||||||
destinations: const [
|
destinations: const [
|
||||||
NavigationDestination(
|
NavigationDestination(icon: Icon(Icons.settings), label: 'Settings'),
|
||||||
icon: Icon(Icons.settings), label: 'Settings'),
|
NavigationDestination(icon: Icon(Icons.apps), label: 'Apps'),
|
||||||
NavigationDestination(icon: Icon(Icons.apps), label: 'Apps'),
|
NavigationDestination(icon: Icon(Icons.add), label: 'Add App'),
|
||||||
NavigationDestination(icon: Icon(Icons.add), label: 'Add App'),
|
],
|
||||||
],
|
onDestinationSelected: (int index) {
|
||||||
onDestinationSelected: (int index) {
|
setState(() {
|
||||||
setState(() {
|
selectedIndex = index;
|
||||||
selectedIndex = index;
|
});
|
||||||
});
|
},
|
||||||
},
|
selectedIndex: selectedIndex,
|
||||||
selectedIndex: selectedIndex,
|
),
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -72,7 +72,10 @@ class AppsProvider with ChangeNotifier {
|
|||||||
StreamedResponse response =
|
StreamedResponse response =
|
||||||
await Client().send(Request('GET', Uri.parse(apps[appId]!.app.apkUrl)));
|
await Client().send(Request('GET', Uri.parse(apps[appId]!.app.apkUrl)));
|
||||||
File downloadFile =
|
File downloadFile =
|
||||||
File('${(await getTemporaryDirectory()).path}/$appId.apk');
|
File('${(await getExternalStorageDirectory())!.path}/apks/$appId.apk');
|
||||||
|
if (downloadFile.existsSync()) {
|
||||||
|
downloadFile.deleteSync();
|
||||||
|
}
|
||||||
var length = response.contentLength;
|
var length = response.contentLength;
|
||||||
var received = 0;
|
var received = 0;
|
||||||
var sink = downloadFile.openWrite();
|
var sink = downloadFile.openWrite();
|
||||||
@@ -94,14 +97,13 @@ class AppsProvider with ChangeNotifier {
|
|||||||
throw response.reasonPhrase ?? 'Unknown Error';
|
throw response.reasonPhrase ?? 'Unknown Error';
|
||||||
}
|
}
|
||||||
|
|
||||||
var res = await InstallPlugin.installApk(
|
// Unfortunately this 'await' does not actually wait for the APK to finish installing
|
||||||
downloadFile.path, 'dev.imranr.obtainium');
|
// So we only know that the install prompt was shown, but the user could still cancel w/o us knowing
|
||||||
print(res);
|
// This also does not use the 'session-based' installer API, so background/silent updates are impossible
|
||||||
|
await InstallPlugin.installApk(downloadFile.path, 'dev.imranr.obtainium');
|
||||||
|
|
||||||
apps[appId]!.app.installedVersion = apps[appId]!.app.latestVersion;
|
apps[appId]!.app.installedVersion = apps[appId]!.app.latestVersion;
|
||||||
saveApp(apps[appId]!.app);
|
saveApp(apps[appId]!.app);
|
||||||
|
|
||||||
downloadFile.deleteSync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Directory> getAppsDir() async {
|
Future<Directory> getAppsDir() async {
|
||||||
|
Reference in New Issue
Block a user