mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +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
|
openDeploy: Open Deploy Key Webpage
|
||||||
clone: Clone Repo
|
clone: Clone Repo
|
||||||
addDeploy: Adding as a Deploy Key
|
addDeploy: Adding as a Deploy Key
|
||||||
|
save: Save
|
||||||
sshKeyChoice:
|
sshKeyChoice:
|
||||||
title: We need SSH keys to authenticate -
|
title: We need SSH keys to authenticate -
|
||||||
generate: Generate new keys
|
generate: Generate new keys
|
||||||
|
@ -56,6 +56,12 @@ class _GitRemoteSettingsScreenState extends State<GitRemoteSettingsScreen> {
|
|||||||
onPressed: () => _generateSshKey(context),
|
onPressed: () => _generateSshKey(context),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Builder(
|
||||||
|
builder: (BuildContext context) => Button(
|
||||||
|
text: tr('setup.sshKeyChoice.custom'),
|
||||||
|
onPressed: _customSshKeys,
|
||||||
|
),
|
||||||
|
),
|
||||||
ListPreference(
|
ListPreference(
|
||||||
title: tr('settings.ssh.syncFreq'),
|
title: tr('settings.ssh.syncFreq'),
|
||||||
currentOption: settings.remoteSyncFrequency.toPublicString(),
|
currentOption: settings.remoteSyncFrequency.toPublicString(),
|
||||||
@ -87,13 +93,44 @@ class _GitRemoteSettingsScreenState extends State<GitRemoteSettingsScreen> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
body: Padding(
|
body: SingleChildScrollView(
|
||||||
padding: const EdgeInsets.all(16.0),
|
child: Padding(
|
||||||
child: body,
|
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) {
|
void _copyKeyToClipboard(BuildContext context) {
|
||||||
Clipboard.setData(ClipboardData(text: widget.sshPublicKey));
|
Clipboard.setData(ClipboardData(text: widget.sshPublicKey));
|
||||||
showSnackbar(context, tr('setup.sshKey.copied'));
|
showSnackbar(context, tr('setup.sshKey.copied'));
|
||||||
|
@ -204,10 +204,12 @@ class GitHostSetupKeyChoice extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class GitHostUserProvidedKeys extends StatefulWidget {
|
class GitHostUserProvidedKeys extends StatefulWidget {
|
||||||
final Func2<String, String, void> doneFunction;
|
final Func2<String, String, void> doneFunction; // public, private
|
||||||
|
final String saveText;
|
||||||
|
|
||||||
GitHostUserProvidedKeys({
|
GitHostUserProvidedKeys({
|
||||||
@required this.doneFunction,
|
@required this.doneFunction,
|
||||||
|
this.saveText = "",
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -221,6 +223,8 @@ class _GitHostUserProvidedKeysState extends State<GitHostUserProvidedKeys> {
|
|||||||
TextEditingController _publicKeyController;
|
TextEditingController _publicKeyController;
|
||||||
TextEditingController _privateKeyController;
|
TextEditingController _privateKeyController;
|
||||||
|
|
||||||
|
String saveText;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@ -229,6 +233,8 @@ class _GitHostUserProvidedKeysState extends State<GitHostUserProvidedKeys> {
|
|||||||
_privateFormKey = GlobalKey<FormState>();
|
_privateFormKey = GlobalKey<FormState>();
|
||||||
_publicKeyController = TextEditingController();
|
_publicKeyController = TextEditingController();
|
||||||
_privateKeyController = TextEditingController();
|
_privateKeyController = TextEditingController();
|
||||||
|
|
||||||
|
saveText = widget.saveText.isEmpty ? tr("setup.next") : widget.saveText;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -241,7 +247,7 @@ class _GitHostUserProvidedKeysState extends State<GitHostUserProvidedKeys> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
var body = Container(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text(
|
Text(
|
||||||
@ -259,7 +265,7 @@ class _GitHostUserProvidedKeysState extends State<GitHostUserProvidedKeys> {
|
|||||||
PrivateKeyEditor(_privateFormKey, _privateKeyController),
|
PrivateKeyEditor(_privateFormKey, _privateKeyController),
|
||||||
const SizedBox(height: 16.0),
|
const SizedBox(height: 16.0),
|
||||||
GitHostSetupButton(
|
GitHostSetupButton(
|
||||||
text: tr("setup.next"),
|
text: saveText,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
var publicValid = _publicFormKey.currentState.validate();
|
var publicValid = _publicFormKey.currentState.validate();
|
||||||
var privateValid = _privateFormKey.currentState.validate();
|
var privateValid = _privateFormKey.currentState.validate();
|
||||||
@ -286,6 +292,13 @@ class _GitHostUserProvidedKeysState extends State<GitHostUserProvidedKeys> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return SingleChildScrollView(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: body,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user