Don't ask android where to save

This commit is contained in:
julian 2022-09-30 18:46:52 -06:00
parent c803519a42
commit 8243eb1a86
7 changed files with 300 additions and 226 deletions

View file

@ -303,13 +303,17 @@ class _DebugViewState extends ConsumerState<DebugView> {
Logging.instance Logging.instance
.log("$e\n$s", level: LogLevel.Error); .log("$e\n$s", level: LogLevel.Error);
} }
String? path;
final String? path = if (Platform.isAndroid) {
await FilePicker.platform.getDirectoryPath( path = dir.path;
} else {
path = await FilePicker.platform
.getDirectoryPath(
dialogTitle: "Choose Backup location", dialogTitle: "Choose Backup location",
initialDirectory: dir.path, initialDirectory: dir.path,
lockParentWindow: true, lockParentWindow: true,
); );
}
if (path != null) { if (path != null) {
final eventBus = EventBus(); final eventBus = EventBus();
@ -328,7 +332,7 @@ class _DebugViewState extends ConsumerState<DebugView> {
), ),
)); ));
await ref final filename = await ref
.read(debugServiceProvider) .read(debugServiceProvider)
.exportToFile(path, eventBus); .exportToFile(path, eventBus);
@ -336,10 +340,26 @@ class _DebugViewState extends ConsumerState<DebugView> {
if (mounted) { if (mounted) {
Navigator.pop(context); Navigator.pop(context);
unawaited(showFloatingFlushBar(
if (Platform.isAndroid) {
unawaited(
showDialog(
context: context,
builder: (context) => StackOkDialog(
title: "Logs saved to",
message: "${path!}/$filename",
),
),
);
} else {
unawaited(
showFloatingFlushBar(
type: FlushBarType.info, type: FlushBarType.info,
context: context, context: context,
message: 'Logs file saved')); message: 'Logs file saved',
),
);
}
} }
} }
}, },

View file

