1+ // ignore_for_file: use_build_context_synchronously
2+
13import 'package:app_store/main.dart' ;
24import 'package:app_store/src/core/http.dart' ;
35import 'package:app_store/src/core/navigation.dart' ;
6+ import 'package:app_store/src/handlers/exceptions.dart' ;
47import 'package:app_store/src/modules/applications/applications_model.dart' ;
58import 'package:app_store/src/modules/applications/widgets/build_applications.dart' ;
69import 'package:flutter/material.dart' ;
@@ -15,21 +18,21 @@ class ApplicationsController extends ChangeNotifier {
1518 BuildApplicationsWidget (endpoint: "search/$search " ), context);
1619 notifyListeners ();
1720 } catch (e) {
18- rethrow ;
21+ throw CustomExceptionsWidget (e. toString (), context) ;
1922 }
2023 }
2124
2225 static Future <ApplicationsModel > getByFlatpakAppId (
23- String flatpakAppId) async {
26+ String flatpakAppId, BuildContext context ) async {
2427 try {
2528 final data = await Http .get (flatpakAppId);
2629 return ApplicationsModel .fromJson (data);
2730 } catch (e) {
28- rethrow ;
31+ throw CustomExceptionsWidget (e. toString (), context) ;
2932 }
3033 }
3134
32- Future <bool > hasInstalledFlatpak (ApplicationsModel applicationsModel) async {
35+ Future <bool > hasInstalledFlatpak (ApplicationsModel applicationsModel, BuildContext context ) async {
3336 try {
3437 late bool hasInstalled;
3538 final result = await shell.run ('''ls /var/lib/flatpak/app/''' );
@@ -42,31 +45,88 @@ class ApplicationsController extends ChangeNotifier {
4245
4346 return hasInstalled;
4447 } catch (e) {
45- rethrow ;
48+ throw CustomExceptionsWidget (e. toString (), context) ;
4649 }
4750 }
4851
49- Future <void > installFlatpak (ApplicationsModel applicationsModel) async {
52+ Future <void > installFlatpak (ApplicationsModel applicationsModel, BuildContext context ) async {
5053 try {
5154 final result = await shell.run (
5255 '''flatpak-install-gui --override-appname="${applicationsModel .name }" ${applicationsModel .flatpakAppId }''' ,
5356 );
5457 result;
5558 notifyListeners ();
5659 } catch (e) {
57- rethrow ;
60+ throw CustomExceptionsWidget (e. toString (), context) ;
5861 }
5962 }
6063
61- Future <void > removeFlatpak (ApplicationsModel applicationsModel) async {
64+ Future <void > removeFlatpak (ApplicationsModel applicationsModel, BuildContext context ) async {
6265 try {
6366 final result = await shell.run (
6467 '''flatpak-install-gui --override-appname="${applicationsModel .name }" --remove ${applicationsModel .flatpakAppId }''' ,
6568 );
6669 result;
6770 notifyListeners ();
6871 } catch (e) {
69- rethrow ;
72+ throw CustomExceptionsWidget (e.toString (), context);
73+ }
74+ }
75+
76+ Future <bool > hasInstalledDebian (ApplicationsModel applicationsModel, BuildContext context) async {
77+ try {
78+
79+ final name = applicationsModel.name! .replaceAll (RegExp (r' ' ), "-" ).toLowerCase ();
80+ final data = await shell.run ("apt list --installed $name " );
81+
82+ for (var element in data.outLines) {
83+ if (element.contains (name)) {
84+ return true ;
85+ }
86+ }
87+
88+ return false ;
89+ } catch (e) {
90+ throw CustomExceptionsWidget (e.toString (), context);
7091 }
7192 }
93+
94+ Future <bool > isDebianPackage (ApplicationsModel applicationsModel, BuildContext context) async {
95+ try {
96+ final name = applicationsModel.name! .replaceAll (RegExp (r' ' ), "-" ).toLowerCase ();
97+ final data = await shell.run ("apt list $name " );
98+
99+ for (var element in data.outLines) {
100+ if (element.contains (name)) {
101+ return true ;
102+ }
103+ }
104+
105+ return false ;
106+ } catch (e) {
107+ throw CustomExceptionsWidget (e.toString (), context);
108+ }
109+ }
110+
111+ Future <void > installDebianPackage (ApplicationsModel applicationsModel, BuildContext context) async {
112+ try {
113+ final name = applicationsModel.name! .replaceAll (RegExp (r' ' ), "-" ).toLowerCase ();
114+ final result = await shell.run ("pkexec apt-get install $name -y" );
115+ result;
116+ notifyListeners ();
117+ } catch (e) {
118+ throw CustomExceptionsWidget (e.toString (), context);
119+ }
120+ }
121+
122+ Future <void > removeDebianPackage (ApplicationsModel applicationsModel, BuildContext context) async {
123+ try {
124+ final name = applicationsModel.name! .replaceAll (RegExp (r' ' ), "-" ).toLowerCase ();
125+ final result = await shell.run ("pkexec apt-get remove $name -y" );
126+ result;
127+ notifyListeners ();
128+ } catch (e) {
129+ throw CustomExceptionsWidget (e.toString (), context);
130+ }
131+ }
72132}
0 commit comments