Skip to content

Commit b2f041f

Browse files
authored
Merge pull request #26 from Hanprogramer/dev
v0.0.3.1
2 parents fa4228e + ed55228 commit b2f041f

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

lib/screens/settings/plugins_browser.dart

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class PluginsItem {
2323
String name, author, repo, version, iconUrl, desc, identifier;
2424
bool isInstalled = false;
2525
bool isProcessing = false;
26+
String processingMessage = "";
2627

2728
String get folderName {
2829
return identifier + "@" + version;
@@ -34,6 +35,7 @@ class PluginsItem {
3435

3536
class PluginsBrowserState extends State<PluginsBrowser> {
3637
List<PluginsItem> items = [];
38+
3739
JsonDecoder decoder = const JsonDecoder();
3840
GitHub github = GitHub(); // Create an anonymous github client
3941
bool _isLoadingVisible = false;
@@ -71,15 +73,28 @@ class PluginsBrowserState extends State<PluginsBrowser> {
7173
if (!await PluginsManager.checkPluginsExist(
7274
item.identifier, item.version)) {
7375
try {
76+
setState(() {
77+
item.processingMessage = "Fetching data";
78+
});
7479
Repository repo = await github.repositories.getRepository(
7580
RepositorySlug.full(
7681
item.repo.replaceAll("https://github.com/", "")));
82+
83+
setState(() {
84+
item.processingMessage = "Processing releases";
85+
});
7786
List<Release> releases =
7887
await github.repositories.listReleases(repo.slug()).toList();
7988

8089
if (repo.hasDownloads) {
90+
setState(() {
91+
item.processingMessage = "Getting latest update";
92+
});
8193
var r = releases.first;
8294
if (r.zipballUrl != null) {
95+
setState(() {
96+
item.processingMessage = "Downloading data";
97+
});
8398
var bytes = (await http.get(Uri.parse(r.zipballUrl!))).bodyBytes;
8499
var path = await PluginsManager.pluginsPath +
85100
item.folderName +
@@ -89,6 +104,9 @@ class PluginsBrowserState extends State<PluginsBrowser> {
89104
// Create the folder if not exists
90105
await Directory(path).create(recursive: true);
91106

107+
setState(() {
108+
item.processingMessage = "Extracting data";
109+
});
92110
// Extract the contents of the Zip archive to disk.
93111
for (final file in archive) {
94112
final filename = (file.name.split("/")..removeAt(0)).join("/");
@@ -117,24 +135,29 @@ class PluginsBrowserState extends State<PluginsBrowser> {
117135
}
118136
} else {
119137
debugPrint("[PluginsManager] The plugins is already installed");
120-
item.isInstalled = true;
138+
setState(() {
139+
item.isInstalled = true;
140+
});
121141
return false;
122142
}
123-
/* Do Something with repo */
124-
if (item.isInstalled) return false;
125143

126144
setState(() {
127145
item.isProcessing = false;
128146
});
147+
148+
/* Do Something with repo */
149+
if (item.isInstalled) {
150+
return false;
151+
}
152+
129153
return true;
130154
}
131155

132156
void reloadPlugins({String query = ""}) async {
133157
items.clear();
134158
_isLoadingVisible = true;
135159
Response resp = await http.get(Uri.parse(
136-
"https://github.com/CoreCoder-Devs/corecoder_plugins/main/plugins.json")
137-
);
160+
"https://github.com/CoreCoder-Devs/corecoder_plugins/main/plugins.json"));
138161
_isLoadingVisible = false;
139162
if (resp.statusCode == 200) {
140163
// OK
@@ -175,9 +198,7 @@ class PluginsBrowserState extends State<PluginsBrowser> {
175198
),
176199
body: Column(children: [
177200
Visibility(
178-
visible: _isLoadingVisible,
179-
child: const Text('Loading...')
180-
),
201+
visible: _isLoadingVisible, child: const Text('Loading...')),
181202
Column(
182203
children: List.generate(items.length, (index) {
183204
var item = items[index];
@@ -186,9 +207,14 @@ class PluginsBrowserState extends State<PluginsBrowser> {
186207
leading: Image.network(item.iconUrl),
187208
subtitle: Text(item.desc),
188209
trailing: (item.isProcessing)
189-
? const CircularProgressIndicator(
190-
value: null,
191-
)
210+
? Container(
211+
constraints: BoxConstraints(maxWidth: 256),
212+
child: Row(children: [
213+
Text(item.processingMessage),
214+
const CircularProgressIndicator(
215+
value: null,
216+
),
217+
]))
192218
: (item.isInstalled)
193219
? ElevatedButton(
194220
onPressed: () {

0 commit comments

Comments
 (0)