mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-27 17:29:50 +08:00
GitRemoteSettings -> Let a custom SSH key be provided
Just like during the GitHost Setup.
This commit is contained in:
@ -332,6 +332,7 @@ setup:
|
||||
openDeploy: Open Deploy Key Webpage
|
||||
clone: Clone Repo
|
||||
addDeploy: Adding as a Deploy Key
|
||||
save: Save
|
||||
sshKeyChoice:
|
||||
title: We need SSH keys to authenticate -
|
||||
generate: Generate new keys
|
||||
|
@ -56,6 +56,12 @@ class _GitRemoteSettingsScreenState extends State<GitRemoteSettingsScreen> {
|
||||
onPressed: () => _generateSshKey(context),
|
||||
),
|
||||
),
|
||||
Builder(
|
||||
builder: (BuildContext context) => Button(
|
||||
text: tr('setup.sshKeyChoice.custom'),
|
||||
onPressed: _customSshKeys,
|
||||
),
|
||||
),
|
||||
ListPreference(
|
||||
title: tr('settings.ssh.syncFreq'),
|
||||
currentOption: settings.remoteSyncFrequency.toPublicString(),
|
||||
@ -87,13 +93,44 @@ class _GitRemoteSettingsScreenState extends State<GitRemoteSettingsScreen> {
|
||||
},
|
||||
),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: body,
|
||||
body: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: body,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _customSshKeys() {
|
||||
var route = MaterialPageRoute(
|
||||
builder: (context) => Scaffold(
|
||||
body: GitHostUserProvidedKeys(
|
||||
doneFunction: _updateKeys,
|
||||
saveText: tr("setup.sshKey.save"),
|
||||
),
|
||||
appBar: AppBar(
|
||||
title: Text(tr('setup.sshKeyChoice.custom')),
|
||||
),
|
||||
),
|
||||
settings: const RouteSettings(name: '/settings/gitRemote/customKeys'),
|
||||
);
|
||||
Navigator.of(context).push(route);
|
||||
}
|
||||
|
||||
void _updateKeys(String publicKey, String privateKey) {
|
||||
var settings = Provider.of<Settings>(context, listen: false);
|
||||
|
||||
if (publicKey.isEmpty || privateKey.isEmpty) {
|
||||
return;
|
||||
}
|
||||
settings.sshPublicKey = publicKey;
|
||||
settings.sshPrivateKey = privateKey;
|
||||
settings.save();
|
||||
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
void _copyKeyToClipboard(BuildContext context) {
|
||||
Clipboard.setData(ClipboardData(text: widget.sshPublicKey));
|
||||
showSnackbar(context, tr('setup.sshKey.copied'));
|
||||
|
@ -204,10 +204,12 @@ class GitHostSetupKeyChoice extends StatelessWidget {
|
||||
}
|
||||
|
||||
class GitHostUserProvidedKeys extends StatefulWidget {
|
||||
final Func2<String, String, void> doneFunction;
|
||||
final Func2<String, String, void> doneFunction; // public, private
|
||||
final String saveText;
|
||||
|
||||
GitHostUserProvidedKeys({
|
||||
@required this.doneFunction,
|
||||
this.saveText = "",
|
||||
});
|
||||
|
||||
@override
|
||||
@ -221,6 +223,8 @@ class _GitHostUserProvidedKeysState extends State<GitHostUserProvidedKeys> {
|
||||
TextEditingController _publicKeyController;
|
||||
TextEditingController _privateKeyController;
|
||||
|
||||
String saveText;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@ -229,6 +233,8 @@ class _GitHostUserProvidedKeysState extends State<GitHostUserProvidedKeys> {
|
||||
_privateFormKey = GlobalKey<FormState>();
|
||||
_publicKeyController = TextEditingController();
|
||||
_privateKeyController = TextEditingController();
|
||||
|
||||
saveText = widget.saveText.isEmpty ? tr("setup.next") : widget.saveText;
|
||||
}
|
||||
|
||||
@override
|
||||
@ -241,7 +247,7 @@ class _GitHostUserProvidedKeysState extends State<GitHostUserProvidedKeys> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
var body = Container(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
@ -259,7 +265,7 @@ class _GitHostUserProvidedKeysState extends State<GitHostUserProvidedKeys> {
|
||||
PrivateKeyEditor(_privateFormKey, _privateKeyController),
|
||||
const SizedBox(height: 16.0),
|
||||
GitHostSetupButton(
|
||||
text: tr("setup.next"),
|
||||
text: saveText,
|
||||
onPressed: () {
|
||||
var publicValid = _publicFormKey.currentState.validate();
|
||||
var privateValid = _privateFormKey.currentState.validate();
|
||||
@ -286,6 +292,13 @@ class _GitHostUserProvidedKeysState extends State<GitHostUserProvidedKeys> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
),
|
||||
);
|
||||
|
||||
return SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: body,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user