Skip to content

Commit

Permalink
add upgrader (#9)
Browse files Browse the repository at this point in the history
Signed-off-by: kuromesi <[email protected]>
  • Loading branch information
Kuromesi authored Nov 14, 2024
1 parent b8adff8 commit 9790b4a
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 67 deletions.
30 changes: 29 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,32 @@ jobs:
uses: ncipollo/release-action@v1
with:
artifacts: "build/app/outputs/flutter-apk/app-release.apk"
tag: v${{ env.VERSION }}
tag: v${{ env.VERSION }}

- name: Install Tools
run: sudo apt-get update && sudo apt-get install -y jq

- name: Set up environment
run: |
PUB_DATE=$(date -R)
VERSION=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.tag_name')
DOWNLOAD_URL=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.assets[0].browser_download_url')
FILE_SIZE=$(curl -sI $DOWNLOAD_URL | grep -i Content-Length | awk '{print $2}' | tr -d '\r')
- name: Generate appcast.xml
run: |
sed -e "s/{{APP_NAME}}/Landscape/g" \
-e "s/{{VERSION}}/$VERSION/g" \
-e "s/{{PUB_DATE}}/$PUB_DATE/g" \
-e "s/{{CHANGELOG}}/${{ github.event.head_commit.message }}/g" \
-e "s/{{DOWNLOAD_URL}}/$DOWNLOAD_URL/g" \
-e "s/{{FILE_SIZE}}/$FILE_SIZE/g" \
templates/appcast_template.xml > appcast.xml
- name: Publish appcast
run: |
git status
git add .
git commit -m "[KUROMESI-BOT] publish appcast.yaml"
git fetch origin master
git push origin HEAD:master
13 changes: 9 additions & 4 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import 'package:flutter/material.dart';
import 'package:landscape/pages/gif.dart';
import 'package:landscape/pages/scroll_text.dart';
import 'package:landscape/remote/http.dart';
import 'package:upgrader/upgrader.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
import 'package:landscape/pages/error.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:landscape/notifiers/notifier.dart';
import 'package:landscape/utils/utils.dart';

class MyApp extends StatelessWidget {
@override
Expand Down Expand Up @@ -130,10 +132,13 @@ class _LandscapeState extends State<Landscape> {
)
],
),
body: PageView(
physics: NeverScrollableScrollPhysics(),
controller: _pageController,
children: _pages,
body: UpgradeAlert(
upgrader: upgrader,
child: PageView(
physics: NeverScrollableScrollPhysics(),
controller: _pageController,
children: _pages,
),
),
drawer: Drawer(
child: ListView(
Expand Down
42 changes: 42 additions & 0 deletions lib/utils/test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:flutter/material.dart';
import 'package:upgrader/upgrader.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();

// Only call clearSavedSettings() during testing to reset internal values.
await Upgrader.clearSavedSettings(); // REMOVE this for release builds

// On Android, the default behavior will be to use the Google Play Store
// version of the app.
// On iOS, the default behavior will be to use the App Store version of
// the app, so update the Bundle Identifier in example/ios/Runner with a
// valid identifier already in the App Store.
runApp(const MyApp());
}

const appcastURL =
'https://raw.githubusercontent.com/larryaasen/upgrader/master/test/testappcast.xml';
final upgrader = Upgrader(
storeController: UpgraderStoreController(
onAndroid: () => UpgraderAppcastStore(appcastURL: appcastURL),
),
);

class MyApp extends StatelessWidget {
const MyApp({super.key});


@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Upgrader Example',
home: Scaffold(
appBar: AppBar(title: Text('Upgrader Appcast Example')),
body: UpgradeAlert(
upgrader: upgrader,
child: Center(child: Text('Checking...')),
)),
);
}
}
10 changes: 10 additions & 0 deletions lib/utils/upgrader.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:upgrader/upgrader.dart';

const appcastURL =
'https://raw.githubusercontent.com/kuromesi/landscape-mobile/master/appcast.xml';

final upgrader = Upgrader(
storeController: UpgraderStoreController(
onAndroid: () => UpgraderAppcastStore(appcastURL: appcastURL),
),
);
64 changes: 2 additions & 62 deletions lib/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -1,62 +1,2 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class FullScreenWrapper {
static GestureDetector wrap<T extends Widget>(T obj, BuildContext context,
{List<void Function()> enter = const [],
List<void Function()> exit = const []}) {
return GestureDetector(
onTap: () {
enter.forEach((fn) => fn());
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Scaffold(
body: Center(
child: GestureDetector(
onTap: () {
exit.forEach((fn) => fn());
Navigator.pop(
context,
);
},
child: Container(
child: obj,
width: double.infinity,
height: double.infinity,
)),
),
)),
);
},
child: obj);
}
}

GestureDetector fullScreenWrap<T extends Widget>(T obj, BuildContext context) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Scaffold(
body: Center(
child: GestureDetector(
onTap: () {
Navigator.pop(
context,
);
},
child: Container(
child: obj,
width: double.infinity,
height: double.infinity,
)),
),
),
),
);
},
child: obj,
);
}
export 'package:landscape/utils/wrapper.dart';
export 'package:landscape/utils/upgrader.dart';
61 changes: 61 additions & 0 deletions lib/utils/wrapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:flutter/material.dart';

class FullScreenWrapper {
static GestureDetector wrap<T extends Widget>(T obj, BuildContext context,
{List<void Function()> enter = const [],
List<void Function()> exit = const []}) {
return GestureDetector(
onTap: () {
enter.forEach((fn) => fn());
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Scaffold(
body: Center(
child: GestureDetector(
onTap: () {
exit.forEach((fn) => fn());
Navigator.pop(
context,
);
},
child: Container(
child: obj,
width: double.infinity,
height: double.infinity,
)),
),
)),
);
},
child: obj);
}
}

GestureDetector fullScreenWrap<T extends Widget>(T obj, BuildContext context) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Scaffold(
body: Center(
child: GestureDetector(
onTap: () {
Navigator.pop(
context,
);
},
child: Container(
child: obj,
width: double.infinity,
height: double.infinity,
)),
),
),
),
);
},
child: obj,
);
}
16 changes: 16 additions & 0 deletions templates/appcast.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!-- appcast_template.xml -->
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>{{APP_NAME}} Changelog</title>
<link>{{APPCAST_URL}}</link>
<description>Most recent changes with links to updates.</description>
<language>en</language>
<item>
<title>Version {{VERSION}}</title>
<pubDate>{{PUB_DATE}}</pubDate>
<description>{{CHANGELOG}}</description>
<enclosure url="{{DOWNLOAD_URL}}" sparkle:version="{{VERSION}}" length="{{FILE_SIZE}}" type="application/octet-stream" />
</item>
</channel>
</rss>

0 comments on commit 9790b4a

Please sign in to comment.