From 72d6c2ce34d1f735a098204295fd512237bf7e0e Mon Sep 17 00:00:00 2001 From: zontreck Date: Wed, 24 Jul 2024 17:33:55 -0700 Subject: [PATCH] Restructure to make more sense --- lib/Editor.dart | 13 +++++++++++++ lib/main.dart | 25 ++++++++++++++++++++----- lib/pages/permsrequired.dart | 2 +- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/Editor.dart b/lib/Editor.dart index b40c755..8d900e5 100644 --- a/lib/Editor.dart +++ b/lib/Editor.dart @@ -10,6 +10,7 @@ import 'package:libac_dart/nbt/impl/CompoundTag.dart'; import 'package:nbteditor/Constants.dart'; import 'package:nbteditor/Consts2.dart'; import 'package:nbteditor/SessionData.dart'; +import 'package:nbteditor/main.dart'; import 'package:nbteditor/tags/CompoundTag.dart'; import 'package:nbteditor/tags/Tag.dart'; @@ -89,6 +90,10 @@ class EditorState extends State { leading: const Icon(Icons.folder), subtitle: const Text("Open an existing NBT Document for editing"), onTap: () async { + if (await needsPermissionsPage()) { + Navigator.pushNamed(context, "/perms"); + return; + } String? filePath; var result = await FilePicker.platform.pickFiles(); if (result != null) { @@ -131,6 +136,10 @@ class EditorState extends State { image: AssetImage("Icons/PNG/Compound.png"), ), onTap: () async { + if (await needsPermissionsPage()) { + Navigator.pushNamed(context, "/perms"); + return; + } var result = await showDialog( context: context, builder: (builder) { @@ -181,6 +190,10 @@ class EditorState extends State { image: AssetImage("Icons/PNG/String.png"), ), onTap: () async { + if (await needsPermissionsPage()) { + Navigator.pushNamed(context, "/perms"); + return; + } // Prompt for where to save print("Begin picking file to save to"); var FSL = await FilePicker.platform.saveFile(bytes: Uint8List(0)); diff --git a/lib/main.dart b/lib/main.dart index bac7650..2dc29c6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,20 +7,21 @@ import 'package:nbteditor/pages/SNBTEditor.dart'; import 'package:nbteditor/pages/permsrequired.dart'; import 'package:permission_handler/permission_handler.dart'; -void main() { - runApp(const MainApp()); +void main() async { + runApp(MainApp()); } class MainApp extends StatelessWidget { - const MainApp({super.key}); + MainApp({ + super.key, + }); @override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData.dark(), routes: { - "/": (context) => const StartPage(), - "/edit": (context) => const Editor(), + "/": (context) => const Editor(), "/add": (context) => const AddPage(), "/snbt": (context) => const SnbtEdit(), "/perms": (context) => const PermissionsRequiredPage() @@ -29,6 +30,20 @@ class MainApp extends StatelessWidget { } } +bool needsPermissions() { + return Platform.isIOS || Platform.isMacOS || Platform.isAndroid; +} + +Future needsPermissionsPage() async { + if (needsPermissions()) { + if (await Permission.manageExternalStorage.isDenied) { + return true; + } else + return false; + } else + return false; +} + class StartPage extends StatefulWidget { const StartPage({super.key}); diff --git a/lib/pages/permsrequired.dart b/lib/pages/permsrequired.dart index e7d7fa5..c3d890e 100644 --- a/lib/pages/permsrequired.dart +++ b/lib/pages/permsrequired.dart @@ -32,7 +32,7 @@ class PermissionsRequiredPage extends StatelessWidget { "The storage permission is reporting it is permanently denied. Please open settings and allow that permission."))); } else if (stat.isGranted) { Future.delayed(const Duration(seconds: 5), () { - Navigator.pushReplacementNamed(context, "/edit"); + Navigator.pop(context); }); } }