2024-11-05 01:30:46 +01:00
|
|
|
// Warnings ignored for development, we can spit 'const' everywhere
|
|
|
|
// once it will matter
|
|
|
|
// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables
|
|
|
|
|
2024-11-08 00:11:18 +01:00
|
|
|
import 'dart:async';
|
|
|
|
|
2024-05-25 00:17:21 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2024-11-08 00:11:18 +01:00
|
|
|
import 'package:app_links/app_links.dart';
|
2024-11-05 01:30:46 +01:00
|
|
|
|
|
|
|
import 'package:gophershy/gopher_browser.dart';
|
2024-05-25 00:17:21 +02:00
|
|
|
|
|
|
|
void main() {
|
2024-11-05 01:30:46 +01:00
|
|
|
runApp(const GopherShy());
|
2024-05-25 00:17:21 +02:00
|
|
|
}
|
|
|
|
|
2024-11-08 00:11:18 +01:00
|
|
|
class _GopherShyState extends State<GopherShy> {
|
|
|
|
late final AppLinks _appLinks;
|
|
|
|
final _navigatorKey = GlobalKey<NavigatorState>();
|
|
|
|
StreamSubscription<Uri>? _linkSubscription;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_appLinks = AppLinks();
|
|
|
|
_initDeepLinks();
|
|
|
|
print("Launching bcs: ${widget.fromIntentLink}");
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_linkSubscription?.cancel();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _initDeepLinks() async {
|
|
|
|
// Handle links
|
|
|
|
_linkSubscription = _appLinks.uriLinkStream.listen((uri) {
|
|
|
|
debugPrint('GopherShy: onAppLink: $uri');
|
|
|
|
_openAppLink(uri);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void _openAppLink(Uri uri) {
|
|
|
|
_navigatorKey.currentState?.push(MaterialPageRoute<void>(
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return GopherShy(fromIntentLink: uri.toString());
|
|
|
|
},
|
|
|
|
));
|
|
|
|
}
|
2024-05-25 00:17:21 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
2024-11-08 00:11:18 +01:00
|
|
|
navigatorKey: _navigatorKey,
|
2024-11-05 01:30:46 +01:00
|
|
|
title: 'GopherShy',
|
2024-05-25 00:17:21 +02:00
|
|
|
theme: ThemeData(
|
|
|
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
|
|
|
useMaterial3: true,
|
|
|
|
),
|
2024-11-05 01:30:46 +01:00
|
|
|
home: SafeArea(
|
|
|
|
child: Scaffold(
|
|
|
|
appBar: PreferredSize(
|
|
|
|
preferredSize: Size.fromHeight(50),
|
|
|
|
child: Text(
|
2024-11-08 00:11:18 +01:00
|
|
|
"${widget.fromIntentLink} Whoaaaaa",
|
2024-11-05 01:30:46 +01:00
|
|
|
style: TextStyle(fontSize: 50),
|
|
|
|
),
|
2024-05-25 00:17:21 +02:00
|
|
|
),
|
2024-11-05 01:30:46 +01:00
|
|
|
// In future replace with bookmark view
|
2024-11-08 00:19:31 +01:00
|
|
|
body: GopherBrowser( //TODO: replace default url with homepage from prefs
|
2024-11-08 00:11:18 +01:00
|
|
|
initialUrl: widget.fromIntentLink ?? "gopher://treebrary.org"),
|
2024-11-05 01:30:46 +01:00
|
|
|
)),
|
2024-05-25 00:17:21 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-11-08 00:11:18 +01:00
|
|
|
|
|
|
|
class GopherShy extends StatefulWidget {
|
|
|
|
const GopherShy({super.key, this.fromIntentLink});
|
|
|
|
|
|
|
|
final String? fromIntentLink;
|
|
|
|
@override
|
|
|
|
State<GopherShy> createState() => _GopherShyState();
|
|
|
|
}
|