@ -82,6 +82,17 @@ class _EnableAutoBackupViewState extends ConsumerState<CreateAutoBackupView> {
passwordFocusNode = FocusNode(); passwordFocusNode = FocusNode();
passwordRepeatFocusNode = FocusNode(); passwordRepeatFocusNode = FocusNode();
if (Platform.isAndroid) {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
final dir = await stackFileSystem.prepareStorage();
if (mounted) {
setState(() {
fileLocationController.text = dir.path;
});
}
});
}
super.initState(); super.initState();
} }
@ -133,8 +144,11 @@ class _EnableAutoBackupViewState extends ConsumerState<CreateAutoBackupView> {
const SizedBox( const SizedBox(
height: 10, height: 10,
), ),
if (!Platform.isAndroid)
TextField( TextField(
onTap: () async { onTap: Platform.isAndroid
? null
: () async {
try { try {
await stackFileSystem.prepareStorage(); await stackFileSystem.prepareStorage();
@ -149,13 +163,15 @@ class _EnableAutoBackupViewState extends ConsumerState<CreateAutoBackupView> {
}); });
} }
} catch (e, s) { } catch (e, s) {
Logging.instance.log("$e\n$s", level: LogLevel.Error); Logging.instance
.log("$e\n$s", level: LogLevel.Error);
} }
}, },
controller: fileLocationController, controller: fileLocationController,
style: STextStyles.field(context), style: STextStyles.field(context),
decoration: InputDecoration( decoration: InputDecoration(
hintText: "Save to...", hintText: "Save to...",
hintStyle: STextStyles.fieldLabel(context),
suffixIcon: UnconstrainedBox( suffixIcon: UnconstrainedBox(
child: Row( child: Row(
children: [ children: [
@ -188,6 +204,7 @@ class _EnableAutoBackupViewState extends ConsumerState<CreateAutoBackupView> {
), ),
onChanged: (newValue) {}, onChanged: (newValue) {},
), ),
if (!Platform.isAndroid)
const SizedBox( const SizedBox(
height: 10, height: 10,
), ),
@ -593,8 +610,15 @@ class _EnableAutoBackupViewState extends ConsumerState<CreateAutoBackupView> {
await showDialog<dynamic>( await showDialog<dynamic>(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
builder: (_) => const StackOkDialog( builder: (_) => Platform.isAndroid
title: "Stack Auto Backup enabled!"), ? StackOkDialog(
title:
"Stack Auto Backup enabled and saved to:",
message: fileToSave,
)
: const StackOkDialog(
title:
"Stack Auto Backup enabled!"),
); );
if (mounted) { if (mounted) {
passwordController.text = ""; passwordController.text = "";

View file

@ -64,6 +64,17 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
passwordFocusNode = FocusNode(); passwordFocusNode = FocusNode();
passwordRepeatFocusNode = FocusNode(); passwordRepeatFocusNode = FocusNode();
if (Platform.isAndroid) {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
final dir = await stackFileSystem.prepareStorage();
if (mounted) {
setState(() {
fileLocationController.text = dir.path;
});
}
});
}
super.initState(); super.initState();
} }
@ -113,49 +124,38 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
if (!Platform.isAndroid)
Consumer(builder: (context, ref, __) { Consumer(builder: (context, ref, __) {
return Container( return Container(
color: Colors.transparent, color: Colors.transparent,
child: TextField( child: TextField(
onTap: () async { onTap: Platform.isAndroid
? null
: () async {
try { try {
await stackFileSystem.prepareStorage(); await stackFileSystem.prepareStorage();
// ref
// .read(
// shouldShowLockscreenOnResumeStateProvider
// .state)
// .state = false;
if (mounted) { if (mounted) {
await stackFileSystem.pickDir(context); await stackFileSystem
.pickDir(context);
} }
// Future<void>.delayed( if (mounted) {
// const Duration(seconds: 2),
// () => ref
// .read(
// shouldShowLockscreenOnResumeStateProvider
// .state)
// .state = true,
// );
setState(() { setState(() {
fileLocationController.text = fileLocationController.text =
stackFileSystem.dirPath ?? ""; stackFileSystem.dirPath ?? "";
}); });
}
} catch (e, s) { } catch (e, s) {
// ref Logging.instance.log("$e\n$s",
// .read( level: LogLevel.Error);
// shouldShowLockscreenOnResumeStateProvider
// .state)
// .state = true;
Logging.instance
.log("$e\n$s", level: LogLevel.Error);
} }
}, },
controller: fileLocationController, controller: fileLocationController,
style: STextStyles.field(context), style: STextStyles.field(context),
decoration: InputDecoration( decoration: InputDecoration(
hintText: "Save to...", hintText: "Save to...",
hintStyle: STextStyles.fieldLabel(context),
suffixIcon: UnconstrainedBox( suffixIcon: UnconstrainedBox(
child: Row( child: Row(
children: [ children: [
@ -192,6 +192,7 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
), ),
); );
}), }),
if (!Platform.isAndroid)
const SizedBox( const SizedBox(
height: 8, height: 8,
), ),
@ -315,8 +316,12 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
.extension<StackColors>()! .extension<StackColors>()!
.accentColorRed .accentColorRed
: passwordStrength < 1 : passwordStrength < 1
? Theme.of(context).extension<StackColors>()!.accentColorYellow ? Theme.of(context)
: Theme.of(context).extension<StackColors>()!.accentColorGreen, .extension<StackColors>()!
.accentColorYellow
: Theme.of(context)
.extension<StackColors>()!
.accentColorGreen,
backgroundColor: Theme.of(context) backgroundColor: Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
.buttonBackSecondary, .buttonBackSecondary,
@ -389,8 +394,12 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
const Spacer(), const Spacer(),
TextButton( TextButton(
style: shouldEnableCreate style: shouldEnableCreate
? Theme.of(context) .extension<StackColors>()!.getPrimaryEnabledButtonColor(context) ? Theme.of(context)
: Theme.of(context) .extension<StackColors>()!.getPrimaryDisabledButtonColor(context), .extension<StackColors>()!
.getPrimaryEnabledButtonColor(context)
: Theme.of(context)
.extension<StackColors>()!
.getPrimaryDisabledButtonColor(context),
onPressed: !shouldEnableCreate onPressed: !shouldEnableCreate
? null ? null
: () async { : () async {
@ -468,8 +477,14 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
await showDialog<dynamic>( await showDialog<dynamic>(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
builder: (_) => const StackOkDialog( builder: (_) => Platform.isAndroid
title: "Backup creation succeeded"), ? StackOkDialog(
title: "Backup saved to:",
message: fileToSave,
)
: const StackOkDialog(
title:
"Backup creation succeeded"),
); );
passwordController.text = ""; passwordController.text = "";
passwordRepeatController.text = ""; passwordRepeatController.text = "";

View file

@ -84,6 +84,17 @@ class _EditAutoBackupViewState extends ConsumerState<EditAutoBackupView> {
passwordFocusNode = FocusNode(); passwordFocusNode = FocusNode();
passwordRepeatFocusNode = FocusNode(); passwordRepeatFocusNode = FocusNode();
if (Platform.isAndroid) {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
final dir = await stackFileSystem.prepareStorage();
if (mounted) {
setState(() {
fileLocationController.text = dir.path;
});
}
});
}
super.initState(); super.initState();
} }
@ -135,8 +146,11 @@ class _EditAutoBackupViewState extends ConsumerState<EditAutoBackupView> {
const SizedBox( const SizedBox(
height: 10, height: 10,
), ),
if (!Platform.isAndroid)
TextField( TextField(
onTap: () async { onTap: Platform.isAndroid
? null
: () async {
try { try {
await stackFileSystem.prepareStorage(); await stackFileSystem.prepareStorage();
@ -151,13 +165,15 @@ class _EditAutoBackupViewState extends ConsumerState<EditAutoBackupView> {
}); });
} }
} catch (e, s) { } catch (e, s) {
Logging.instance.log("$e\n$s", level: LogLevel.Error); Logging.instance
.log("$e\n$s", level: LogLevel.Error);
} }
}, },
controller: fileLocationController, controller: fileLocationController,
style: STextStyles.field(context), style: STextStyles.field(context),
decoration: InputDecoration( decoration: InputDecoration(
hintText: "Save to...", hintText: "Save to...",
hintStyle: STextStyles.fieldLabel(context),
suffixIcon: UnconstrainedBox( suffixIcon: UnconstrainedBox(
child: Row( child: Row(
children: [ children: [
@ -190,6 +206,7 @@ class _EditAutoBackupViewState extends ConsumerState<EditAutoBackupView> {
), ),
onChanged: (newValue) {}, onChanged: (newValue) {},
), ),
if (!Platform.isAndroid)
const SizedBox( const SizedBox(
height: 10, height: 10,
), ),
@ -594,7 +611,13 @@ class _EditAutoBackupViewState extends ConsumerState<EditAutoBackupView> {
await showDialog<dynamic>( await showDialog<dynamic>(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
builder: (_) => const StackOkDialog( builder: (_) => Platform.isAndroid
? StackOkDialog(
title:
"Stack Auto Backup saved to:",
message: fileToSave,
)
: const StackOkDialog(
title: "Stack Auto Backup saved"), title: "Stack Auto Backup saved"),
); );
if (mounted) { if (mounted) {

View file

@ -13,7 +13,7 @@ class StackFileSystem {
final bool isDesktop = !(Platform.isAndroid || Platform.isIOS); final bool isDesktop = !(Platform.isAndroid || Platform.isIOS);
Future<void> prepareStorage() async { Future<Directory> prepareStorage() async {
rootPath = (await getApplicationDocumentsDirectory()); rootPath = (await getApplicationDocumentsDirectory());
debugPrint(rootPath!.absolute.toString()); debugPrint(rootPath!.absolute.toString());
if (Platform.isAndroid) { if (Platform.isAndroid) {
@ -47,6 +47,7 @@ class StackFileSystem {
debugPrint("$e $s"); debugPrint("$e $s");
} }
startPath = sampleFolder; startPath = sampleFolder;
return sampleFolder;
} }
Future<void> pickDir(BuildContext context) async { Future<void> pickDir(BuildContext context) async {

View file

@ -99,29 +99,17 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> {
onTap: () async { onTap: () async {
try { try {
await stackFileSystem.prepareStorage(); await stackFileSystem.prepareStorage();
// ref if (mounted) {
// .read(shouldShowLockscreenOnResumeStateProvider
// .state)
// .state = false;
await stackFileSystem.openFile(context); await stackFileSystem.openFile(context);
}
// Future<void>.delayed( if (mounted) {
// const Duration(seconds: 2), setState(() {
// () => ref
// .read(
// shouldShowLockscreenOnResumeStateProvider
// .state)
// .state = true,
// );
fileLocationController.text = fileLocationController.text =
stackFileSystem.filePath ?? ""; stackFileSystem.filePath ?? "";
setState(() {}); });
}
} catch (e, s) { } catch (e, s) {
// ref
// .read(shouldShowLockscreenOnResumeStateProvider
// .state)
// .state = true;
Logging.instance Logging.instance
.log("$e\n$s", level: LogLevel.Error); .log("$e\n$s", level: LogLevel.Error);
} }
@ -130,6 +118,7 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> {
style: STextStyles.field(context), style: STextStyles.field(context),
decoration: InputDecoration( decoration: InputDecoration(
hintText: "Choose file...", hintText: "Choose file...",
hintStyle: STextStyles.fieldLabel(context),
suffixIcon: UnconstrainedBox( suffixIcon: UnconstrainedBox(
child: Row( child: Row(
children: [ children: [

View file

@ -75,7 +75,8 @@ class DebugService extends ChangeNotifier {
level: LogLevel.Info); level: LogLevel.Info);
} }
Future<void> exportToFile(String directory, EventBus eventBus) async { /// returns the filename of the saved logs file
Future<String> exportToFile(String directory, EventBus eventBus) async {
final now = DateTime.now(); final now = DateTime.now();
final filename = final filename =
"Stack_Wallet_logs_${now.year}_${now.month}_${now.day}_${now.hour}_${now.minute}_${now.second}.txt"; "Stack_Wallet_logs_${now.year}_${now.month}_${now.day}_${now.hour}_${now.minute}_${now.second}.txt";
@ -99,5 +100,6 @@ class DebugService extends ChangeNotifier {
await sink.close(); await sink.close();
eventBus.fire(1.0); eventBus.fire(1.0);
return filename;
} }
} }