123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764 |
- import 'dart:io';
- import 'package:archive/archive_io.dart';
- import 'package:crisp/crisp.dart';
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/widgets.dart';
- import 'package:flutter_email_sender/flutter_email_sender.dart';
- import 'package:flutter_sodium/flutter_sodium.dart';
- import 'package:flutter_windowmanager/flutter_windowmanager.dart';
- import 'package:package_info_plus/package_info_plus.dart';
- import 'package:path_provider/path_provider.dart';
- import 'package:photos/core/constants.dart';
- import 'package:photos/ui/app_lock.dart';
- import 'package:photos/utils/auth_util.dart';
- import 'package:photos/core/configuration.dart';
- import 'package:photos/db/files_db.dart';
- import 'package:photos/services/billing_service.dart';
- import 'package:photos/ui/loading_widget.dart';
- import 'package:photos/ui/subscription_page.dart';
- import 'package:photos/ui/web_page.dart';
- import 'package:photos/utils/data_util.dart';
- import 'package:photos/utils/dialog_util.dart';
- import 'package:photos/utils/toast_util.dart';
- import 'package:share/share.dart';
- import 'package:url_launcher/url_launcher.dart';
- class SettingsPage extends StatelessWidget {
- const SettingsPage({Key key}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text("settings"),
- ),
- body: _getBody(),
- );
- }
- Widget _getBody() {
- final hasLoggedIn = Configuration.instance.getToken() != null;
- final List<Widget> contents = [];
- if (hasLoggedIn) {
- contents.addAll([
- BackupSettingsWidget(),
- Padding(padding: EdgeInsets.all(12)),
- ]);
- }
- contents.addAll([
- SecuritySectionWidget(),
- Padding(padding: EdgeInsets.all(12)),
- SupportSectionWidget(),
- Padding(padding: EdgeInsets.all(12)),
- InfoSectionWidget(),
- ]);
- if (hasLoggedIn) {
- contents.add(AccountSectionWidget());
- }
- contents.add(
- FutureBuilder(
- future: _getAppVersion(),
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- return Padding(
- padding: const EdgeInsets.all(16.0),
- child: Text(
- "app version: " + snapshot.data,
- style: TextStyle(
- fontSize: 12,
- color: Colors.white.withOpacity(0.6),
- ),
- ),
- );
- }
- return Container();
- },
- ),
- );
- if (kDebugMode && hasLoggedIn) {
- contents.add(DebugWidget());
- }
- return SingleChildScrollView(
- child: Padding(
- padding: const EdgeInsets.all(12.0),
- child: Column(
- children: contents,
- ),
- ),
- );
- }
- static Future<String> _getAppVersion() async {
- var pkgInfo = await PackageInfo.fromPlatform();
- return "${pkgInfo.version}";
- }
- }
- class BackupSettingsWidget extends StatefulWidget {
- BackupSettingsWidget({Key key}) : super(key: key);
- @override
- BackupSettingsWidgetState createState() => BackupSettingsWidgetState();
- }
- class BackupSettingsWidgetState extends State<BackupSettingsWidget> {
- double _usageInGBs;
- @override
- void initState() {
- _getUsage();
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return Container(
- child: Column(
- children: [
- SettingsSectionTitle("backup"),
- GestureDetector(
- behavior: HitTestBehavior.translucent,
- onTap: () async {
- _showFoldersDialog(context);
- },
- child: SettingsTextItem(
- text: "backed up folders", icon: Icons.navigate_next),
- ),
- Divider(height: 4),
- Padding(padding: EdgeInsets.all(4)),
- Container(
- height: 36,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text("backup over mobile data"),
- Switch(
- value: Configuration.instance.shouldBackupOverMobileData(),
- onChanged: (value) async {
- Configuration.instance.setBackupOverMobileData(value);
- setState(() {});
- },
- ),
- ],
- ),
- ),
- Padding(padding: EdgeInsets.all(4)),
- Divider(height: 4),
- GestureDetector(
- behavior: HitTestBehavior.translucent,
- onTap: () async {
- Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return SubscriptionPage();
- },
- ),
- );
- },
- child: SettingsTextItem(
- text: "subscription plan", icon: Icons.navigate_next),
- ),
- Divider(height: 4),
- Padding(padding: EdgeInsets.all(8)),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text("total data backed up"),
- Container(
- height: 20,
- child: _usageInGBs == null
- ? loadWidget
- : Text(
- _usageInGBs.toString() + " GB",
- ),
- ),
- ],
- ),
- ],
- ),
- );
- }
- void _showFoldersDialog(BuildContext context) async {
- AlertDialog alert = AlertDialog(
- title: Text("select folders to back up"),
- content: BackedUpFoldersWidget(),
- actions: [
- FlatButton(
- child: Text("OK"),
- onPressed: () {
- Navigator.of(context, rootNavigator: true).pop('dialog');
- },
- ),
- ],
- );
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return alert;
- },
- );
- }
- void _getUsage() {
- BillingService.instance.fetchUsage().then((usage) async {
- if (mounted) {
- setState(() {
- _usageInGBs = convertBytesToGBs(usage);
- });
- }
- });
- }
- }
- class BackedUpFoldersWidget extends StatefulWidget {
- const BackedUpFoldersWidget({
- Key key,
- }) : super(key: key);
- @override
- _BackedUpFoldersWidgetState createState() => _BackedUpFoldersWidgetState();
- }
- class _BackedUpFoldersWidgetState extends State<BackedUpFoldersWidget> {
- @override
- Widget build(BuildContext context) {
- return FutureBuilder<List<String>>(
- future: FilesDB.instance.getLocalPaths(),
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- snapshot.data.sort((first, second) {
- return first.toLowerCase().compareTo(second.toLowerCase());
- });
- final backedUpFolders = Configuration.instance.getPathsToBackUp();
- final foldersWidget = List<Widget>();
- for (final folder in snapshot.data) {
- foldersWidget.add(CheckboxListTile(
- value: backedUpFolders.contains(folder),
- dense: true,
- title: Text(folder),
- controlAffinity: ListTileControlAffinity.leading,
- onChanged: (value) async {
- if (value) {
- backedUpFolders.add(folder);
- } else {
- backedUpFolders.remove(folder);
- }
- await Configuration.instance.setPathsToBackUp(backedUpFolders);
- setState(() {});
- },
- ));
- }
- final scrollController = ScrollController();
- return Container(
- child: Scrollbar(
- isAlwaysShown: true,
- controller: scrollController,
- child: SingleChildScrollView(
- child: Column(children: foldersWidget),
- controller: scrollController,
- ),
- ),
- );
- }
- return loadWidget;
- },
- );
- }
- }
- class SecuritySectionWidget extends StatefulWidget {
- SecuritySectionWidget({Key key}) : super(key: key);
- @override
- _SecuritySectionWidgetState createState() => _SecuritySectionWidgetState();
- }
- class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
- @override
- void initState() {
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- final List<Widget> children = [];
- children.addAll([
- SettingsSectionTitle("security"),
- Container(
- height: 36,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text("lockscreen"),
- Switch(
- value: Configuration.instance.shouldShowLockScreen(),
- onChanged: (value) async {
- AppLock.of(context).disable();
- final result = await requestAuthentication();
- if (result) {
- AppLock.of(context).setEnabled(value);
- Configuration.instance.setShouldShowLockScreen(value);
- setState(() {});
- } else {
- AppLock.of(context).setEnabled(
- Configuration.instance.shouldShowLockScreen());
- }
- },
- ),
- ],
- ),
- ),
- ]);
- if (Platform.isAndroid) {
- children.addAll([
- Padding(padding: EdgeInsets.all(4)),
- Divider(height: 4),
- Padding(padding: EdgeInsets.all(4)),
- Container(
- height: 36,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text("hide from recents"),
- Switch(
- value: Configuration.instance.shouldHideFromRecents(),
- onChanged: (value) async {
- if (value) {
- AlertDialog alert = AlertDialog(
- title: Text("hide from recents?"),
- content: SingleChildScrollView(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- "hiding from the task switcher will prevent you from taking screenshots in this app.",
- style: TextStyle(
- height: 1.5,
- ),
- ),
- Padding(padding: EdgeInsets.all(8)),
- Text(
- "are you sure?",
- style: TextStyle(
- height: 1.5,
- ),
- ),
- ],
- ),
- ),
- actions: [
- TextButton(
- child:
- Text("no", style: TextStyle(color: Colors.white)),
- onPressed: () {
- Navigator.of(context, rootNavigator: true)
- .pop('dialog');
- },
- ),
- TextButton(
- child: Text("yes",
- style: TextStyle(
- color: Colors.white.withOpacity(0.8))),
- onPressed: () async {
- Navigator.of(context, rootNavigator: true)
- .pop('dialog');
- await Configuration.instance
- .setShouldHideFromRecents(true);
- await FlutterWindowManager.addFlags(
- FlutterWindowManager.FLAG_SECURE);
- setState(() {});
- },
- ),
- ],
- );
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return alert;
- },
- );
- } else {
- await Configuration.instance
- .setShouldHideFromRecents(false);
- await FlutterWindowManager.clearFlags(
- FlutterWindowManager.FLAG_SECURE);
- setState(() {});
- }
- },
- ),
- ],
- ),
- ),
- ]);
- }
- return Container(
- child: Column(
- children: children,
- ),
- );
- }
- }
- class SettingsSectionTitle extends StatelessWidget {
- final String title;
- const SettingsSectionTitle(this.title, {Key key}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- return Container(
- child: Column(children: [
- Padding(padding: EdgeInsets.all(4)),
- Align(
- alignment: Alignment.centerLeft,
- child: Text(
- title,
- style: TextStyle(
- fontWeight: FontWeight.bold,
- fontSize: 16,
- color: Theme.of(context).accentColor,
- ),
- ),
- ),
- Padding(padding: EdgeInsets.all(4)),
- ]));
- }
- }
- class SupportSectionWidget extends StatelessWidget {
- const SupportSectionWidget({Key key}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- return Container(
- child: Column(children: [
- SettingsSectionTitle("support"),
- GestureDetector(
- behavior: HitTestBehavior.translucent,
- onTap: () {
- Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- final endpoint = Configuration.instance.getHttpEndpoint() +
- "/users/roadmap";
- final isLoggedIn = Configuration.instance.getToken() != null;
- final url = isLoggedIn
- ? endpoint + "?token=" + Configuration.instance.getToken()
- : ROADMAP_URL;
- return WebPage("roadmap", url);
- },
- ),
- );
- },
- child: SettingsTextItem(text: "roadmap", icon: Icons.navigate_next),
- ),
- Divider(height: 4),
- GestureDetector(
- behavior: HitTestBehavior.translucent,
- onTap: () async {
- final Email email = Email(
- recipients: ['hey@ente.io'],
- isHTML: false,
- );
- try {
- await FlutterEmailSender.send(email);
- } catch (e) {
- showGenericErrorDialog(context);
- }
- },
- onLongPress: () async {
- showToast("thanks for reporting a bug!");
- final dialog = createProgressDialog(context, "preparing logs...");
- await dialog.show();
- final tempPath = (await getTemporaryDirectory()).path;
- final zipFilePath = tempPath + "/logs.zip";
- final logsDirectory = Directory(tempPath + "/logs");
- var encoder = ZipFileEncoder();
- encoder.create(zipFilePath);
- encoder.addDirectory(logsDirectory);
- encoder.close();
- await dialog.hide();
- final Email email = Email(
- recipients: ['bug@ente.io'],
- attachmentPaths: [zipFilePath],
- isHTML: false,
- );
- try {
- await FlutterEmailSender.send(email);
- } catch (e) {
- return Share.shareFiles([zipFilePath]);
- }
- },
- child: SettingsTextItem(text: "email", icon: Icons.navigate_next),
- ),
- Divider(height: 4),
- GestureDetector(
- behavior: HitTestBehavior.translucent,
- onTap: () async {
- Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return CrispChatPage();
- },
- ),
- );
- },
- child: SettingsTextItem(text: "chat", icon: Icons.navigate_next),
- ),
- ]),
- );
- }
- }
- class InfoSectionWidget extends StatelessWidget {
- const InfoSectionWidget({Key key}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- return Container(
- child: Column(children: [
- SettingsSectionTitle("about"),
- GestureDetector(
- behavior: HitTestBehavior.translucent,
- onTap: () async {
- Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return WebPage("faq", "https://ente.io/faq");
- },
- ),
- );
- },
- child: SettingsTextItem(text: "faq", icon: Icons.navigate_next),
- ),
- Divider(height: 4),
- GestureDetector(
- behavior: HitTestBehavior.translucent,
- onTap: () {
- Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return WebPage("terms", "https://ente.io/terms");
- },
- ),
- );
- },
- child: SettingsTextItem(text: "terms", icon: Icons.navigate_next),
- ),
- Divider(height: 4),
- GestureDetector(
- behavior: HitTestBehavior.translucent,
- onTap: () {
- Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return WebPage("privacy", "https://ente.io/privacy");
- },
- ),
- );
- },
- child: SettingsTextItem(text: "privacy", icon: Icons.navigate_next),
- ),
- Divider(height: 4),
- GestureDetector(
- behavior: HitTestBehavior.translucent,
- onTap: () async {
- launch("https://github.com/ente-io/frame");
- },
- child:
- SettingsTextItem(text: "source code", icon: Icons.navigate_next),
- ),
- ]),
- );
- }
- }
- class AccountSectionWidget extends StatelessWidget {
- const AccountSectionWidget({Key key}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- return Container(
- child: Column(children: [
- Padding(padding: EdgeInsets.all(12)),
- SettingsSectionTitle("account"),
- GestureDetector(
- behavior: HitTestBehavior.translucent,
- onTap: () async {
- AlertDialog alert = AlertDialog(
- title: Text("logout"),
- content: Text("are you sure you want to logout?"),
- actions: [
- TextButton(
- child: Text(
- "no",
- style: TextStyle(
- color: Theme.of(context).buttonColor,
- ),
- ),
- onPressed: () {
- Navigator.of(context, rootNavigator: true).pop('dialog');
- },
- ),
- TextButton(
- child: Text(
- "yes, logout",
- style: TextStyle(
- color: Colors.red,
- ),
- ),
- onPressed: () async {
- Navigator.of(context, rootNavigator: true).pop('dialog');
- final dialog =
- createProgressDialog(context, "logging out...");
- await dialog.show();
- await Configuration.instance.logout();
- await dialog.hide();
- Navigator.of(context).popUntil((route) => route.isFirst);
- },
- ),
- ],
- );
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return alert;
- },
- );
- },
- child: SettingsTextItem(text: "logout", icon: Icons.navigate_next),
- ),
- ]),
- );
- }
- }
- class DebugWidget extends StatelessWidget {
- const DebugWidget({Key key}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- return Container(
- child: Column(children: [
- Padding(padding: EdgeInsets.all(12)),
- SettingsSectionTitle("debug"),
- GestureDetector(
- behavior: HitTestBehavior.translucent,
- onTap: () async {
- _showKeyAttributesDialog(context);
- },
- child: SettingsTextItem(
- text: "key attributes", icon: Icons.navigate_next),
- ),
- ]),
- );
- }
- void _showKeyAttributesDialog(BuildContext context) {
- final keyAttributes = Configuration.instance.getKeyAttributes();
- AlertDialog alert = AlertDialog(
- title: Text("key attributes"),
- content: SingleChildScrollView(
- child: Column(children: [
- Text("Key", style: TextStyle(fontWeight: FontWeight.bold)),
- Text(Sodium.bin2base64(Configuration.instance.getKey())),
- Padding(padding: EdgeInsets.all(12)),
- Text("Encrypted Key", style: TextStyle(fontWeight: FontWeight.bold)),
- Text(keyAttributes.encryptedKey),
- Padding(padding: EdgeInsets.all(12)),
- Text("Key Decryption Nonce",
- style: TextStyle(fontWeight: FontWeight.bold)),
- Text(keyAttributes.keyDecryptionNonce),
- Padding(padding: EdgeInsets.all(12)),
- Text("KEK Salt", style: TextStyle(fontWeight: FontWeight.bold)),
- Text(keyAttributes.kekSalt),
- Padding(padding: EdgeInsets.all(12)),
- ]),
- ),
- actions: [
- FlatButton(
- child: Text("OK"),
- onPressed: () {
- Navigator.of(context, rootNavigator: true).pop('dialog');
- },
- ),
- ],
- );
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return alert;
- },
- );
- }
- }
- class SettingsTextItem extends StatelessWidget {
- final String text;
- final IconData icon;
- const SettingsTextItem({
- Key key,
- @required this.text,
- @required this.icon,
- }) : super(key: key);
- @override
- Widget build(BuildContext context) {
- return Column(
- children: [
- Padding(padding: EdgeInsets.all(Platform.isIOS ? 4 : 6)),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Align(alignment: Alignment.centerLeft, child: Text(text)),
- Icon(icon),
- ],
- ),
- Padding(padding: EdgeInsets.all(Platform.isIOS ? 2 : 6)),
- ],
- );
- }
- }
- class CrispChatPage extends StatefulWidget {
- CrispChatPage({Key key}) : super(key: key);
- @override
- _CrispChatPageState createState() => _CrispChatPageState();
- }
- class _CrispChatPageState extends State<CrispChatPage> {
- static const websiteID = "86d56ea2-68a2-43f9-8acb-95e06dee42e8";
- @override
- void initState() {
- crisp.initialize(
- websiteId: websiteID,
- );
- crisp.register(
- CrispUser(
- email: Configuration.instance.getEmail(),
- ),
- );
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text("support chat"),
- ),
- body: CrispView(
- loadingWidget: loadWidget,
- ),
- );
- }
- }
|