diff --git a/lib/Consts2.dart b/lib/Consts2.dart index 1bc52c2..35ccb62 100644 --- a/lib/Consts2.dart +++ b/lib/Consts2.dart @@ -1 +1 @@ -const VERSION = "1.0722.24+1506"; +const VERSION = "1.0724.24+0706"; diff --git a/lib/Editor.dart b/lib/Editor.dart index 8a7189c..7352c9c 100644 --- a/lib/Editor.dart +++ b/lib/Editor.dart @@ -1,3 +1,4 @@ +import 'dart:io'; import 'dart:typed_data'; import 'package:flutter/material.dart'; @@ -12,6 +13,7 @@ import 'package:nbteditor/Consts2.dart'; import 'package:nbteditor/SessionData.dart'; import 'package:nbteditor/tags/CompoundTag.dart'; import 'package:nbteditor/tags/Tag.dart'; +import 'package:permission_handler/permission_handler.dart'; class Editor extends StatefulWidget { const Editor({super.key}); @@ -127,7 +129,7 @@ class EditorState extends State { title: const Text("S A V E N B T"), subtitle: const Text("Save to NBT"), leading: const Image( - image: AssetImage("Icons/PNG/nbteditor.png"), + image: AssetImage("Icons/PNG/Compound.png"), ), onTap: () async { var result = await showDialog( @@ -161,8 +163,7 @@ class EditorState extends State { } // Prompt for where to save print("Begin picking file to save to"); - var params = SaveFileDialogParams(data: u8l); - var filePath = await FlutterFileDialog.saveFile(params: params); + var filePath = await FlutterFileDialog.saveFile(); if (filePath == null) { print("No file selected"); diff --git a/lib/main.dart b/lib/main.dart index ff68eef..34e896b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'package:nbteditor/Editor.dart'; import 'package:nbteditor/pages/AddPage.dart'; import 'package:nbteditor/pages/SNBTEditor.dart'; +import 'package:nbteditor/pages/permsrequired.dart'; +import 'package:permission_handler/permission_handler.dart'; void main() { runApp(const MainApp()); @@ -15,10 +17,45 @@ class MainApp extends StatelessWidget { return MaterialApp( theme: ThemeData.dark(), routes: { - "/": (context) => const Editor(), + "/": (context) => StartPage(), + "/edit": (context) => const Editor(), "/add": (context) => const AddPage(), "/snbt": (context) => const SnbtEdit(), + "/perms": (context) => PermissionsRequiredPage() }, ); } } + +class StartPage extends StatefulWidget { + @override + State createState() { + return StartPageState(); + } +} + +class StartPageState extends State { + @override + void didChangeDependencies() { + checkPermissions(); + } + + Future checkPermissions() async { + if (await Permission.manageExternalStorage.isDenied) { + await Future.delayed(Duration(seconds: 5), () { + Navigator.pushReplacementNamed(context, "/perms"); + }); + } else { + Navigator.pushReplacementNamed(context, "/edit"); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Column( + children: [Image(image: AssetImage("Icons/PNG/nbteditor.png"))], + ), + ); + } +} diff --git a/lib/pages/permsrequired.dart b/lib/pages/permsrequired.dart new file mode 100644 index 0000000..8509301 --- /dev/null +++ b/lib/pages/permsrequired.dart @@ -0,0 +1,44 @@ +import 'package:flutter/material.dart'; +import 'package:nbteditor/Constants.dart'; +import 'package:permission_handler/permission_handler.dart'; + +class PermissionsRequiredPage extends StatelessWidget { + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text("NBT Editor - Permissions Denied"), + backgroundColor: Constants.TITLEBAR_COLOR, + ), + body: Padding( + padding: EdgeInsets.all(8), + child: SingleChildScrollView( + child: Column( + children: [ + ListTile( + title: Text( + "We require only one permission, it is being denied by your device. Please grant file permissions to be able to open or save files."), + ), + ElevatedButton( + onPressed: () async { + if (await Permission.manageExternalStorage.isDenied) { + var stat = + await Permission.manageExternalStorage.request(); + if (stat.isPermanentlyDenied) { + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text( + "The storage permission is reporting it is permanently denied. Please open settings and allow that permission."))); + } else if (stat.isGranted) { + Future.delayed(Duration(seconds: 5), () { + Navigator.pushReplacementNamed(context, "/edit"); + }); + } + } + }, + child: Text("GRANT")) + ], + ), + ), + )); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 1b3ef26..38ddb1b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: nbteditor description: A Minecraft NBT Editor written in Flutter publish_to: 'none' -version: 1.0722.24+1907 +version: 1.0724.24+0706 environment: @@ -17,6 +17,7 @@ dependencies: libac_dart: hosted: https://git.zontreck.com/api/packages/AriasCreations/pub/ version: 1.2.072224+1906 + permission_handler: ^11.3.1 dev_dependencies: flutter_test: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 4f78848..a0d0bbe 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,9 +6,12 @@ #include "generated_plugin_registrant.h" +#include #include void RegisterPlugins(flutter::PluginRegistry* registry) { + PermissionHandlerWindowsPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); UrlLauncherWindowsRegisterWithRegistrar( registry->GetRegistrarForPlugin("UrlLauncherWindows")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 88b22e5..c20a586 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + permission_handler_windows url_launcher_windows ) diff --git a/wininst.iss b/wininst.iss index a69b6f7..7908009 100644 --- a/wininst.iss +++ b/wininst.iss @@ -2,7 +2,7 @@ ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "NBT Editor" -#define MyAppVersion "1.0722.24.1506" +#define MyAppVersion "1.0724.24+0706" #define MyAppPublisher "Piccari Creations" #define MyAppURL "https://zontreck.com" #define MyAppExeName "nbteditor.exe"