Skip to content

Commit 5726de8

Browse files
committed
feat: notification about nightly channel update
1 parent 596a4b5 commit 5726de8

File tree

5 files changed

+96
-46
lines changed

5 files changed

+96
-46
lines changed

.github/workflows/spotube-release-binary.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,8 @@ jobs:
166166
omitPrereleaseDuringUpdate: true
167167
allowUpdates: true
168168
artifacts: Spotube-Release-Binaries/*,RELEASE.sha256sum,RELEASE.md5sum
169-
body: 'Build Number: ${{github.run_number}}'
169+
body: |
170+
Build Number: ${{github.run_number}}
171+
172+
Nightly release includes newest features but may contain bugs
173+
It is preferred to use the stable version unless you know what you're doing

lib/collections/env.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ abstract class Env {
3333
@EnviedField(varName: "RELEASE_CHANNEL", defaultValue: "nightly")
3434
static final String _releaseChannel = _Env._releaseChannel;
3535

36-
ReleaseChannel get releaseChannel => _releaseChannel == "stable"
36+
static ReleaseChannel get releaseChannel => _releaseChannel == "stable"
3737
? ReleaseChannel.stable
3838
: ReleaseChannel.nightly;
3939

lib/components/root/update_dialog.dart

+26-16
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,50 @@ import 'package:version/version.dart';
55

66
class RootAppUpdateDialog extends StatelessWidget {
77
final Version? version;
8-
const RootAppUpdateDialog({super.key, this.version});
8+
final int? nightlyBuildNum;
9+
10+
const RootAppUpdateDialog({super.key, this.version}) : nightlyBuildNum = null;
11+
const RootAppUpdateDialog.nightly({super.key, required this.nightlyBuildNum})
12+
: version = null;
913

1014
@override
1115
Widget build(BuildContext context) {
1216
const url = "https://spotube.krtirtho.dev/downloads";
17+
const nightlyUrl = "https://spotube.krtirtho.dev/downloads/nightly";
1318
return AlertDialog(
1419
title: const Text("Spotube has an update"),
1520
actions: [
1621
FilledButton(
1722
child: const Text("Download Now"),
1823
onPressed: () => launchUrlString(
19-
url,
24+
nightlyBuildNum != null ? nightlyUrl : url,
2025
mode: LaunchMode.externalApplication,
2126
),
2227
),
2328
],
2429
content: Column(
2530
mainAxisSize: MainAxisSize.min,
2631
children: [
27-
Text("Spotube v$version has been released"),
28-
Row(
29-
mainAxisAlignment: MainAxisAlignment.center,
30-
children: [
31-
const Text("Read the latest "),
32-
AnchorButton(
33-
"release notes",
34-
style: const TextStyle(color: Colors.blue),
35-
onTap: () => launchUrlString(
36-
url,
37-
mode: LaunchMode.externalApplication,
38-
),
39-
),
40-
],
32+
Text(
33+
nightlyBuildNum != null
34+
? "Spotube Nightly $nightlyBuildNum has been releases"
35+
: "Spotube v$version has been released",
4136
),
37+
if (nightlyBuildNum != null)
38+
Row(
39+
mainAxisAlignment: MainAxisAlignment.center,
40+
children: [
41+
const Text("Read the latest "),
42+
AnchorButton(
43+
"release notes",
44+
style: const TextStyle(color: Colors.blue),
45+
onTap: () => launchUrlString(
46+
url,
47+
mode: LaunchMode.externalApplication,
48+
),
49+
),
50+
],
51+
),
4252
],
4353
),
4454
);

lib/pages/settings/about.dart

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter/services.dart';
33
import 'package:spotube/collections/assets.gen.dart';
4+
import 'package:spotube/collections/env.dart';
45
import 'package:spotube/components/shared/image/universal_image.dart';
56
import 'package:spotube/components/shared/links/hyper_link.dart';
67
import 'package:spotube/components/shared/page_window_title_bar.dart';
@@ -72,6 +73,13 @@ class AboutSpotube extends HookConsumerWidget {
7273
Text("v${packageInfo.version}")
7374
],
7475
),
76+
TableRow(
77+
children: [
78+
Text(context.l10n.channel),
79+
colon,
80+
Text(Env.releaseChannel.name)
81+
],
82+
),
7583
TableRow(
7684
children: [
7785
Text(context.l10n.build_number),

lib/utils/service_utils.dart

+56-28
Original file line numberDiff line numberDiff line change
@@ -335,35 +335,63 @@ abstract class ServiceUtils {
335335
) async {
336336
if (!Env.enableUpdateChecker) return;
337337
if (!ref.read(userPreferencesProvider.select((s) => s.checkUpdate))) return;
338-
339338
final packageInfo = await PackageInfo.fromPlatform();
340339

341-
final value = await http.get(
342-
Uri.parse(
343-
"https://api.github.com/repos/KRTirtho/spotube/releases/latest",
344-
),
345-
);
346-
final tagName =
347-
(jsonDecode(value.body)["tag_name"] as String).replaceAll("v", "");
348-
final currentVersion = packageInfo.version == "Unknown"
349-
? null
350-
: Version.parse(packageInfo.version);
351-
final latestVersion = tagName == "nightly" ? null : Version.parse(tagName);
352-
353-
if (currentVersion == null ||
354-
latestVersion == null ||
355-
(latestVersion.isPreRelease && !currentVersion.isPreRelease) ||
356-
(!latestVersion.isPreRelease && currentVersion.isPreRelease)) return;
357-
358-
if (latestVersion <= currentVersion || !context.mounted) return;
359-
360-
showDialog(
361-
context: context,
362-
barrierDismissible: true,
363-
barrierColor: Colors.black26,
364-
builder: (context) {
365-
return RootAppUpdateDialog(version: latestVersion);
366-
},
367-
);
340+
if (Env.releaseChannel == ReleaseChannel.nightly) {
341+
final value = await http.get(
342+
Uri.parse(
343+
"https://api.github.com/repos/KRTirtho/spotube/releases/tags/nightly",
344+
),
345+
);
346+
347+
final body = jsonDecode(value.body)["body"] as String;
348+
349+
final buildNum = int.tryParse(
350+
RegExp(r'Build Number: (\d+)').firstMatch(body)?.group(1) ?? '0',
351+
) ??
352+
0;
353+
354+
if (buildNum <= int.parse(packageInfo.buildNumber) || !context.mounted) {
355+
return;
356+
}
357+
358+
await showDialog(
359+
context: context,
360+
barrierDismissible: true,
361+
barrierColor: Colors.black26,
362+
builder: (context) {
363+
return RootAppUpdateDialog.nightly(nightlyBuildNum: buildNum);
364+
},
365+
);
366+
} else {
367+
final value = await http.get(
368+
Uri.parse(
369+
"https://api.github.com/repos/KRTirtho/spotube/releases/latest",
370+
),
371+
);
372+
final tagName =
373+
(jsonDecode(value.body)["tag_name"] as String).replaceAll("v", "");
374+
final currentVersion = packageInfo.version == "Unknown"
375+
? null
376+
: Version.parse(packageInfo.version);
377+
final latestVersion =
378+
tagName == "nightly" ? null : Version.parse(tagName);
379+
380+
if (currentVersion == null ||
381+
latestVersion == null ||
382+
(latestVersion.isPreRelease && !currentVersion.isPreRelease) ||
383+
(!latestVersion.isPreRelease && currentVersion.isPreRelease)) return;
384+
385+
if (latestVersion <= currentVersion || !context.mounted) return;
386+
387+
showDialog(
388+
context: context,
389+
barrierDismissible: true,
390+
barrierColor: Colors.black26,
391+
builder: (context) {
392+
return RootAppUpdateDialog(version: latestVersion);
393+
},
394+
);
395+
}
368396
}
369397
}

0 commit comments

Comments
 (0)