diff --git a/assets/langs/en.yaml b/assets/langs/en.yaml index 337bf43e..cc6afe4b 100644 --- a/assets/langs/en.yaml +++ b/assets/langs/en.yaml @@ -311,6 +311,7 @@ setup: keyEditors: public: Invalid Public Key - Doesn't start with ssh-rsa private: Invalid Private Key + load: Load from File sshKey: generate: Generating SSH Key title: In order to access this repository, this public key must be copied as a deploy key diff --git a/changelog.yml b/changelog.yml index b3288138..a16973be 100644 --- a/changelog.yml +++ b/changelog.yml @@ -1,5 +1,8 @@ - version: "1.71" draft: true + improvements: + - text: "Allow SSH Keys to be loaded from the FS - #74" + image: ssh_key_file.jpeg bugs: - text: "Dark Theme: Render checkboxes in a lighter color" - text: "Fix Relative Parent links not working - #256" diff --git a/lib/setup/key_editors.dart b/lib/setup/key_editors.dart index f8a039ef..5b4da8f7 100644 --- a/lib/setup/key_editors.dart +++ b/lib/setup/key_editors.dart @@ -1,6 +1,11 @@ +import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:easy_localization/easy_localization.dart'; +import 'package:file_picker/file_picker.dart'; + +import 'package:gitjournal/utils/logger.dart'; class PublicKeyEditor extends StatelessWidget { final Key formKey; @@ -74,18 +79,45 @@ class KeyEditor extends StatelessWidget { autovalidateMode: AutovalidateMode.onUserInteraction, ); - return SizedBox( - width: double.infinity, - height: 80.0, - child: Container( - color: Theme.of(context).buttonColor, - child: SingleChildScrollView( - child: Container( - padding: const EdgeInsets.all(8.0), - child: form, + var screenSize = MediaQuery.of(context).size; + + return Column( + children: [ + Container( + constraints: BoxConstraints( + maxHeight: screenSize.height / 4, + ), + color: Theme.of(context).buttonColor, + child: SingleChildScrollView( + child: Container( + padding: const EdgeInsets.all(8.0), + child: form, + ), ), ), - ), + OutlineButton( + child: Text(tr("setup.keyEditors.load")), + onPressed: _pickAndLoadFile, + ), + ], ); } + + void _pickAndLoadFile() async { + var result = await FilePicker.platform.pickFiles(); + + if (result != null) { + var file = File(result.files.single.path); + try { + var data = await file.readAsString(); + textEditingController.text = data.trim(); + } catch (e, stackTrace) { + Log.e( + "Open File for importing SSH Key", + ex: e, + stacktrace: stackTrace, + ); + } + } + } } diff --git a/pubspec.lock b/pubspec.lock index 0357af21..dee97a3b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -241,6 +241,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "6.0.0-nullsafety.2" + file_picker: + dependency: "direct main" + description: + name: file_picker + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.6" fimber: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 14363874..4541e370 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -58,6 +58,7 @@ dependencies: timeago: ^2.0.27 multicast_dns: ^0.2.2 bonsoir: ^0.1.2+2 + file_picker: ^2.0.6 dev_dependencies: flutter_launcher_icons: "^0.7.2"